I have a Spring Bean where the Gauges are initilized like that:
@PostConstruct
public void initGauge() {
paymentsTriedGauge = Gauge.build().name("payments_tried").help("How many payments was sent to PaymentServices to be created").register(registry.getPrometheusRegistry());
paymentsCreated = Gauge.build().name("payments_created").help("How many payments sent to PaymentServices were created").register(registry.getPrometheusRegistry());
}
where the registry is from
@Autowired
PrometheusMeterRegistry registry;
and then in one method I do:
paymentsTriedGauge.inc();
but later on Promtheus's /metrics page I got no update:
# HELP payments_tried How many payments was sent to PaymentServices to be created
# TYPE payments_tried gauge
payments_tried 0.0
Your usecase is using Prometheus gauges directly. Micrometer itself can be used with its own gauges. (Spring Boot is not required)
For example:
// maintain a reference to myGauge
AtomicInteger myGauge = registry.gauge("numberGauge", new AtomicInteger(0));
// ... elsewhere you can update the value it holds using the object reference
myGauge.set(27);
myGauge.set(11);
Notice the variable myGauge
is actually an AtomicInteger
and Micrometer is just reporting the value of that instance. AtomicInteger
also has an increment()
method you can use fine.