[rrd-users] Undesired fractions

Simon Hobson linux at thehobsons.co.uk
Mon Dec 17 22:48:27 CET 2007

Jan Engelhardt wrote:

>we observed

correct behaviour !

>that in the following testcase, the RRA accumulates numbers
>with a fractional part, which is undesired for our purpose.
>	#!/bin/bash
>	rrdtool create foo.rrd --step 1 DS:foo:GAUGE:120:U:U RRA:LAST:0:1:60;
>	rrdtool update foo.rrd N:0;
>	sleep 1;
>	rrdtool update foo.rrd N:1;
>	# Show problem
>	rrdtool dump foo.rrd | grep '\.[1-9]';
>How could this be solved so that the RRA only ever contains integers and
>does not average over two values?
>What's more, the value that gets record in the RRA seems to depend on
>the moon phase,

No, it depends on what you put in - remember, garbage in, garbage out

>  or at least the subsecond granularity of bash execution
>time and sleep wait time:
>	$ sh ts
>	<value> 3.2619000000e-02 </value>
>	<primary_value> 9.7739700000e-01 </primary_value>
>	<!-- 2007-12-17 21:34:05 CET / 1197923645 -->
>	<row><v> 9.7739700000e-01 </v></row>
>	$ sh ts
>	<value> 1.6257900000e-01 </value>
>	<primary_value> 8.4968000000e-01 </primary_value>
>	<!-- 2007-12-17 21:34:08 CET / 1197923648 -->
>	<row><v> 8.4968000000e-01 </v></row>

This comes up regularly so try the archives. The data is normalised 
to a rate, so if you want to get out exactly what you put in then you 
MUST supply updates with timestamps that EXACTLY match your steps - 
not "just about" but exactly.

In bash, you can do something like (IIRC) :

now=`date +%s`
now=$(( ${now} / 60 * 60 ))
# 60 is your step size, this gets the last date value which is an 
exact multiple of your step
# set your values here
rrdtool update foo.rrd ${now}:....

I suggest you go to http://www.vandenbogaerdt.nl/rrdtool/ and read 
the page that explains normalisation.

More information about the rrd-users mailing list