Calculate kilowatthours from gauge with watts

958 views
Skip to first unread message

ipse...@googlemail.com

unread,
Aug 20, 2017, 7:54:11 AM8/20/17
to Prometheus Users
Hi,

I have a metric (gauge) that shows measured actual watts consumed. As this is intermitted (sometime the device is switched off and the value is 0). How can I easliy calculate the kWh consumed, i.e. integrate properly over that metric?

Simply adding up values does not work - should I average over periods in time and then add?

Andreas

Ben Kochie

unread,
Aug 20, 2017, 10:25:43 AM8/20/17
to ipse...@googlemail.com, Prometheus Users
I have something similar (SmartPi) that exports instant watts like this.

I use this calculation to get Watt-Hours:

sum_over_time(smartpi_active_watts[1h]) / 3600

I also set a Grafana "Min step" to 1h to avoid overlaps.

The reason for 3600 above is that my scrape_interval is 1s.  If you have a longer scrape interval, you will have to divide 3600 by the scrape_interval in seconds.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/e7d3ac18-785c-447d-9ca3-550cca51fd14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ivu...@gmail.com

unread,
Oct 26, 2017, 12:24:24 PM10/26/17
to Prometheus Users
On Sunday, August 20, 2017 at 3:25:43 PM UTC+1, Ben Kochie wrote:
The reason for 3600 above is that my scrape_interval is 1s.  If you have a longer scrape interval, you will have to divide 3600 by the scrape_interval in seconds.

Would count_over_time do the trick instead?

Ben Kochie

unread,
Oct 26, 2017, 12:32:12 PM10/26/17
to ivu...@gmail.com, Prometheus Users
Yes, I think you're right.

sum_over_time(smartpi_active_watts[1h]) / count_over_time(smartpi_active_watts[1h])

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages