Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[rrd-users] Accumulative power usage graph

89 views
Skip to first unread message

gm_sjo

unread,
Feb 21, 2009, 4:39:31 AM2/21/09
to
Hi all,


This is my first post to this list so let me know if anything is out
of order. I'm a complete rrdtool noob so bear with me.

I've got some power usage graphs knocked up, using a currentcost CC128
as a data source, via a Perl script. It's working fine just displaying
historic actual usage, as per this example :-

http://power.saqnet.org.uk/images/power_1d.png


Now, more importantly than the above graph I need to create a chart
showing kWh used per day/month/quarter/year. I'm thinking that because
I have a 1 day graph with an average consumption value I should be
able to transpose this into a kwh used for that day.

Something like this :-

http://i42.tinypic.com/33p7zgw.png


Problem is I have no idea how to achieve this - has anyone done this
that could share their conf, or perhaps just some
pointers/suggestions?

At the bottom is one of the power graph confs.

Thanks!


--
/usr/local/bin/rrdtool graph /var/www/htdocs/images/power_1h.png
--watermark "SAQ POWER - 1 HOUR" --start end-1hour \
--width 750 --height 100 --end now --slope-mode --vertical-label Watts
--lower-limit 0 --alt-autoscale-max \
DEF:Power=powertemp.rrd:Power:AVERAGE \
DEF:PowerMin=powertemp.rrd:Power:MIN \
DEF:PowerMax=powertemp.rrd:Power:MAX \
CDEF:PowerRange=PowerMax,PowerMin,- \
LINE1:PowerMin: AREA:PowerRange#0000FF11:"":STACK \
LINE1:PowerMin#0000FF33:"" \
LINE1:PowerMax#0000FF33:"" \
LINE1:Power#0000FF:"" \
GPRINT:PowerMin:MIN:"Min\:%4.0lfW" \
GPRINT:PowerMax:MAX:"Max\:%4.0lfW" \
GPRINT:Power:AVERAGE:"Avg\:%4.0lfW"
--

_______________________________________________
rrd-users mailing list
rrd-...@lists.oetiker.ch
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

Alex van den Bogaerdt

unread,
Feb 21, 2009, 6:07:02 AM2/21/09
to
----- Original Message -----
From: "gm_sjo" <saqm...@gmail.com>
To: <rrd-...@lists.oetiker.ch>
Sent: Saturday, February 21, 2009 10:39 AM
Subject: [rrd-users] Accumulative power usage graph


> Hi all,
>
>
> This is my first post to this list so let me know if anything is out
> of order. I'm a complete rrdtool noob so bear with me.
>
> I've got some power usage graphs knocked up, using a currentcost CC128
> as a data source, via a Perl script. It's working fine just displaying
> historic actual usage, as per this example :-
>
> http://power.saqnet.org.uk/images/power_1d.png

Looking good, albeit a bit high. If you think 500W is the true power
consumption, then OK. Else make sure you aren't confused between what you
think you are storing and what you are actually storing here. I'm talking
about units.

> Now, more importantly than the above graph I need to create a chart
> showing kWh used per day/month/quarter/year. I'm thinking that because
> I have a 1 day graph with an average consumption value I should be
> able to transpose this into a kwh used for that day.

And indeed you can. W=J/s and kWh is 3600000J. Just do the math.

Next question: can you use rrdtool to graph this the way you showed in the
next link.


> Something like this :-
>
> http://i42.tinypic.com/33p7zgw.png
>
> Problem is I have no idea how to achieve this - has anyone done this
> that could share their conf, or perhaps just some
> pointers/suggestions?

The problem here is that you define a day as midnight local time to midnight
local time. This is not how RRDtool works. The problem is bigger when you
start talking about months and quarters.

Unless you are willing to look at more normalized intervals (midnight UTC to
midnight UTC, intervals of 30 days starting at well defined moments in time,
and so on) you cannot display more than one of such interval at a time.

What can you do:

1: store your data in intervals no larger than one hour, every day compute
the average for that day, store the average elsewhere (e.g. some SQL
database) and graph there. Once a year you will count one hour twice, once a
year you will skip an hour in your averages.
2: live with the fact that you can display intervals which have a start
timestamp and an end timestamp which are whole multiples of the interval.
Example: if the interval is 3600 (one hour) then you can display 10:00 to
11:00 and 11:00 to 12:00, you cannot display 09:30 to 10:30 and 10:30 to
11:30.

Look at the unix time stamp, e.g. 1235214000 (11:00 UTC today) divided by
3600 has no remainder.
Last midnight for me was 1235170800, divided by 86400 does give a remainder
thus is not suitable.
Midnight for you, once daylight saving has started, has the same problem.

It works exactly the same for longer intervals, such as a "month" (30 days)
or a "quarter" (90 days).


HTH
Alex

gm_sjo

unread,
Feb 21, 2009, 3:28:26 PM2/21/09
to
2009/2/21 Alex van den Bogaerdt <al...@vandenbogaerdt.nl>:

