Situation
I have a counter with values from a power meter (KWh since it was installed). On my Grafana dashboard I like to show how much money was spend on electric power during the given time range.
Doing this with a fixed price per KWh is easy: increase(loxone_values{control="Stromverbrauch Z?hler"}[$__range]) * 0.22
I can show the last value with a "Stat" in Grafana and get the amount of money spend.
Problem
Obviously this fails if the price per KWh changes, which is does every hour in my case. I have a second metric that holds the current price. I like to multiply the KWh by the average price.
I think I can do this with group_left
but failed to construct a working query.
My first approach increase(loxone_values{control="Stromverbrauch Z?hler"}[$__range]) * group_left avg(loxone_values{control="Strompreis aktuell"})
which gives a parse error.
It looks like group_left
needs something to match the vectors. But there is no common tag (beside instance
but that might change in the future).
Anyway I gave that a try but increase(loxone_values{control="Stromverbrauch Z?hler"}[$__range]) * on (instance) group_left avg(loxone_values{control="Strompreis aktuell"})
gives me an empty result.
question from:
https://stackoverflow.com/questions/65651811/prometheus-how-can-i-multiply-a-vector-by-the-average-of-another-vector 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…