Search code examples
ubuntucronrrdtool

rrdtool fetch returns all -nan


Create db:

rrdtool create test.rrd --step 60 --start N DS:mem:GAUGE:60:U:U RRA:LAST:0.5:12:24 RRA:MAX:0.5:12:24 RRA:MIN:0.5:12:24 RRA:AVERAGE:0.5:12:24

Then I create get_mem.sh:

#!/bin/bash

export PATH=/usr/local/rrdtool/bin/rrdtool:/usr/local/rrdtool/bin/rrdtool:/home/parallels/bin:/home/parallels/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:$PATH


RRDTOOL='/usr/local/rrdtool/bin/rrdtool'
FILE='test.rrd'
COMMAND=`cat /proc/meminfo | grep MemFree | grep -oE '[0-9]+' | awk '{print $1}'`
$RRDTOOL updatev $FILE N:$COMMAND
echo $COMMAND >> log.txt

and cron task:

0-55/1 * * * * ./get_mem.sh

I tried to run from myself and from root (result is similar)

So, I try to fetch my values:

rrdtool fetch test.rrd AVERAGE -s 1509908400

screen

(all fetch types show -nans)

dump is similar: screen

log.txt (just make sure): screen

What am I doing wrong?


Solution

  • You don't say how many data samples you have added; you'll need at least 13 to have any chance of anything other then NaN in your output.

    You definitely have these problems --

    • Your Step size is 60s, but your DS Heartbeat is also 60s. This means you need to have samples more often than 59s for them to be valid. Generally, your heartbeat should be twice the step size.
    • Your cronjob is collecting data every minute from 0 to 55. What about minutes 56-59? Also, if this is collecting every minute, then this is right on your heartbeat boundary, so it will likely store NaN.
    • Your smallest RRA has 1cdp=12pdp. This might be what you want; but bear in mind that you'll need 12 sequential valid data points in order to get one entry in your RRA. Maybe add an RRA with 1cdp=1pdp?

    I would suggest you create the RRD like this:

    rrdtool create test.rrd --step 60 --start N \
        DS:mem:GAUGE:120:0:U \
        RRA:AVERAGE:0.5:1:24 \
        RRA:LAST:0.5:12:24 RRA:MAX:0.5:12:24 \
        RRA:MIN:0.5:12:24 RRA:AVERAGE:0.5:12:24