减少一个微米计数器的方法

huangapple go评论83阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月26日 18:51:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555993.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定