prometheus - 如何在普罗米修斯中获取速率的分位数

标签 prometheus

我正在看这个article

# TYPE prometheus_http_request_duration_seconds histogram
prometheus_http_request_duration_seconds_bucket{handler="/",le="0.1"} 25547
prometheus_http_request_duration_seconds_bucket{handler="/",le="0.2"} 26688
prometheus_http_request_duration_seconds_bucket{handler="/",le="0.4"} 27760
prometheus_http_request_duration_seconds_bucket{handler="/",le="1"} 28641
prometheus_http_request_duration_seconds_bucket{handler="/",le="3"} 28782

我不明白为什么

histogram_quantile(0.9, 
    rate(prometheus_http_request_duration_seconds_bucket[5m])
)

不会以 observe event/second 为单位给出速率的分位数,而是以 second/observe event 为单位给出请求持续时间的分位数

rate(prometheus_http_request_duration_seconds_bucket[5m]

应该给你 特定桶/秒内观察事件的数量平均超过 5 分钟

我想 histogram_quantile 会给你比率分位数

我一定是理解错了

最佳答案

Thishere是prometheus中historgram_quantile的代码。

举个例子,

assumed the original bucket is :
[50][100][150][200][200] with corresponding upperbound 5s,10s,15s,20s,+Inf.

then the rate(xx[5m]) returned a bucket like this:
[20/5*60][40/5*60][60/5*60][80/5*60][80/5*60]

histogram_quantile will delegate the returned bucket to another function bucketQuantile.
It used the rough following logic to compute the percentile: 

1) get the total rank of the percentile 
such as 90ile is 0.9 * total counts = 0.9 * (80/5*60)
2) compute the value of 90ile
last upperbound before the total rank position is 15 secs;
current upperbound of the total rank is 20 secs;
the count in the bucket that 90ile position belongs is (80/5*60)-(60/5*60);
the internal rank in that single bucket of 90ile position is (0.9 * 80/5*60)-(60/5*60);
finally, the value of 90ile is: 15 sec + (internal rank / that bucket count) * (20sec-15sec) = 15 + 3 * ( (0.9 * 80/5*60)-(60/5*60) / (80/5*60)-(60/5*60) ) = 
15 + 3 * ( (0.9*80 - 60)/(80-60) ) = 15 + 3 * ( 12/20) = 15+3*0.6= 16.8 sec

就是这样,你可以看到分母5*60在计算中实际上是没有影响的。所以 rate() 函数只是用来指定时间窗口 5 分钟。

关于prometheus - 如何在普罗米修斯中获取速率的分位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60962520/

相关文章:

continuous-integration - 如何自动测试 Prometheus 警报?

prometheus - 每个目标使用不同的Prometheus抓取网址

graphing - 用普罗米修斯和格拉法纳绘制慢速计数器

正则表达式从具有连续组的分隔字符串进行解析

grafana - 在 Prometheus 中找不到查询 label_values

通过 Prometheus 和 Grafana 对 AKS 进行 Azure 策略(网守)监控

prometheus - 跨多个实例查询普罗米修斯计数器

Docker:无法使用 VictoriaMetrics "vmagent"抓取 SonarQube,连接被拒绝

prometheus - 如何使用 prometheus-am-executor 运行 shell 脚本

load - promQL如何将node_load除以核心数