[rrd-users] RRDs Coding Question - Dynamic Multiple RRD Data Sources

Simon Hobson linux at thehobsons.co.uk
Wed Sep 26 08:38:29 CEST 2012


Wesley Wyche wrote:

>            "CDEF:usravg=usrdat,1,1,*,*",
>            "CDEF:nicavg=nicdat,1,1,*,*",
>            "CDEF:sysavg=sysdat,1,1,*,*",
>            "CDEF:idlavg=idldat,1,1,*,*",
>
>Don't understand why I would waste cycles multiplying by 1 twice, but that
>was the code I originally found in an example script long ago.

And you go propagating it onwards. It does nothing but (as you say) 
waste CPU cycles. Just drop it.

>"CDEF:usravg=usrdat0,1,1,*,*,usrdat1,1,1,*,*,+,usrdat2,1,1,*,*,+,usrdat3,1,1,*,*,+"
>"CDEF:nicavg=nicdat0,1,1,*,*,nicdat1,1,1,*,*,+,nicdat2,1,1,*,*,+,nicdat3,1,1,*,*,+"
>"CDEF:sysavg=sysdat0,1,1,*,*,sysdat1,1,1,*,*,+,sysdat2,1,1,*,*,+,sysdat3,1,1,*,*,+"
>"CDEF:idlavg=idldat0,1,1,*,*,idldat1,1,1,*,*,+,idldat2,1,1,*,*,+,idldat3,1,1,*,*,+"

...

>The graph is generated, but i get a single line in the middle.

Don't forget that in these calculations, if ANY value is unknown 
(NAN) then the sum of that and the other values will also be unknown.

There are two ways round this, one being to convert the unknowns to zero :

aa=a,UN,0,a,IF
(if a is unknown then choose 0, else choose a)
but this will mean you always get a line on the graph even if there 
is no data at all.

Or if you want to preserve there being no data at some points, then 
it's a bit more involved (not a lot)
ab=a,UN,b,a,b,+,IF
(if a is unknown, then choose b, else choose a+b)
At this point, you either have a number (a+b), or unknown if a and b 
are unknown. Then :
abc=ab,UN,c,ab,c,+,IF
which adds c into the mix. Repeat as required.
You can of course roll up a whole lot into one RPN expression which 
will become somewhat hard to follow later !

Bear in mind that (unless you avoid consolidation altogether) then 
you cannot add MIN and MAX values together. Consider the case where, 
at every update, the values total to 1 - but the distribution is such 
that occasionally that unit may go to just one RRD. Also, over time, 
the distribution is such that all the RRDs get 1/4.
Once consolidated, you'll find that average is 0.25, but min is 0, 
and max is 1 in each RRD. However, we never had more than 1 in any 
update, nor did we ever have less than 1. Somehow we've ended up with 
a min of 0, and a max of 4.

-- 
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.



More information about the rrd-users mailing list