Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decrement a micrometer counter

I can increment the micrometer counter by doing like this:

meterRegistry.counter("SOME_COUNTER").increment();

But, when I do the below:

meterRegistry.counter("SOME_COUNTER").increment(-1);

It is not decrementing the value. How can I decrement the counter value by 1?

like image 781
Rahul Raj Avatar asked Feb 04 '26 04:02

Rahul Raj


1 Answers

A micrometer counter can only ever go up. From the Javadoc (emphasis mine):

Counters monitor monotonically increasing values. Counters may never be reset to a lesser value.

You might have to switch to a Gauge if your value can go down as well as up.

like image 156
Joachim Sauer Avatar answered Feb 05 '26 22:02

Joachim Sauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!