How to calculate the power consumption in kwh using a prometheus query

583 Views Asked by At

I have this Prometheus query that i am using to calculate the power consumption of apc PDUs in KWH,

sum(sum_over_time((rPDU2DeviceStatusPower_gauge{site=~"$site"})[$__range] /100 ) / count_over_time(rPDU2DeviceStatusPower_gauge{site=~"$site"}[$__range]) * ($__range/3600)) by (site)

i am visualizing this in pie chart that why i am grouping by site name of each pdu.

my collect interval is 5min

the metric rPDU2DeviceStatusPower_gauge return the power consumption of the pdu load in hundredths of kilowatts, that's why i am dividing by 100

can you tell me if this query is correct ?

What i tried : the query above

What i am expecting : well, to get the correct value in kwh

1

There are 1 best solutions below

2
markalex On
sum_over_time(
        rPDU2DeviceStatusPower_gauge{site=~"$site"}[$__range] /100 
    )
    / count_over_time(
        rPDU2DeviceStatusPower_gauge{site=~"$site"}[$__range]
    )

can be boiled down to avg_over_time(rPDU2DeviceStatusPower_gauge{site=~"$site"}[$__range])/100.

So, your resulting query would be:

sum(
    avg_over_time(rPDU2DeviceStatusPower_gauge{site=~"$site"}[$__range])
       / 100 * ($__range/3600)
) by (site)

If rPDU2DeviceStatusPower_gauge reports reports in hundreds of kW, then result should be estimation of power consumption in kWh.

Also, if rPDU2DeviceStatusPower_gauge is generated by your side, consider Best practices regarding naming and units of your metrics. If it possible at least move from hundreds kW to kW.