Looking at Micrometer, I get the idea that the whole idea is the use the Metrics e.g. classes from "io.micrometer.core.instrument" (because it's a facade) and it ends up in the global registry for basic usage.
And the documentation says that for Prometheus output, one should then use the PrometheusMeterRegistry.scrape().
But it escapes me how Micrometer and Prometheus is connected. I have an @GET "metrics" endpoint which pretty much looks like
Metrics.globalRegistry.counter("foo").increment();
PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
return Response.ok(prometheusRegistry.scrape()).build();
but nothing is shown, probably because the Prometheus registry is brand new (well, so it's in the Micrometer Prometheus section). How is the link made so that the Micrometer global registry is connected to the PrometheusMeterRegistry?
You can connect Metrics.globalRegistry
to prometheusRegistry
by calling globalRegistry.add(prometheusRegistry)
. E.g. you should re-write you code like this:
Metrics.globalRegistry.counter("foo").increment();
PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
Metrics.globalRegistry.add(prometheusRegistry); // <-- that's how you connect them
return Response.ok(prometheusRegistry.scrape()).build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With