问题描述
我正在尝试使用 Java 库“io.micrometer.core.instrument”来计算不同时间间隔内的一些值。
使用 Counter 我的代码如下所示:
private MeterRegistry meterRegistry;
private Counter attemptsCount;
@postconstruct
private void initCounter() {
attemptsCount = Counter.builder("ATTEMPTS_COUNT")
.tag("type","word")
.description("Attempts number count")
.register(meterRegistry);
}
public void incrementAttemptsCount(final int sendAttemptsCount) {
attemptsCount.increment(sendAttemptsCount);
attemptsCount.count();
}
在测试用例客户端代码中 3 次传递给 incrementAttemptsCount-方法以下值:3、3、3。
最初我期望,我的千分尺代码生成 3 个度量值:3、3、3 并将其传递给 Prometheus。而且,使用 Graphana 工具,我会看到直方图,它反映了离散值。像这样:
但我看到的不是这个:
所以它对值 (3+3+3) 进行积分并输出 9。
如何提供度量 (3,3,3) 的离散值的输出?我应该使用什么工具?
解决方法
检查 docs、Counters 是求和值(我不确定您所说的积分是什么意思)。当您计算某事时,您会记住总和。尽管当导出计数器时,有趣的不是总和而是该总和的比率(时间的一阶导数),您可以在 Rate aggregation 下的文档中阅读相关内容。
根据我的理解,您需要的是 Gauge;仪表用于获取当前值。