I have a Prometheus gauge metric x
that models a rate per second. My goal is to create a Grafana dashboard that shows a bar chart for this rate and is generic over various levels of aggregation such as "average rate over the last 60min".
For a fixed duration such as 60min, this is straightforward. We take the average in Prometheus and multiple with the number of seconds in the time window:
avg_over_time( x[60m] ) * 60 * 60
With this fixed query, it is also easy to create a Grafana dashboard that shows a bar chart with one 'bar' per hour (setting 'Min step' to 60m) whose magnitude is defined by the query above.
I want to make this visualization generic over the time span over which the mean value is taken. To this end, I have defined a "duration" variable $duration
in Grafana. However, I am stuck on how to formulate the prometheus query:
avg_over_time( x[$duration] ) * ???
Since $duration
is not a number but a string such as 60m
, I can't simply take $duration * 60
here. How can I convert the contents of $duration
to a number of seconds?
Thank you!