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 会给你比率分位数

我一定是理解错了

最佳答案

This和 here是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 分钟。

https://stackoverflow.com/questions/60962520/

相关文章:

spring-boot - Spring WebFlux Reactive 和 Kotlin Cor

sql - Postgres : How do I extract year and month f

firefox - 如何删除 Firefox 中的 X 按钮?

java - 从 JSONObject 中删除除一个之外的所有键

jenkins - 在airflow中的特定时间运行任务

scala - 为什么zio的putStrLn没有输出

angular - 使用 ngrx 和选择器等待资源加载到守卫中

node.js - 如何与 nx 并行运行 express 和 angular?

regex - PowerShell 从脚本中删除所有注释

react-native - 在 React Native Web 的情况下自定义 react-na