0

I am using RRDtool to graph the status of a pump on my Raspberry Pi. I must be doing some configuration wrong, since the values are close to what I am inputting, but not exact.

The pin status should be either 1 or 0.

<!-- 2014-03-10 10:24:00 CDT / 1394465040 --> <row><v>NaN</v></row> <!-- 2014-03-10 10:25:00 CDT / 1394465100 --> <row><v>NaN</v></row> <!-- 2014-03-10 10:26:00 CDT / 1394465160 --> <row><v>1.0000000000e+00</v></row> <!-- 2014-03-10 10:27:00 CDT / 1394465220 --> <row><v>2.3711630000e-01</v></row> <!-- 2014-03-10 10:28:00 CDT / 1394465280 --> <row><v>9.8168226667e-01</v></row> <!-- 2014-03-10 10:29:00 CDT / 1394465340 --> <row><v>1.6624716667e-02</v></row> <!-- 2014-03-10 10:30:00 CDT / 1394465400 --> <row><v>9.8544061667e-01</v></row> <!-- 2014-03-10 10:31:00 CDT / 1394465460 --> <row><v>2.9590616667e-02</v></row> <!-- 2014-03-10 10:32:00 CDT / 1394465520 --> <row><v>9.7204963333e-01</v></row> <!-- 2014-03-10 10:33:00 CDT / 1394465580 --> <row><v>2.6263616667e-02</v></row> <!-- 2014-03-10 10:34:00 CDT / 1394465640 --> <row><v>9.7533411667e-01</v></row> <!-- 2014-03-10 10:35:00 CDT / 1394465700 --> <row><v>2.3075633333e-02</v></row> <!-- 2014-03-10 10:36:00 CDT / 1394465760 --> <row><v>9.7849575000e-01</v></row> <!-- 2014-03-10 10:37:00 CDT / 1394465820 --> <row><v>1.9948233333e-02</v></row> <!-- 2014-03-10 10:38:00 CDT / 1394465880 --> <row><v>9.8158333333e-01</v></row> <!-- 2014-03-10 10:39:00 CDT / 1394465940 --> <row><v>1.6888216667e-02</v></row> <!-- 2014-03-10 10:40:00 CDT / 1394466000 --> <row><v>9.2141166667e-01</v></row> <!-- 2014-03-10 10:41:00 CDT / 1394466060 --> <row><v>5.2411610000e-01</v></row> <!-- 2014-03-10 10:42:00 CDT / 1394466120 --> <row><v>5.2411610000e-01</v></row> <!-- 2014-03-10 10:43:00 CDT / 1394466180 --> <row><v>9.6672030000e-01</v></row> <!-- 2014-03-10 10:44:00 CDT / 1394466240 --> <row><v>5.0939110833e-01</v></row> <!-- 2014-03-10 10:45:00 CDT / 1394466300 --> <row><v>5.0939110833e-01</v></row> <!-- 2014-03-10 10:46:00 CDT / 1394466360 --> <row><v>4.9845539167e-01</v></row> <!-- 2014-03-10 10:47:00 CDT / 1394466420 --> <row><v>4.9845539167e-01</v></row> <!-- 2014-03-10 10:48:00 CDT / 1394466480 --> <row><v>9.9399037500e-01</v></row> <!-- 2014-03-10 10:49:00 CDT / 1394466540 --> <row><v>9.9399037500e-01</v></row> <!-- 2014-03-10 10:50:00 CDT / 1394466600 --> <row><v>2.6977033333e-02</v></row> <!-- 2014-03-10 10:51:00 CDT / 1394466660 --> <row><v>9.7898348333e-01</v></row> <!-- 2014-03-10 10:52:00 CDT / 1394466720 --> <row><v>9.7898348333e-01</v></row>

create_db.sh #!/bin/bash rrdtool create pinstats.rrd \ --step 60 \ DS:pump:GAUGE:600:0:1 \ RRA:MAX:0.5:1:2016

update.sh

#!/bin/sh a=0 while [ "$a" == 0 ]; do echo "pump ondate" /home/pi/on.sh /home/pi/graph.sh pump=1 rrdtool update pinstats.rrd N:$pump sleep 60 echo "pump offdate" /home/pi/off.sh /home/pi/graph.sh pump=0 rrdtool update pinstats.rrd N:$pump sleep 120 done

1 Answers1

0

You are being affected by Data Normalisation.

This will adjust your values according to a linear approximation in order to make the time point lie on an interval boundary. IE, if your Interval is 5min, then the updated value will be as it was at 12:00, 12:05, 12:10 ... etc

This makes sense if you are graphing a large number which is a rate; the overall averages still work out and the data are at regular intervals. However, if you are using a Gauge data type with small integers it becomes problematic.

In order to avoid this, you have to update on an interval boundary rather than using N as your time point.

Try this shell code:

interval=60
timestamp=`date +%s`
num_intervals=`expr $timestamp / $interval`
adjusted_time=`expr $num_intervals '*' $interval`
rrdtool update pistats.rrd $adjusted_time:1
sleep $interval
adjusted_time=`expr $adjusted_time + $interval`
rrdtool update pistats.rrd $adjusted_time:0

This code ensures that the update times are exactly on an interval boundary, and hence no Data Normalisation is performed (actually, it becomes a null operation).

For more details, see Alex van den Bogaerdt's excellent tutorial here.

Steve Shipway
  • 3,754
  • 3
  • 22
  • 39
  • Thanks Steve for your answer... This makes sense for the X-axis, but not the Y-axis. I am inputting a 0 or a 1 to the database, and when querying found the values above. You can see they are CLOSE to 0 and 1, but are not. `0.2371163 0.981682267 0.016624717`, etc. Any idea why the values are changing? Is my data source the wrong type? – user2748032 Mar 11 '14 at 14:30
  • The Data Normalisation adjusts the value at the same time as the time, so the Y-axis IS affected. The tutorial (linked above) explains it all in great detail. – Steve Shipway Aug 02 '14 at 08:58