# [rrd-users] VDEFs and handling NaNs....

Alex van den Bogaerdt alex at ergens.op.het.net
Fri Apr 27 20:02:02 CEST 2007

```On Fri, Apr 27, 2007 at 11:05:19AM -0600, David Ball wrote:

>   I'm trying to (re)interpret the docs for VDEFs, but wouldn't mind a
> little clarification if possible.  If my rrd has a ton of NaNs in it,
> and I have a DS defining, say, bits/sec, and then I use a VDEF to
> determine AVERAGE or PERCENT, are the NaNs assumed to be 0s?  Are they
> included in the calculations at all ?  Or are only the 'real' values
> in the .rrd included when calculating PERCENT, AVERAGE, etc ?

PERCENT: NaNs stay in the dataset.  They are considered lower than
anything else (even lower than negative infinity).
If PERCENT returns NaN, you had a huge amount of them.

AVERAGE and TOTAL:
Count the number of entries with finite rates (not NaN).  Add up all
rates in those.  Then multiply by step size (for TOTAL) or divide by
number of entries (for AVERAGE).  If this return NaN, there were no
entries with finite data.

MAXIMUM and MINIMUM:
Skip unknowns.  If this returns NaN, all entries were unknown.

This was produced from memory and looking at a (not: the most current)
source.  YMMV.  If in doubt, setup a database, enter some known data
as well as some NaNs, and and process it.  You know what you've put
in, so compare what you expect to see and what you actually get.

One example, because I feel like it...

average(NaN,1,2,3,NaN,NaN) will be 2 or 1, depending on whether
NaNs are (1) or are not (2) included:

- if NaNs are considered zero:
average(NaN,1,2,3,NaN,NaN)
average(0,1,2,3,0,0)
0+1+2+3+0+0 = 6
number of entries = 6
average = 1
- if NaNs are taken out:
average(NaN,1,2,3,NaN,NaN)
average(1,2,3)
1+2+3 = 6
number of entries = 3
average = 2

So, we test:

(
echo create test.rrd --start 1177624800 DS:test:GAUGE:300:U:U RRA:AVERAGE:0:1:6
echo update test.rrd 1177625100:U 1177625400:1 1177625700:2 1177626000:3 1177626300:U 1177626600:U
echo dump test.rrd
echo graph --start 1177624800 --end 1177626600 bla DEF:test=test.rrd:test:AVERAGE VDEF:test_average=test,AVERAGE PRINT:test_average:%6.2lf PRINT:test:AVERAGE:%6.2lf
) | rrdtool -

--
Alex van den Bogaerdt
http://www.vandenbogaerdt.nl/rrdtool/

```