> Looking good, albeit a bit high. =A0If you think 500W is the true power


> consumption, then OK. Else make sure you aren't confused between what you
> think you are storing and what you are actually storing here. I'm talking
> about units.

Thanks Alex. Yes 500W is about right for my average load (workstation,
server, media centre, some heating sometimes etc).

> The problem here is that you define a day as midnight local time to midni=
ght
> local time. =A0This is not how RRDtool works. The problem is bigger when =


you
> start talking about months and quarters.
>

> Unless you are willing to look at more normalized intervals (midnight UTC=
to
> midnight UTC, intervals of 30 days starting at well defined moments in ti=
me,


> and so on) you cannot display more than one of such interval at a time.

I'll look into it. I was aware it uses unix timestamps so i'll see
what I can come up with. It doesn't need to be super accurate, i'm
just trying to get a reasonable comparative figure to what my
electricity company thinks i've used :-)


Thanks

Rob Conway

unread,
Feb 22, 2009, 7:49:37 AM2/22/09
to
I do exactly the same thing to calculate my total house power however I
count the disc rotations of my kwh meter. =


See www.rjconway.homeip.net select power. You will need Internet Explorer
to use the controls.


You will need a couple of scripts and text files, cannot guarantee this is
100% however should get you underway with the idea.


This is what I used to create the rrd. Change it to suite your needs,
cannot remember exactly how this works however do not change the step of
600. create an rrd for kw and kwh

rrdtool create /var/rrd/kw.rrd --start ?????????? --step 600
DS:P1:GAUGE:1300:0:100 RRA:AVERAGE:0.5:1:1440 RRA:AVERAGE:0.5:4:2160
RRA:AVERAGE:0.5:12:8760 RRA:MIN:0.5:144:1825 RRA:MAX:0.5:144:1825


1) =

Script to capture the counter at midnight and store its value in a file
(discday.txt), also this script if its Sunday will store the counter in a
file called discweek.txt. This script needs to run at midnight, use crontab
to schedule the script to run.

This is a sample crontab from my NSLU2, last entry triggers a script in this
case flowread to run at 11:50pm. You will also see my scripts that create
my trends (Aqua7D etc)

SHELL=3D/bin/sh
PATH=3D/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=3D""
HOME=3D/
# ---------- ---------- Default is Empty ---------- ---------- #
0 0-23/8 * * * root /usr/sbin/CheckDiskFull &>/dev/null
0 0 * * * root /usr/sbin/WatchDog &>/dev/null
*/15 * * * * root /public/Aqua2D &>/dev/null
1 * * * * root /public/Aqua7D &>/dev/null
2 * * * * root /public/Aqua1W &>/dev/null
5 * * * * root /public/Aqua1M &>/dev/null
12 * * * * root /public/Aqua2M &>/dev/null
50 23 * * * root /public/flowread &>/dev/null


THIS SCRIPT RUNS AT MIDNIGHT VIA CRONTAB AND STORES THE COUNTER IN A TEXT
FILE

#!/bin/bash
S1=3D$(/bin/date +%a)
S2=3D'Sun'
OWR=3D"/opt/owfs/bin/owread -s 3001"


### Read 1wire data ###
disc=3D$($OWR 1D.EBEF0900000034/counters.B)


### Place current reading in storage ###
echo $disc $('date')>/var/scripts/discday.txt

### Write Sundays flow to calculate total weekly KWH (NOT CURRENTLY USED)###
if [ $S1 =3D=3D $S2 ];
then
echo $disc $('date')>/var/scripts/discweek.txt
fi

OK so we now capture the counter at midnight (11:50pm) and store the counter
in a text file. You will need to make sure your file permissions are OK for
the script and txt files so that they can be read.

2)a script that calculates the kw and stores the data in a file. This
script just loops around every 5 minutes. You will see to calculate the kw
you need to take the current counts and subtract them from the last count
then do your maths.. Thus this script also saves the count as disc_10.txt
so next time it runs it knows the difference between the last count and the
new count thus how many kw have been measured in that time interval, 300
seconds

This script pushes two readings into the rrd every 300 seconds which get
averaged together every 600 seconds within the rrd.


A note on AWK. Awk enables you to do maths functions, The first value in
the txt file (ie /var/scripts/disc_10.txt ) becomes variable $0 within the
calc. Thus (DR-$0) provides you with the number of counts in the last 300
seconds. You will need to change the subsequent maths to suit your counter.
I am measuring the disc rotations of my power meter thus my calc *3600/45000
is not what you want.

THIS IS THE MAIN SCRIPT THAT LOOPS EVERY 300 second TO GET DATA INTO AN RRD.
I generally started these files with a program called "nohup" which enables
you to start a script and let it run in the background. nohup /scriptname
&>/dev/null nohup was tricky to find for the nslu2, cannot remember how I
got it. Anyway you just need to start this program and get it to
continuously run.

