[rrd-users] Simple questions about RRD

A Darren Dunham ddunham at taos.com
Fri Dec 4 19:16:45 CET 2009


On Fri, Dec 04, 2009 at 11:52:33AM +1100, Jean-Yves Avenard wrote:

> I store two years of one minute data (just because I have plenty of disk space)
> 
> rrdtool create currentcost.rrd -s 60 \
> DS:total:GAUGE:600:0:U \
> DS:ch1:GAUGE:600:0:U \
> DS:ch2:GAUGE:600:0:U \
> DS:ch3:GAUGE:600:0:U \
> RRA:AVERAGE:0.5:1:1054080 \
> RRA:AVERAGE:0.5:1440:1830 \
> RRA:MIN:0.5:1:527040 \
> RRA:MIN:0.5:1440:1830 \
> RRA:MAX:0.5:1:527040 \
> RRA:MAX:0.5:1440:1830
> 
> 
> I draw my daily graph with
> $ret = exec("$RRDTOOL graph images/powerday.png -l 0 \
> -t 'POWER - DAILY' \
> -x HOUR:1:HOUR:4:HOUR:2:0:%k \
> --step 60 --end $timestamp -w $DAYWIDTH -h $DAYHEIGHT \
> DEF:total=currentcost.rrd:total:AVERAGE DEF:ch2=currentcost.rrd:ch2:AVERAGE \
> DEF:solar=solarprod.rrd:total:AVERAGE DEF:ch1=currentcost.rrd:ch1:AVERAGE \
> DEF:totalmin=currentcost.rrd:total:MIN DEF:ch2min=currentcost.rrd:ch2:MIN \
> DEF:solarmin=solarprod.rrd:total:MIN DEF:ch1min=currentcost.rrd:ch1:MIN \
> DEF:totalmax=currentcost.rrd:total:MAX DEF:ch2max=currentcost.rrd:ch2:MAX \
> DEF:solarmax=solarprod.rrd:total:MAX DEF:ch1max=currentcost.rrd:ch1:MAX \
> 
> scale is calculated so no rounding is done ....
> 
> But with the way power usage go ; it's a very broken graph... So I
> would like to show 5 minutes average instead for the daily graph...
> does calling rrdgraph with --step 300 is all that is required to get 5
> minutes average ? It doesn't seem to be a 5 minutes average to me
> looking at the generated graph ; still having big spike on the minute
> I turned on my boiler kettle. A 5 minutes average should have removed
> the skipe.

>From rrd_data:
   If consolidation needs to be done, the CF of the RRA specified in the
   DEF itself will be used to reduce the data density. This behavior can
   be changed using :reduce=<CF>. This optional parameter specifies the
   CF to use during the data reduction phase.

So your AVERAGE RRAs will be doing 5 minute averages, but your MIN and
MAX RRAs will not.

> If that's not the way, how do I graph 5 minutes average when my data
> is made of 1 minute recording ?

Specify an explicit reduction CF and step value in your graph DEF.
Here's a perl example.  Apologies for using RRDs.  It shouldn't be too
hard to translate to using 'rrdtool' directly if you prefer.

use RRDs;
use Time::Local;
my $ts = timelocal(0,0,0,1,0,2008); #1 Jan, 2008, midnight local time
my $cf = "MAX";

my $rrd_dir = "/tmp";

my $rrd = "$rrd_dir/avg_test.rrd";
RRDs::create ($rrd, "--step", "60",
              "--start", "$ts",
              "DS:total:GAUGE:600:0:U",
              "RRA:${cf}:0.5:1:5000");

# put in 1 "high" value and 4 "low" values every 5 min

foreach (0 .. 24) # 24  5 min periods => 2 hr
{
  RRDs::update ($rrd, "${ts}:16");
  $ts += 60;
  foreach (0 .. 3)
  {
    RRDs::update ($rrd, "${ts}:1");
    $ts += 60;
  }
}

my $last = RRDs::last($rrd);
# create two graphs, one normal, one at 5 min step.
my @options = (
               "--end", $last,
               "--start", "end-2h",
               "AREA:total#FF0000FF");
my $graph_dir
RRDs::graph ("$rrd_dir/norm.png",
             "DEF:total=$rrd:total:${cf}",
             @options);
RRDs::graph ("$rrd_dir/avg.png",
             "DEF:total=$rrd:total:${cf}",
             "--step", "300",
             @options);
RRDs::graph ("$rrd_dir/avg2.png",
             "DEF:total=$rrd:total:${cf}:step=300:reduce=AVERAGE",
             @options);


This uses a single "MAX" RRA and does a normal graph (no consolidation,
with spikes), a --step=300 graph (consolidation uses the RRA, so MAX
consolidation), and a graph where the consolidation is specified to be
AVERAGE.  

You can change the RRA's consolidation function at the top easily to see
how if it were AVERAGE already, there's no differences between the
second two graphs.

Hopefully that demonstrates the differences pretty well.

-- 
Darren



More information about the rrd-users mailing list