1

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?

Mandroid
  • 6,200
  • 12
  • 64
  • 134

1 Answers1

2

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);
checketts
  • 14,167
  • 10
  • 53
  • 82