Search code examples
prometheusgrafanapromql

Understanding of rate() function of PromQL


I went through the PromQL docs and found rate little bit confusing. Then I tried one query from Prometheus query dashboard and found below given results

Time Count increase  rate(count[1m])
15s  4381  0          0
30s  4381  0          0
45s  4381  0          0
1m   4381  0          0

15s  4381  0          0
30s  4402  21         0.700023
45s  4402  0          0.700023
2m   4423  21         0.7

15s  4423  0          0.7
30s  4440  17         0.56666666
45s  4440  0          0.56666666
3m   4456  16         0.53333333

Last column value I am getting from dashboard but I am not able to understand how is this calculated.

Resolution - 15s

scrape_interval: 30s


Solution

  • 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.