#!/bin/bash
OWWRITE=3D"/opt/owfs/bin/owwrite -s 3001"
OWREAD=3D"/opt/owfs/bin/owread -s 3001"
AWK=3D"/usr/bin/awk"

while true
do

### Read 1wire data ##
disc=3D$($OWREAD 1D.EBEF0900000034/counters.B)

### Calculations based upon Data ###
KW=3D$($AWK -v DR=3D"$disc" '{printf "%g\n",(((DR-$0)*3600)/45000)}'
/var/scripts/disc_10.txt)
echo $disc >/var/scripts/disc_10.txt
Todaykwh=3D$($AWK -v DR=3D"$disc" '{printf "%g\n",((DR-$0)/150)}'
/var/scripts/discdy.txt)

### Push Data into NEW Trend Files ###
rrdtool update /var/www/rrd/kw.rrd N:$KW
rrdtool update /var/www/rrd/kwh_daily.rrd N:$Todaykwh:1

sleep 300
done

I hope this helps

rob


-----Original Message-----
From: rrd-user...@lists.oetiker.ch
[mailto:rrd-user...@lists.oetiker.ch] On Behalf Of gm_sjo
Sent: Sunday, February 22, 2009 7:28 AM
To: Alex van den Bogaerdt
Cc: rrd-...@lists.oetiker.ch
Subject: Re: [rrd-users] Accumulative power usage graph

2009/2/21 Alex van den Bogaerdt <al...@vandenbogaerdt.nl>:

> Looking good, albeit a bit high. =A0If you think 500W is the true power
> consumption, then OK. Else make sure you aren't confused between what you
> think you are storing and what you are actually storing here. I'm talking
> about units.

Thanks Alex. Yes 500W is about right for my average load (workstation,
server, media centre, some heating sometimes etc).

> The problem here is that you define a day as midnight local time to

midnight


> local time. =A0This is not how RRDtool works. The problem is bigger when =
you
> start talking about months and quarters.
>
> Unless you are willing to look at more normalized intervals (midnight UTC

to
> midnight UTC, intervals of 30 days starting at well defined moments in

time,


> and so on) you cannot display more than one of such interval at a time.

I'll look into it. I was aware it uses unix timestamps so i'll see
what I can come up with. It doesn't need to be super accurate, i'm
just trying to get a reasonable comparative figure to what my
electricity company thinks i've used :-)


Thanks

_______________________________________________
rrd-users mailing list
rrd-...@lists.oetiker.ch
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

No virus found in this incoming message.
Checked by AVG - www.avg.com =

Version: 8.0.237 / Virus Database: 270.11.2/1965 - Release Date: 02/21/09
15:36:00

gm_sjo

unread,
Feb 23, 2009, 9:29:48 AM2/23/09
to
Thanks Rob. I'll take a good read through that soon.


For the meantime i've knocked up my graphs as follows :-

/usr/local/bin/rrdtool graph /var/www/htdocs/images/power_1d.png \
--watermark "SAQ POWER - 1 DAY" --start end-1day --width 1000 --height
100 --end now --slope-mode --vertical-label Watts --alt-autoscale \


DEF:Power=powertemp.rrd:Power:AVERAGE \
DEF:PowerMin=powertemp.rrd:Power:MIN \
DEF:PowerMax=powertemp.rrd:Power:MAX \
CDEF:PowerRange=PowerMax,PowerMin,- \

CDEF:kWh=Power,1000,/,24,* \


LINE1:PowerMin: \
AREA:PowerRange#0000FF11:"":STACK \
LINE1:PowerMin#0000FF33:"" \
LINE1:PowerMax#0000FF33:"" \

LINE1:Power#0000FF:"Average Consumption\:" \
GPRINT:Power:AVERAGE:"%4.0lf Watts" \


GPRINT:PowerMin:MIN:"[Min\:%4.0lfW" \

GPRINT:PowerMax:MAX:"Max\:%4.0lfW]" \
COMMENT:"[Units used\:" \
GPRINT:kWh:AVERAGE:"%1.2lf kWh]"


Now the '24' in CDEF:kWh is obviously hours but i'm wondering if there
is any variable containing the length of the graph, in seconds,
whatever. I did try playing with begintime but was probably
DoinItWrong(tm) and didnt' get very far. It'd be nice if I could have
a generic entry I can re-use without having to calculate the hours
myself.

Any thoughts?

Thanks!

A Darren Dunham

unread,
Feb 25, 2009, 12:13:12 PM2/25/09
to
On Mon, Feb 23, 2009 at 02:29:32PM +0000, gm_sjo wrote:
> Now the '24' in CDEF:kWh is obviously hours but i'm wondering if there
> is any variable containing the length of the graph, in seconds,
> whatever. I did try playing with begintime but was probably
> DoinItWrong(tm) and didnt' get very far. It'd be nice if I could have
> a generic entry I can re-use without having to calculate the hours
> myself.

What version are you using? 'graphv' would be an easy way if it's
availble to you.

--
Darren

0 new messages