Reputation: 2315
I am drawing a graph in grafana where I am getting the rate of one counter and subtracting it from rate of another counter. I am using the Interval Variable in the graph. Now when I want to use 5m as interval, I want the rate to be multiplied (5*60). Similarly when 1h then it should be multiplied by (1 * 24 * 60 * 60)
$period = 1m,5m,10m,1h and like this.
My query
rate(service_total{state="otp_send"}[$period]) * 300 - ignoring(state) rate(service_total{state="otp_validate"}[$period]) *300
So I want this 300 to be put in a variable which changes when I change the $period value in grafana
> If $period is 5m, 300 should be 300
> If $period is 1m, 300 should be 60
> If $period is 10m, 300 should be 600
And in this way. Is there something that I can do in grafana.
SO basically I want to attach the $period to a constant variable that multiplies according to the interval.
Upvotes: 0
Views: 1407
Reputation: 22511
You can change from "rate(vector)*time" to "delta(vector)" to get the same result, like the following:
delta(service_total{state="otp_send"}[$period]) - ignoring(state) delta(service_total{state="otp_validate"}[$period])
More info in the Prometheus documentation here.
UPDATE:
As @brian-brazil replied, the correct in this case is to use the "increase" function instead of the "delta" function because the second one doesn't deal with counter resets.
More info in the Prometheus documentation here
Upvotes: 1
Reputation: 34172
increase(service_total{state="otp_send"}[$period])
- ignoring(state)
increase(service_total{state="otp_validate"}[$period])
increase
is syntactic sugar on top of rate
that does this.
Upvotes: 2