Reputation: 7524
I have instrumented my code inside a method for micrometer gauge like this:
SimpleMeterRegistry registry = new SimpleMeterRegistry();
Gauge
.builder("greeting_service_gauge", new AtomicInteger(new Random().nextInt(10)), AtomicInteger::get)
.register(registry);
I have added few other metrics too.
Other metrics appear on prometheus endpoint, but this gauge metrics doesn't.
What am I missing here?
Upvotes: 1
Views: 2106
Reputation: 15003
You are registering the gauge to the SimpleMeterRegistry
. Instead you should be registering the metric to the Prometheus registry (or the CompositeMeterRegistry)
You can inject the MeterRegistry
if this is a Spring project. Or use the global Metrics.globalRegistry
to get the composite one.
Gauge
.builder("greeting_service_gauge", new AtomicInteger(new Random().nextInt(10)), AtomicInteger::get)
.register(Metrics.globalRegistry);
Upvotes: 3