【问题标题】:Micrometer and Prometheus Timer as Rate千分尺和普罗米修斯计时器作为速率
【发布时间】:2018-10-30 01:12:17
【问题描述】:

根据 Micrometer 的文档 https://micrometer.io/docs/concepts#_server_side,框架 (Micrometer) 应处理将计时器指标从绝对量转换为速率

下面的代码模拟了一个虚拟计时器:

@Service
public class AppService {
    private Timer timer = Metrics.timer("foobar");

    public String test() {
        timer.record(() -> {
            try {
                Thread.sleep((long) (Math.random() * 1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        return "foo";
    }
}

但在 Prometheus 中,我只看到指标 foobar_seconds_sumfoobar_seconds_count 单调递增,而不是将它们视为速率

也许我误解或忽略了文档中的某些内容?

【问题讨论】:

    标签: prometheus spring-boot-actuator micrometer


    【解决方案1】:

    这是 Prometheus Summary 的工作方式,您可以使用以下方法计算平均事件大小:

      rate(foobar_seconds_sum[5m])
    /
      rate(foobar_seconds_count[5m])
    

    对于 Prometheus,客户端库是愚蠢的,应该将更复杂的数学运算留给 Prometheus。

    【讨论】:

    • 谢谢,这更有意义。这证明我对文档的理解以某种方式被颠倒了。答案已接受
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 2023-02-22
    • 1970-01-01
    相关资源
    最近更新 更多