英文:
How to decrement a micrometer counter
问题
可以通过以下方式递减计数器的值:
meterRegistry.counter("SOME_COUNTER").increment(-1);
英文:
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?
答案1
得分: 4
一个微米计数器只能不断增加。从Javadoc中(强调我的):
计数器监控单调增加的值。计数器永远不会被重置为较小的值。
如果您的值可能上升也可能下降,您可能需要切换到一个 Gauge
。
英文:
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.
答案2
得分: 4
Micrometer文档中提到:
计数器报告一个单一的指标:计数。
Counter
接口允许您按固定数量增加,必须为正数。
因此,递减-1是不起作用的。
计数器不适用于递减。您可能希望为此目的使用不同的仪表,例如 gauge。
英文:
The Micrometer documentation says:
> Counters report a single metric: a count. The Counter
interface lets you increment by a fixed amount, which must be positive.
So incrementing by -1 does not work.
Counters are not meant to decrement. You probably want to use a different meter for this purpose, for example a gauge.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论