Reputation: 332
I currently use the following query to get the kwh drawn from the grid for this year:
sum_over_time( (sum_over_time(wattage_v1[1m])*360/1000/count_over_time(wattage_v1[1m]))[1y:1h] )
EDIT: This query seems to deliver basically the same result:
sum_over_time(wattage_v1[1y:1h])*360/1000
The metric wattage_v1
provides wattage¹ readings every 15s to 1m.
The query above seems to work. Now I would like to have a similar query which only sums the wattage value if it is above a threshold - say 4000w. I want to roughly estimate the (yearly) consumption of a big consumer that is only running from time to time.
¹ actually 1/360 watt
Thanks
EDIT: I have noticed that the graph doesn't increase monotonic if the range (1y from above set to 1d for example) is smaller than the actual data that is present. I would like to have a counter for the kwh consumed since the beginning of the year or for the selected time range.
Upvotes: 2
Views: 1947
Reputation: 18094
The following promql query should return the total energy consumption in Joules for minutes with over 4kW power usage during the last year ending at the current timestamp:
sum_over_time(
(wattage_v1 > 4000)[1y:1m]
) * 60
This query uses PromQL comparison operator and Prometheus subquery feature.
If the result must be converted from Joules
(aka watt-seconds) to more commonly used kilowatt-hours (aka kWh
), then it must be divided by 3600000:
sum_over_time(
(wattage_v1 > 4000)[1y:1m]
) * 60 / 3600000
P.S. I work on Prometheus-like monitoring system - VictoriaMetrics, which provides additional useful functions for energy consumption calculations:
integrate(wattage_v1[1y])
would return energy consumption in Joules over the last year ending at the given timestamp.kWh
over arbitrary time range:running_sum(integrate(wattage_v1)) / 3600000
Upvotes: 1