RRDTool works best when recording a rate. Therefore, by using a COUNTER
DS type, you can change your periodic kWh total to a point-in-time W value in the database.
For example, if you are sampling every minute, then you can multiply your kWh by 3600000 (to get Watt-seconds, or Joules) and have RRDTool use a COUNTER type to convert this to a per-second rate, or Watts (it is always better to store the data in SI units for clarity and simplicity).
You can then display or calculate this by multiplying by the step size.
For example, if you wish to see a graph of kWh used per day, you need to have a 1-day granularity RRA defined. Then, you can fetch the data from this (either using rrdtool fetch
, or rrdtool graph
with a specific data granularity) and have a calculated value obtained by multiplying the average Watts by the Interval, and then dividing by 3600000 to get kWh.
This creates an RRD file with a 1-minute sample rate, to store watts.
rrdtool create power.rrd --step 60 \
DS:watts:COUNTER:120:0: \
RRA:AVERAGE:0.5:1:86400 \
RRA:AVERAGE:0.5:1440:400
This will update the RRD, given your latest sample of kWh
JOULES=`expr $KWH \* 3600000`
rrdtool update power.rrd N:$JOULES
This will graph the daily usage, in kWh, over a month
rrdtool graph graph.png \
--end now --start "end-1month" --step 86400 \
--title "Power usage per day" --vertical-label "kWh" \
--units-exponent 0 \
DEF:watts=power.rrd:watts:AVERAGE:step=86400 \
CDEF:kwh=watts,STEPWIDTH,*,3600,/,1000,/ \
VDEF:totkwh=watts,TOTAL,3600000,/ \
GRPINT:totkwh:"Total kWh this month: %.0lf kWh"
You can, of course, modify this to your needs. You may want different RRAs, or graphing steps, or summarisation.