【问题标题】:Prometheus/Micrometer: how to count discrete values instead integralPrometheus/Micrometer:如何计算离散值而不是积分
【发布时间】:2021-07-08 09:09:11
【问题描述】:

我正在尝试使用 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-method 以下值:3、3、3。

最初我预计,我的千分尺代码会生成 3 个度量值:3、3、3,并将其传递给 Prometheus。而且,使用 Graphana 工具,我将看到反映离散值的直方图。像这样的:

但我看到的不是这个:

所以它整合了值 (3+3+3) 和输出 9。

如何提供度量 (3, 3, 3) 的离散值的输出?我应该使用什么仪器?

【问题讨论】:

    标签: java prometheus micrometer


    【解决方案1】:

    检查docsCounters 是求和值(我不确定你所说的积分是什么意思)。当你计算某事时,你要记住总和。虽然在导出计数器时,感兴趣的不是总和而是总和的比率(按时间的一阶导数),您可以在Rate aggregation 下的文档中阅读相关内容。

    根据我的理解,您需要的是Gauge;仪表用于获取当前值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-13
      • 2016-12-16
      • 1970-01-01
      • 1970-01-01
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      相关资源
      最近更新 更多