[rrd-users] Question about averaging daily ; but with 5 min. steps

Alex van den Bogaerdt alex at vandenbogaerdt.nl
Tue Dec 15 16:12:42 CET 2009

Sorry for the top-posting.  I don't like this myself, but I do not want to 
fix the quotation again (I get no "> " in front of your message when I 
reply; probably my client's fault).

"CDEF:cexport=ctotal,csolar,-,0,MAX" results in power consumed from the net, 
not power delivered to the net.  If that statement is truly a summary of 
your large script, then it is wrong. Else, the summary you gave is wrong.

"Resolution must be 5 minutes, no matter the graph resolution" is not 
relevant when using PRINT as I suggested. Yes, indeed you will need to feed 
that value back to rrdtool if you want to use it later in a graph.

At input time, but still outside rrdtool (so: in your collector script) you 
can do:
balance=ctotal-csolar; if (balance>0) then balance=0
This results in this negative number you describe, when you actually used 
less than you produced.

Then feed balance to rrdtool as a separate datasource. It results in Joules 
actually delivered to the net and will, even after consolidation, provide an 
accurate number of Joules delivered to the net over a certain time frame.

If this means you need to fire up rrdtool to compute ctotal, then I'm afraid 
this is almost unavoidable.
Almost, because with significant programming you should be able to modify 
RRDtool in such a way that it will do its computations on the desired 
resolution before adapting this resolution to match the graph's resolution. 
This will result in extra work (for RRDtool, at graph time), so maybe it's 
better to just take your losses and do compute ctotal at each update.

And now I'm going back to lurk mode.

----- Original Message ----- 
From: "Jean-Yves Avenard" <jyavenard at gmail.com>
To: "Alex van den Bogaerdt" <alex at vandenbogaerdt.nl>
Cc: <rrd-users at lists.oetiker.ch>
Sent: Tuesday, December 15, 2009 1:41 PM
Subject: Re: [rrd-users] Question about averaging daily ; but with 5 min. 


2009/12/15 Alex van den Bogaerdt <alex at vandenbogaerdt.nl>:
> Then, when you subtract your usage from your generated power, with a 
> minimum
> of zero, you end up with the amount of Joules you did generate but not use
> yourself. The remainder is fed to the net. You want to know how much that
> amount is. Correct?

correct, but that value *must* be calculated on 5 minutes average ; at
all time, no matter the resolution requested.

> Assuming that "ctotal" is the amount of power used, and "csolar" is the
> amount of power generated:
> I think you wrote this summary backwards, or else this is where your 
> problem
> is. It should be
> CDEF:cexport=csolar,ctotal,-,0,MAX

I don't have it backward. If  you look at the graph I'm generating,
you'll see that I put it underneath the individual power output ; with
the feed-in tarif shown underneath.

So I made the calculation in that order to provide a negative result.

It looks nicer that way :)

> The average of that amount of Joules during a certain time frame (such as
> 86400 seconds), multiplied by the number of seconds, is the amount of
> Joules. And converting that to Wh or kWh is just a matter of multiplying
> (using CDEF) before letting RRDtool compute its average.

but then the average isn't done on the 5 minutes interval but on
86400s intervals..
Look at my example I posted this morning. You'll see that doing the
calculation on daily interval gives an entirely different result than
if performed on daily average.

> You could, for instance, let RRDtool generate a report without graphing. 
> Use
> PRINT (not: GPRINT) to write the average.
> rrdtool graph nothing --start $midnight1 --end start+24h DEF:ctotal=....
> DEF:csolar=... CDEF:cexport=csolar,ctotal,-,0,MAX,86400,*,3600,/
> PRINT:cexport:AVERAGE:%6.2lf
> (you need to add several lines, for instance make sure there are no
> unknowns)
> For every 5-minute slot: if you produced more than you used, it turns up 
> as
> a positive number. If you produced less than you used, it turns up as 
> zero.
> A smaller example (one day would be too much): 0, 0, 10, 20, 50, 40, 0, 0,
> 0, 0
> During 6 intervals you used less than you produced. 10+20+50+40=120. When
> RRDtool is averaging this, it would compute 120/12=10. When multiplied 
> with
> the amount of time, 12 in my example, you end up with 120 which is, not
> surprisingly, the same as 10+20+50+40.
> In this example I used unnamed units. The result is the same if I work in
> kWh, Wh, time slots of 300 seconds, etc.

But then, how do you feed back that info back to RRD?

that's not very elegant..

Obviously, I could run a cron every 5 minutes that calculate the
average of both the usage and the solar output, then store it in a RRD
database ... This would do the job, but where is the fun in that ? :P

More information about the rrd-users mailing list