how rrdtool calculate the average value on graph?

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
chooka
Posts: 3
Joined: Fri Jun 27, 2008 7:46 am

how rrdtool calculate the average value on graph?

Post by chooka »

Hello,

Maybe i ask a stupid question but i tried to calculate the average value for some of my graph generated in cacti, and i can't find the same value as the one on the graph.

I wrote a simple perl script to extract value from the rrd file using rrd fetch, then add all of them multiplicated by the delta time for each.

here is the code :

Code: Select all

  #!/usr/bin/perl
  use strict;
  use Getopt::Std;
  use vars qw($opt_r);

  getopts('r:');

  # extract the value for the last day (my polling time is 10)
  my @values = `rrdtool fetch $opt_r AVERAGE -s -86400 -e -10`;  
  
  my $MAX_in = 0;
  my $AVG_in = 0;
  my $MAX_out = 0;
  my $AVG_out = 0;
  my $first_time = 0;
  my $last_time = 0;
  my $time_max_in = 0;
  my $time_max_out = 0;
    
  foreach my $value (@values)
  {
    my ($cur_time , $cur_AVG_in, $cur_AVG_out) = {0,0,0};
    
    ($cur_time , $cur_AVG_in, $cur_AVG_out) = split(" ", $value);
    
    $cur_time =~ s/://;
    
    if ( $cur_time <= 0 || $cur_AVG_in eq "nan" || $cur_AVG_out eq "nan" ) {
      print "value (value error) : $value\n\n";
      next;
    }
    
    if ( $first_time == 0) {
      $first_time = $cur_time;
      $last_time = $cur_time;
      next;
    }
    
    $AVG_in += $cur_AVG_in*8*($cur_time - $last_time);
    $AVG_out += $cur_AVG_out*8*($cur_time - $last_time);
    
    if ( $cur_AVG_in*8 > $MAX_in )
    {
      $MAX_in = $cur_AVG_in*8;
      $time_max_in = $cur_time;
    }
  
    if ( $cur_AVG_out*8 > $MAX_out )
    {
      $MAX_out = $cur_AVG_out*8;
      $time_max_out = $cur_time;
    }
    
    $last_time = $cur_time;
  }
  
  
  print "total in : $AVG_in\n";
  print "total out : $AVG_out\n";
  $AVG_in = $AVG_in / ( $last_time - $first_time );
  $AVG_out = $AVG_out / ( $last_time - $first_time );      
  
    
  print "result from $first_time to $last_time (".($last_time - $first_time).") \n";
  print "AVG_in = $AVG_in MAX_in = $MAX_in ($time_max_in)\n";
  print "AVG_out = $AVG_out MAX_out = $MAX_out ($time_max_out)\n";
my polling time is 10s for the first 24h.

the maximum values are exact but the average value are always false...
i have the good number of value (using wc or a counter in the script) and the times values are ok.

Maybe someone know how rrdtool calculate the average value on graph, maybe there is something different...

here is the rrd file generation command line :

Code: Select all

/usr/bin/rrdtool create \
file.rrd \
--step 10  \
DS:traffic_in:COUNTER:600:0:1000000000 \
DS:traffic_out:COUNTER:600:0:1000000000 \
RRA:AVERAGE:0.5:1:18000 \
RRA:AVERAGE:0.5:6:9000 \
RRA:MAX:0.5:1:18000 \
RRA:MAX:0.5:6:9000 \
Thanks in advance for the help :)

(PS : sorry for my english, i come from France, and my english is not very very good...)
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

This is more of an rrdtool question. You may ask it on the rrdtool-users mailing list providing the data you've posted here. They will need the whole rrdtool graph statement as well. Find it at Graph management and switch to debug after selecting your graph
Reinhard
chooka
Posts: 3
Joined: Fri Jun 27, 2008 7:46 am

Post by chooka »

i'll try the rrdtool-mailing list as well, but as it seems important, here is the rrdtool graph command :

Code: Select all

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-10 \
--title="device - Traffic - Slot x, Port x" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="bits per second" \
DEF:a="/local/home/Network/cacti/cacti/rra/file.rrd":traffic_in:MAX \
DEF:b="/local/home/Network/cacti/cacti/rra/file.rrd":traffic_out:MAX \
CDEF:cdefa=a,8,* \
CDEF:cdefe=b,8,* \
AREA:cdefa#00CF00:"Inbound"  \
GPRINT:cdefa:LAST:" Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:cdefe#002A97:"Outbound"  \
GPRINT:cdefe:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefe:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefe:MAX:"Maximum\:%8.2lf %s\n"
chooka
Posts: 3
Joined: Fri Jun 27, 2008 7:46 am

Post by chooka »

I finnaly found my mistake.

My script is correct, the value are right.

It seems that the average values on the graphs depends on the consolidation fonction of the data shown on the graph (area/line).

I like to see the max values on the graph, so i changed the consolidation fonction on the graph template to show max value instead of average on the graph. I think it's better to see the bandwidth utilisation as on the webinterface, if the time period shown is too big, the average CF reduce the max value and you can't see clearly when the total bandwidht is used.

On my rrdtool graph command, here is my personnal change :

...
DEF:a="/local/home/Network/cacti/cacti/rra/file.rrd":traffic_in:MAX \
DEF:b="/local/home/Network/cacti/cacti/rra/file.rrd":traffic_out:MAX \

...

In order to have the right average values, i only added items in the graph with AVERAGE values and it work perfectly.

DEF:a="/local/home/Network/cacti/cacti/rra/file.rrd":traffic_in:MAX \
DEF:b="/local/home/Network/cacti/cacti/rra/file.rrd":traffic_out:MAX \
DEF:c="/local/home/Network/cacti/cacti/rra/file.rrd":traffic_in:AVERAGE \
DEF:d="/local/home/Network/cacti/cacti/rra/file.rrd":traffic_out:AVERAGE \


After this change, the average Gprint use the good item to calculate his value.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests