[rrd-users] last average is NaN?

Alex van den Bogaerdt alex at vandenbogaerdt.nl
Wed Jan 14 04:13:04 CET 2009

First a line off topic: Am I the only one having trouble to 'reply all' to 
the topic starter?  I know my mail+news client sucks, but this is the first 
time I see the problem that a reply would be sent to my news server...

----- Original Message ----- 
From: "Levente Kovacs" <leventelist at gmail.com>
To: <rrd-users at lists.oetiker.ch>
Sent: Monday, January 12, 2009 1:48 AM
Subject: [rrd-users] last average is NaN?

> Hi list,
> I think rrdtool is great. I use to collect data of my thermometer project.
> Thank you for the implementation.
> http://logonex.eu/tc/
> My only question is why is that so that the last average is allways "NaN"?
> # rrdtool fetch temperature.rrd AVERAGE
> .
> .
> .
> 1231721100: 2.6959898817e+01 2.3159899759e+01 2.3597679153e+01
> 1231721400: nan nan nan

You get what you ask, not what rrdtool thinks you probably ment to ask. This 
is a good thing, as computer programs aren't good in guessing. They would 
often guess right, meaning they sometimes guess wrong. It's better if you 
are in control, provided that you ask the right questions.

Try the following two almost identical examples:

(adjust these timestamps to the current timestamps you see)
rrdtool fetch temperature.rrd --end 1231721100
rrdtool fetch temperature.rrd --end 1231721101

Notice the difference? You are not, then you are, asking for data after 

The last update was somewhere between 1231721100 and 1231721400, but what 
matters here is which data is consolidated into an RRA. Not all of the data 
between 1231721100 and 1231721400 is known, this is filled in as soon as you 
do an update at or after 1231721400.

Later, when you understand more of rrdtool, visit my site ( 
http://www.vandenbogaerdt.nl/rrdtool/ ) and read about normalization, 
consolidation and such.

A quick(ish) fix is:

1: rrdtool last temperature.rrd
this returns a number, such as 123172105

2: echo 1231721105/300*300|bc
this performs an integer division and multiplication, resulting in 123172100

3: rrdtool fetch --end 123172100 temperature.rrd AVERAGE

And of course you should use a variable instead of the numer 123172105 and 

ts=`rrdtool last temperature.rrd`
ts=`echo $ts/300*300|bc`
rrdtool fetch --end $ts temperature.rrd AVERAGE

shorter equivalent in bash:

rrdtool fetch --end $(($(rrdtool last temperature.rrd)/300*300)) 
temperature.rrd AVERAGE

And there will be many more possible solutions, this is not a contest.


More information about the rrd-users mailing list