Skip to content

Commit

Permalink
docs: update outdated Prometheus Micrometer code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
varsanyid committed Aug 3, 2024
1 parent 7a20454 commit fa10e8c
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pages/plugins/micrometer.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ Create a registry, register the plugin, and provide a route:

```java
public static void main(String[] args) {
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);

MicrometerPlugin micrometerPlugin = MicrometerPlugin.Companion.create(micrometerConfig -> micrometerConfig.registry = registry);
MicrometerPlugin micrometerPlugin = new MicrometerPlugin(micrometerPluginConfig -> micrometerPluginConfig.registry = prometheusMeterRegistry);
Javalin app = Javalin.create(config -> config.registerPlugin(micrometerPlugin)).start(8080);

Javalin app = Javalin.create(config -> {
config.plugins.register(micrometerPlugin);
}).start(8080);

app.get("/prometheus", ctx -> ctx.contentType(TextFormat.CONTENT_TYPE_004).result(registry.scrape()));
String contentType = "text/plain; version=0.0.4; charset=utf-8";
app.get("/prometheus", ctx -> ctx.contentType(contentType).result(prometheusMeterRegistry.scrape()));
}
```

Expand All @@ -65,7 +63,8 @@ import io.micrometer.core.instrument.binder.jvm.*;
import io.micrometer.core.instrument.binder.system.*;


PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);


// add a tag to all reported values to simplify filtering in large installations:
registry.config().commonTags("application", "My-Application");
Expand All @@ -78,13 +77,12 @@ new UptimeMetrics().bindTo(registry);
new ProcessorMetrics().bindTo(registry);
new DiskSpaceMetrics(new File(System.getProperty("user.dir"))).bindTo(registry);

MicrometerPlugin micrometerPlugin = MicrometerPlugin.Companion.create(micrometerConfig -> micrometerConfig.registry = registry);
MicrometerPlugin micrometerPlugin = new MicrometerPlugin(micrometerPluginConfig -> micrometerPluginConfig.registry = prometheusMeterRegistry);

Javalin app = Javalin.create(config -> {
config.plugins.register(micrometerPlugin);
}).start(8080);
Javalin app = Javalin.create(config -> config.registerPlugin(micrometerPlugin)).start(8080);

app.get("/prometheus", ctx -> ctx.contentType(TextFormat.CONTENT_TYPE_004).result(registry.scrape()));
String contentType = "text/plain; version=0.0.4; charset=utf-8";
app.get("/prometheus", ctx -> ctx.contentType(contentType).result(prometheusMeterRegistry.scrape()));
```

## Custom Meters
Expand Down

0 comments on commit fa10e8c

Please sign in to comment.