0

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

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
Sarahack
  • 1
  • 1
  • What do you mean "can we tell if it correct"? Have you run it? Does it return expected output? – markalex Apr 06 '23 at 18:35
  • yes i run it, but the values that i am getting in kwh seems wrong – Sarahack Apr 07 '23 at 11:10
  • What i mean by if it is correct is to know "if the equation that i am using to calculate the value in kwh is correct ?" – Sarahack Apr 07 '23 at 11:16
  • As you can see in my answer, you query seems mostly fine. If you have doubts about values: create new panel, put query `rPDU2DeviceStatusPower_gauge{site=~"$site"}` and switch `Table view`. You'll see all the values of metric, and could verify result value manually. – markalex Apr 07 '23 at 11:17
  • Also remember, since you gather metrics only once 5 minutes, you'll get estimation of power consumption, quite possibly a rough one. – markalex Apr 07 '23 at 11:19

1 Answers1

0
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.

markalex
  • 8,623
  • 2
  • 7
  • 32