我已经对Rate()函数进行了很多分析,但对此并没有得到完美的答案。
假设我将刮擦级别设置为1M,这是我的表达
速率(http_request_total [5m])
- 因此,理想情况下,我应该以1m的间隔废话获取5个数据点,我称为V0,V1,V1,V2,V3,V4,V4,V5。
- 现在,当对费率方法进行评估时,我不确定我是否有正确的理解,但是我有这个公式。
rate()*300 =(v5-v0)/(t5-t1)
我的问题是,这个速率将如何计算(我的理解是正确的)?以及在此示例中如何完成外推的费率()?
我知道增加()就像我们从上述乘以总间隔的价值
I have done a lot of analysis on rate() function but have not got a perfect answer for the same.
Lets Suppose I have set the scraping level as 1m and this is my expression
rate(http_request_total[5m])
- So Ideally I should get 5 data points at 1m interval scrapping which I am referring as V0,V1,V2,V3,V4,V5 .
- Now , when Rate method will get evaluated , I am not sure if I have a correct understanding but I have this formula in mind.
Rate()*300=(V5-V0)/(t5-t1)
My question is this how rate will get calculated(my understanding is correct)? and how the extrapolation will be done the rate() in this example?
I know for increase() its like the value we get from the above multiplied to the total interval
发布评论
评论(1)
从理论上讲,这是正确的(除非在示例中除非您有6个数据点,而不是5个数据点)。但是,当您添加
start
和end
参数到查询时,“魔术”开始发生。在大多数情况下,这两个参数不会完全匹配t1
和t5
从您的示例中,Prometheus将无法捕获您的一个或多个数据点:在上面的示例中,时间窗口与真实值并不完美。在这种情况下,V1的值将被遗漏,这将影响结果,因为将在V5和V2之间计算增加。了解接收值之间的AVG间隔,Prometheus可以假定它没有捕获一些值。因此,它将尝试通过简单地将结果乘以系数来推断结果。
我建议您阅读这个很棒的线程 https://github.com/prometheus/prometheus/prometheus/prometheus/issues/sissues/ 3746 。
我还建议您阅读替代
速率
在这里如何工作在“更好的费率”部分中。披露,我是Victoriametrics的开发人员之一,所以请搭配一粒盐。Theoretically, it is correct (except in your example you have 6 datapoints, not 5). But the "magic" starts happening when you add

start
andend
params to your query. In most cases, these two params will not exactly matcht1
andt5
from your example, and Prometheus won't be able to capture one or more data points of yours:In the example above, time window isn't perfectly aligned with real values. In this case, value of v1 will be missed, which would affect the result since increase will be calculated between v5 and v2. Knowing the avg interval between received values, Prometheus could assume that it didn't capture some of the values. So it will try to extrapolate the result by simply multiplying it by coefficient.
I'd recommend reading this great thread https://github.com/prometheus/prometheus/issues/3746.
I'd also recommend reading how alternative
rate
could work here https://medium.com/@romanhavronenko/victoriametrics-promql-compliance-d4318203f51e in "Better rate" section. Disclosure, I am one of the developers at VictoriaMetrics, so take it with a grain of salt.