How to rate() calculated

3,692 views
Skip to first unread message

Александр Петров

unread,
Mar 17, 2016, 4:38:45 PM3/17/16
to Prometheus Developers
I continue study prometheus.

Sorry for a stupid question but i don't understand what function rate() does and how it's calculated
Yes, i have readed docs https://prometheus.io/docs/querying/functions/#rate%28%29 but all what i understood it's
that rate() calcs  _average_ value of deltas between values of given vector divided by scrape internal (const)

Example from my prometheus console:

settings
a) scrap interval time of prometheus itself -- 5s

query to see vector in 10s (must be 2 values):
http_request_duration_microseconds_sum{handler="prometheus",instance="localhost:9090",job="prometheus"}[10s]

80495.79999999999 @1458245879.227
82492.09999999999 @1458245884.227

first column is a observed value, second column -- timestamp when server scraped given value

so, rate  = ( 82492 - 80495) / ( 1458245884 - 1458245879 ) = 1997 / 5 ~ 399

Is it right? As i understand rate can use some interpolation and result can be little different

real rate: rate(http_request_duration_microseconds_sum{handler="prometheus",instance="localhost:9090",job="prometheus"}[10s]) ~ 347


test b)
set scrap intrval to 25s

query:
http_request_duration_microseconds_sum{handler="prometheus",instance="localhost:9090",job="prometheus"}[50s]
result:

22937.5 @1458246532.324
27891 @1458246557.325

rate = (27891  -22937 ) / 25 ~ 198

real rate(http_request_duration_microseconds_sum{handler="prometheus",instance="localhost:9090",job="prometheus"}[50s]) ~ 198

2) Don't understand why example from http://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations


To calculate the average request duration during the last 5 minutes from a histogram or summary called http_request_duration_seconds, use the following expression:

  rate(http_request_duration_seconds_sum[5m])
/
  rate(http_request_duration_seconds_count[5m])
 
correct

(a)http_request_duration_seconds_sum[5m] -- is a growing sum of request duration over last 5m,
rate(a) -- average value of request duration per second over last 5m. Rigth ?

what means division by
rate(http_request_duration_seconds_count[5m])?


Sorry for simple questions -- i'm new in metrics and prometheus my first monitoring system.
I will be grateful if somebody suggest me general topics about metrics and how ones calculated.

Thanks



Brian Brazil

unread,
Mar 17, 2016, 7:06:52 PM3/17/16
to Александр Петров, Prometheus Developers
On 17 March 2016 at 20:38, Александр Петров <std...@gmail.com> wrote:
I continue study prometheus.

Sorry for a stupid question but i don't understand what function rate() does and how it's calculated
Yes, i have readed docs https://prometheus.io/docs/querying/functions/#rate%28%29 but all what i understood it's
that rate() calcs  _average_ value of deltas between values of given vector divided by scrape internal (const)

Example from my prometheus console:

settings
a) scrap interval time of prometheus itself -- 5s

query to see vector in 10s (must be 2 values):
http_request_duration_microseconds_sum{handler="prometheus",instance="localhost:9090",job="prometheus"}[10s]

80495.79999999999 @1458245879.227
82492.09999999999 @1458245884.227

first column is a observed value, second column -- timestamp when server scraped given value

so, rate  = ( 82492 - 80495) / ( 1458245884 - 1458245879 ) = 1997 / 5 ~ 399

Is it right? As i understand rate can use some interpolation and result can be little different

real rate: rate(http_request_duration_microseconds_sum{handler="prometheus",instance="localhost:9090",job="prometheus"}[10s]) ~ 347

What timestamp are you executing this at, and what version of Prometheus are you using? The answer should be coming out as 399.4 if this is a recent version and that's the data involved.
 

test b)
set scrap intrval to 25s

query:
http_request_duration_microseconds_sum{handler="prometheus",instance="localhost:9090",job="prometheus"}[50s]
result:

22937.5 @1458246532.324
27891 @1458246557.325

rate = (27891  -22937 ) / 25 ~ 198

real rate(http_request_duration_microseconds_sum{handler="prometheus",instance="localhost:9090",job="prometheus"}[50s]) ~ 198

2) Don't understand why example from http://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations


To calculate the average request duration during the last 5 minutes from a histogram or summary called http_request_duration_seconds, use the following expression:

  rate(http_request_duration_seconds_sum[5m])
/
  rate(http_request_duration_seconds_count[5m])
 
correct

(a)http_request_duration_seconds_sum[5m] -- is a growing sum of request duration over last 5m,
rate(a) -- average value of request duration per second over last 5m. Rigth ?

That's the time spent per second on requests, on average for the last 5m.
 

what means division by
rate(http_request_duration_seconds_count[5m])?
That's the average request duration for the last 5m.

Brian
 


Sorry for simple questions -- i'm new in metrics and prometheus my first monitoring system.
I will be grateful if somebody suggest me general topics about metrics and how ones calculated.

Thanks



--
You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-devel...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

xinn...@gmail.com

unread,
May 4, 2018, 6:42:33 AM5/4/18
to Prometheus Developers

> 2) Don't understand why example from http://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
>
>
>
> To calculate the average request duration during the last 5 minutes
> from a histogram or summary called http_request_duration_seconds,
> use the following expression:
>
> rate(http_request_duration_seconds_sum[5m])
> /
> rate(http_request_duration_seconds_count[5m])
>
>  correct
>
> (a)http_request_duration_seconds_sum[5m] -- is a growing sum of request duration over last 5m,
> rate(a) -- average value of request duration per second over last 5m. Rigth ?
>
> what means division by rate(http_request_duration_seconds_count[5m])?
>
> Sorry for simple questions -- i'm new in metrics and prometheus my first monitoring system.
> I will be grateful if somebody suggest me general topics about metrics and how ones calculated.
>
> Thanks

Let's say in the last 5m, the first value of "http_request_duration_seconds_sum" is S1, and the last value of "http_request_duration_seconds_sum" is S5. Then "rate(http_request_duration_seconds_sum[5m])" equal to "(S5 - S1) / 300s".

In the same way, let say in the last 5m, the first value of "http_request_duration_seconds_count" is C1, and the last value of "http_request_duration_seconds_count" is C5. Then "rate(http_request_duration_seconds_count[5m])" equal to "(C5 - C1) / 300s".

OK. Then
rate(http_request_duration_seconds_sum[5m])
/
rate(http_request_duration_seconds_count[5m])

means ((S5 - S1) / 300s) / ((C5 - C1) / 300s)

That equals to (S5 - S1) / (C5 - C1). This is the average request duration for the last 5m.

But here is a bug, if C5 equqls to C1 ...


Brian Brazil

unread,
May 4, 2018, 8:07:15 AM5/4/18
to xinn...@gmail.com, Prometheus Developers
There's no bug, the result will be NaN which is correct as you're dividing by zero. You can't calculate the latency of no requests.

Brian
 


--
You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-developers+unsub...@googlegroups.com.
To post to this group, send email to prometheus-developers@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-developers/f13df36a-99ea-474e-9ead-b780dcebc05a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

ayoube...@gmail.com

unread,
Mar 25, 2019, 10:23:18 AM3/25/19
to Prometheus Developers
to calculate rate should we devide by scrap interval time of prometheus, or by the duration of simpled value of our time series
example:supose our prometheus server has a interval scrape of (a sec), for the last (x min), we want to calculate the rate o mesure M

so rate(M[xm])=(Mx-M0)/(a or x)

Reply all
Reply to author
Forward
0 new messages