The "increase" function calculates how much some counter has grown and the "rate" function calculates the amount per second the measure grows.
Analyzing your data I think you used [30s] for the "increase" and [1m] for the "rate" (the correct used values are important to the result).
Basically, for example, in time 2m we have:
increase[30s] = count at 2m - count at 1.5m = 4423 - 4402 = 21
rate[1m] = (count at 2m - count at 1m) / 60 = (4423 - 4381) / 60 = 0.7
Prometheus documentation: increase and rate.
Answer from Marcelo Ávila de Oliveira on Stack OverflowWhat is the exact fomula of the funtion rate?
irate() Vs rate() Functions in Prometheus
Let’s say you have a counter with these values observed at 1m intervals:
0 60 120 600 720 780
Now rate over 5m will be:
(780-0)/5/60 = 2.6/sec
And irate over 5m will be (only last two data points are used which happen to be only 1m apart)
(780-720)/1/60 = 1/sec
Increasing the resolution does not affect the irate function because the last two observed values do not change when you look further back.
More on reddit.comHow does the Prometheus rate() function differ from increase()?
How do you calculate request rates using the Prometheus rate function?
Can rate() be used with all types of Prometheus metrics?
The "increase" function calculates how much some counter has grown and the "rate" function calculates the amount per second the measure grows.
Analyzing your data I think you used [30s] for the "increase" and [1m] for the "rate" (the correct used values are important to the result).
Basically, for example, in time 2m we have:
increase[30s] = count at 2m - count at 1.5m = 4423 - 4402 = 21
rate[1m] = (count at 2m - count at 1m) / 60 = (4423 - 4381) / 60 = 0.7
Prometheus documentation: increase and rate.
Prometheus calculates rate(count[d]) at timestamp t in the following way:
- It obtains raw samples per each time series with
countname on the time range(t-d ... t]. Note thatt-dtimestamp isn't included in the range, whilettimestamp is included in the range. For example, when calculatingrate(count[1m])at a timestampt=2mthe following raw samples are selected:4423 @ 2m, 4402 @ 1m45s, 4402 @ 1m30s, 4381 @ 1m15s. Note that the4381 @ 1msample isn't included in calculations. - Then it calculates the difference between the last and the first sample on the selected time range per each time series with the name
count. Prometheus can detect and remove time series resets to zero on the selected time range, but let's skip this for now for the sake of clarity. In the case above it calculates4423 @ 2m - 4381 @ 1m15s = 42. - Then it divides results from step 2 by the duration
din seconds per each time series with namecount. In the case above it calculates42 / 1m = 42 / 60s = 0.7.
The actual result for rate(count[1m]) @ 2m - 0.700023 - differs from the calculated result - 0.7 - because of extrapolation, which can be applied to results calculated at step 2 if timestamps for the first and/or the last raw sample are located too far from the selected time range bounds. See more details about the extrapolation in this issue.
Note also that Prometheus misses possible counter increase on the time range [1m ... 1m15s] when calculating both rate() and increase(). See more details about this issue here and here.
Hi All,
I'm trying to understand how irate() & rate() functions work. Why does irate() produce a similar looking graph when the range / resolution is 24h or 5m ? While the difference in graph is clearly visible with rate() when using range as 24h (presents a smoothed out line) or 5m(more spikey).
In the below graph for irate() for 2 different resolutions the graph looks the same. As per prometheus docs irate() calculates the per second instant rate based on the last two data points. What does this mean if my range is 24h? Thank you.
https://preview.redd.it/08mc4pq2mye41.jpg?width=3206&format=pjpg&auto=webp&s=4aef0b681969c8b9831ec0f34310838511ea0350