X axis value in response of rate query

15 views
Skip to first unread message

Manish G

unread,
Sep 5, 2020, 2:56:35 AM9/5/20
to Prometheus Users
Hi,

I understand in rate(mymetrics[time window]) function, we basically have following calculation:
(value at end of time window - value at start of time window) / time window

So this gives value for Y axis.

And how about corresponding X axis value? Is it the start of the time window or end or middle of it or something else?

With regards

Brian Candler

unread,
Sep 5, 2020, 4:15:12 AM9/5/20
to Prometheus Users
Not exactly.  If there are no counter resets, then it's

(last value in time window - first value in time window) / (timestamp of last value - timestamp of first value)

Consider a 5 minute window with 1 minute scrape intervals.  You are likely to have 5 values within the window, and there is 4 minutes between the first and last.

<--------- 5 mins -------->
|  X    X    X    X    X  |
   <------ 4 mins ----->

So the rate is calculated over the 4 minute period between the first and last X.

Counter resets make it more complex than that; only the periods where the value is not decreasing are considered.


On Saturday, 5 September 2020 07:56:35 UTC+1, Manish G wrote:
And how about corresponding X axis value? Is it the start of the time window or end or middle of it or something else?

The time at the end of the time window.  That is, foo[1h] looks back 1 hour from the instant that the query is requested for. 

Manish G

unread,
Sep 6, 2020, 3:46:19 AM9/6/20
to Brian Candler, Prometheus Users
<<Counter resets make it more complex than that; only the periods where the value is not decreasing are considered.>>

Isn't the rate function supposed to take care of resets? OR it does so only when used with an aggregator like sum().

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/c21f491e-ac62-4a81-90df-618941e9e709o%40googlegroups.com.

Brian Candler

unread,
Sep 6, 2020, 11:03:23 AM9/6/20
to Prometheus Users
On Sunday, 6 September 2020 08:46:19 UTC+1, Manish G wrote:
<<Counter resets make it more complex than that; only the periods where the value is not decreasing are considered.>>

Isn't the rate function supposed to take care of resets?

That's exactly what I was saying.  If there are counter resets, then rate() does more than just take the last value in the window minus the first value and divide by the difference in timestamps.
Reply all
Reply to author
Forward
0 new messages