When using PromQL in cloud monitoring dashboard, I can see that the variable $__interval is available (and often automatically used by google cloud). But is there a way to get the time duration for the entire range in question? Grafana has __range, but i can't get that to work.
I'm trying to create a metic that calculates sum over the period of time selected. I can put in a constant (like 24h), but then it doesn't change as the range changes.
Hello @halfdanj,
Welcome to Google Cloud Community!
You're right, PromQL in Cloud Monitoring doesn't have a direct equivalent to Grafana's __range
variable. However, to achieve your goal of calculating the sum over the selected time period in your metric, you may use Rate over Interval.
This approach utilizes the rate
function along with the provided $__interval
variable in PromQL:
sum(rate(<your_metric>[$__interval]))
rate(<your_metric>[$__interval])
: This calculates the rate of change of your metric over the current $__interval.sum()
: This sums the rate values over the entire time range displayed in the dashboard (which is implicitly available in PromQL).
I'm unable to get that working. This is what i'm using at the moment :
Have you tried the $__timeFilter
variable? It doesn't provide the entire duration but it allows you to construct a dynamic time range based on your selection.
Hmm I'm not able to use it. Tried a few formattings, but always getting ": parse error: missing unit character in duration" .
same error trying to use $__interval "parse error: missing unit character in duration"