[rrd-users] Strange behavior when using CDEF to divide two values

Wesley PA4WDH pa4wdh at yahoo.com
Sun Feb 17 11:13:17 CET 2013


Hi All,

I'm running some rrdtool data collection and i see some strange behavior when i try to divide two DS's with a CDEF.

I'm collecting the length of traffic jams and the number of traffic jams in my country and store them in a rrd database. All is well and graphs look good. Now i would like to calculate the average length by dividing the total length with the number. I thought this would be easy by just writing a CDEF:AVG=LENGTH,COUNT,/ line and graphing AVG ... but how wrong could i be .. :-)

First i got a lot of high spikes in my graph. I noticed this happened when the "COUNT" was 0, so actually a division by zero. I thought this would render to NaN but it didn't :-) I solved this by storing NaN in the rrd when the value is 0. Are there any other/better solutions ?

Now the graph looks nice but the value isn't correct. I saved some files for you to see: http://ernstagn.home.xs4all.nl/rrd/
Here you see the three graphs (length number and average) and dump.xml is a "rrdtool dump" xml of the database.
You can see that the value plotted for the average is not correct given the input values. For example at 11:00 at the left of the graph: Total length was 12km, and the number was 4, so the average should be 3. However, the average graph plots at about 1.7.
During midnight there is a similar example: There are 4 traffic jams of about 8km, but the average hardly plots above 0.
I've tried with "length" and "count" swapped in the RPN, but that didn't work out either.

Just to make sure i'm not making any mistake with the calculation i tried to make an awk script which does the same with an xml export and there i get the values i'd expect.

Does anyone know how to solve this ? I'm using rrdtool version 1.4.7.

Thanks in advance.

Best regards,
Wesley



More information about the rrd-users mailing list