如何获得普罗米修斯中速率的分位数 [英] How to get the quantile of rate in prometheus

查看:128
本文介绍了如何获得普罗米修斯中速率的分位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看这篇文章

# 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为单位给出请求持续时间的分位数

doesn't give you the quantile of rate with unit observe event / second but instead give the quantile of request duration with unit second / observe event

rate(prometheus_http_request_duration_seconds_bucket[5m]

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

should give you number of observe event in certain bucket / second average over 5 minute

我想histogram_quantile 会给你分位数

我一定是理解错了

推荐答案

这个他是 prometheus 中 historgram_quantile 的代码.

This and here is the code for the historgram_quantile in prometheus.

举个例子

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 分钟.

That's it, you can see the denominator 5*60 is actually no effect in the computation. so the rate() func is just lent to specify the time window 5 minutes.

这篇关于如何获得普罗米修斯中速率的分位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