Variable based on variable

Using Grafana 7 and Prometheus I would like to implement a dashboard and panel that allows the user to select a $step out of “1h”, “1d”, “1M” independent from the dashboard interval. I use an according interval variable for this purpose.

Derived from this variable I need a second variable, let’s call it $nhours, that represents the length of $step in hours (e.g. 24 in case of $step==1d).

This is the concrete purpose: I have a “my_power” time series that represents power measurements (in W). I want to derive a rough estimate of energy bars (in kWh) $step by $step like this:

0.001 * $nhours * (avg_over_time(my_power[$step]))

Intuitively, I would write the query like this, but it seems to be not possible to put time ranges into a PromQL expression:

0.001 * ($nstep/24h) * (avg_over_time(my_power[$step]))

Any advice to a newbie?

This topic was automatically closed after 365 days. New replies are no longer allowed.