prometheus - 千分尺和普罗米修斯计时器作为速率
问题描述
根据 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_sum
,foobar_seconds_count
而不是将它们视为速率
也许我误解或忽略了文档中的某些内容?
解决方案
这就是 Prometheus Summary 的工作方式,您可以使用以下方法计算平均事件大小:
rate(foobar_seconds_sum[5m])
/
rate(foobar_seconds_count[5m])
使用 Prometheus 的客户端库是愚蠢的,应该将更复杂的数学运算留给 Prometheus。
推荐阅读
- sql-server - 拆分日期列,并根据结果计算金额
- dynamic - 使用带有月+年 (mmyy) SAS EG 的动态表名
- django - 与用户模型相关的Modelserializer
- excel - 循环浏览网址列表并提取可用库存
- java - 通过 Kubernetes 部署时,tomcat docker chmod 无法正常工作
- azure-devops - YAML:在此上下文中,第 4 行第 5 列不允许映射值
- javascript - 使用递归生成器进行遍历和过滤
- excel - 通过 Excel 的 PostgreSQL ODBC 非常慢
- r - Drawing uniform Distributions with ggplot in R
- mysql - 在laravael中获取与该id相关的最新记录