Fixing RRDTool errors from btmon

Post any 3rd party software here.
Post Reply
Peter_V
Posts: 23
Joined: Sat Feb 19, 2011 10:03 am

Fixing RRDTool errors from btmon

Post by Peter_V » Sun Feb 02, 2014 12:06 pm

Hi folks,

Not sure if anyone else has had this problem, but recently I saw a couple channels that showed huge negative values.

I traced it down and figured out that when the RRDTool database was created it didn't have minimum values set on several channels. This means when the registers from the ECM-1240 (or GEM) roll over you end up with a reading that is much lower than the previous reading.
Since it's not possible to have a negative value, setting a minimum value of 0 causes RRDtool to store a NaN (unknown value) for that one reading.

To find out if a channel has a minimum value set for aux4 you can use the following command:
rrdtool info /var/rrd/313895_aux4_ws.rrd
if the minimum value reads NaN, then it's not set (should read 0)
Note: the name of your rrd file will most likely be different. Use the actual name of your file.

To fix this problem (and set a minimum value of 0) you can use the following command:
rrdtool tune /var/rrd/313895_aux4_ws.rrd -i aux4_ws:0

Now comes the fun part. If you have already recorded a negative value in your database you can fix it with this one line Perl program (note you need to have Perl installed on your system):

rrdtool dump "/var/rrd/313895_aux4_ws.rrd"|perl -ne '$a=$_; $a =~ /(-{1}\d\.\d+e\+\d\d)/; if ($1 < 0) {$a =~s/-{1}\d\.\d+e\+\d\d/NaN/;}print $a;'|rrdtool restore -f - "/var/rrd/313895_aux4_ws.rrd"

Note: The above is all one line and assumes you are running Linux. If you are running windows you will probably need to change it some. The file name shows up in two places in that line, you'll need to change them both the match the name of your file.

Basically what this line does is runs an RRDtool dump of the database, pipes the output through a perl script that looks for any negative values and replaces them with NaN. Then pipes this back to RRDtool restore.
It takes a few minutes to run.

Hope this helps.
Post Reply