<span class="postbody"><font size="2">Hello, <br /><br />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. <br /><br />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. <br /><br />here is the code : <br /><br /></font></span><table border="0" cellspacing="1" cellpadding="3" width="90%" align="center"><tbody><tr><td><span class="genmed"><strong><font size="2">Code:</font></strong></span></td></tr><tr><td class="code">&nbsp; #!/usr/bin/perl <br />&nbsp; use strict; <br />&nbsp; use Getopt::Std; <br />&nbsp; use vars qw($opt_r); <br /><br />&nbsp; getopts('r:'); <br /><br />&nbsp; # extract the value for the last day (my polling time is 10) <br />&nbsp; my @values = `rrdtool fetch $opt_r AVERAGE -s -86400 -e -10`;&nbsp; <br />&nbsp; <br />&nbsp; my $MAX_in = 0; <br />&nbsp; my $AVG_in = 0; <br />&nbsp; my $MAX_out = 0; <br />&nbsp; my $AVG_out = 0; <br />&nbsp; my $first_time = 0; <br />&nbsp; my $last_time = 0; <br />&nbsp; my $time_max_in = 0; <br />&nbsp; my $time_max_out = 0; <br />&nbsp; &nbsp; <br />&nbsp; foreach my $value (@values) <br />&nbsp; { <br />&nbsp; &nbsp; my ($cur_time , $cur_AVG_in, $cur_AVG_out) = {0,0,0}; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; ($cur_time , $cur_AVG_in, $cur_AVG_out) = split(&quot; &quot;, $value); <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; $cur_time =~ s/://; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; if ( $cur_time &lt;= 0 || $cur_AVG_in eq &quot;nan&quot; || $cur_AVG_out eq &quot;nan&quot; ) { <br />&nbsp; &nbsp; &nbsp; print &quot;value (value error) : $value\n\n&quot;; <br />&nbsp; &nbsp; &nbsp; next; <br />&nbsp; &nbsp; } <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; if ( $first_time == 0) { <br />&nbsp; &nbsp; &nbsp; $first_time = $cur_time; <br />&nbsp; &nbsp; &nbsp; $last_time = $cur_time; <br />&nbsp; &nbsp; &nbsp; next; <br />&nbsp; &nbsp; } <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; $AVG_in += $cur_AVG_in*8*($cur_time - $last_time); <br />&nbsp; &nbsp; $AVG_out += $cur_AVG_out*8*($cur_time - $last_time); <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; if ( $cur_AVG_in*8 &gt; $MAX_in ) <br />&nbsp; &nbsp; { <br />&nbsp; &nbsp; &nbsp; $MAX_in = $cur_AVG_in*8; <br />&nbsp; &nbsp; &nbsp; $time_max_in = $cur_time; <br />&nbsp; &nbsp; } <br />&nbsp; <br />&nbsp; &nbsp; if ( $cur_AVG_out*8 &gt; $MAX_out ) <br />&nbsp; &nbsp; { <br />&nbsp; &nbsp; &nbsp; $MAX_out = $cur_AVG_out*8; <br />&nbsp; &nbsp; &nbsp; $time_max_out = $cur_time; <br />&nbsp; &nbsp; } <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; $last_time = $cur_time; <br />&nbsp; } <br />&nbsp; <br />&nbsp; <br />&nbsp; print &quot;total in : $AVG_in\n&quot;; <br />&nbsp; print &quot;total out : $AVG_out\n&quot;; <br />&nbsp; $AVG_in = $AVG_in / ( $last_time - $first_time ); <br />&nbsp; $AVG_out = $AVG_out / ( $last_time - $first_time );&nbsp; &nbsp; &nbsp; <br />&nbsp; <br />&nbsp; &nbsp; <br />&nbsp; print &quot;result from $first_time to $last_time (&quot;.($last_time - $first_time).&quot;) \n&quot;; <br />&nbsp; print &quot;AVG_in = $AVG_in MAX_in = $MAX_in ($time_max_in)\n&quot;; <br />&nbsp; print &quot;AVG_out = $AVG_out MAX_out = $MAX_out ($time_max_out)\n&quot;;</td></tr></tbody></table><span class="postbody"><br /><br /><font size="2">my polling time is 10s for the first 24h. <br /><br />the maximum values are exact but the average value are always false... <br />i have the good number of value (using wc or a counter in the script) and the times values are ok. <br /><br />Maybe someone know how rrdtool calculate the average value on graph, maybe there is something different... <br /><br />here is the rrd file generation command line : <br /><br /></font></span><table border="0" cellspacing="1" cellpadding="3" width="90%" align="center"><tbody><tr><td><span class="genmed"><strong><font size="2">Code:</font></strong></span></td></tr><tr><td class="code">/usr/bin/rrdtool create \ <br />file.rrd \ <br />--step 10&nbsp; \ <br />DS:traffic_in:COUNTER:600:0:1000000000 \ <br />DS:traffic_out:COUNTER:600:0:1000000000 \ <br />RRA:AVERAGE:0.5:1:18000 \ <br />RRA:AVERAGE:0.5:6:9000 \ <br />RRA:MAX:0.5:1:18000 \ <br />RRA:MAX:0.5:6:9000 \</td></tr></tbody></table><span class="postbody"><br /><br /><font size="2">here is the rrdtool graph command : <br /><br /></font><table border="0" cellspacing="1" cellpadding="3" width="90%" align="center"><tbody><tr><td><span class="genmed"><strong><font size="2">Code:</font></strong></span></td></tr><tr><td class="code">/usr/bin/rrdtool graph - \ <br />--imgformat=PNG \ <br />--start=-86400 \ <br />--end=-10 \ <br />--title=&quot;device - Traffic - Slot x, Port x&quot; \ <br />--rigid \ <br />--base=1000 \ <br />--height=120 \ <br />--width=500 \ <br />--alt-autoscale-max \ <br />--lower-limit=0 \ <br />--vertical-label=&quot;bits per second&quot; \ <br />DEF:a=&quot;/local/home/Network/cacti/cacti/rra/file.rrd&quot;:traffic_in:MAX \ <br />DEF:b=&quot;/local/home/Network/cacti/cacti/rra/file.rrd&quot;:traffic_out:MAX \ <br />CDEF:cdefa=a,8,* \ <br />CDEF:cdefe=b,8,* \ <br />AREA:cdefa#00CF00:&quot;Inbound&quot;&nbsp; \ <br />GPRINT:cdefa:LAST:&quot; Current\:%8.2lf %s&quot;&nbsp; \ <br />GPRINT:cdefa:AVERAGE:&quot;Average\:%8.2lf %s&quot;&nbsp; \ <br />GPRINT:cdefa:MAX:&quot;Maximum\:%8.2lf %s\n&quot;&nbsp; \ <br />LINE1:cdefe#002A97:&quot;Outbound&quot;&nbsp; \ <br />GPRINT:cdefe:LAST:&quot;Current\:%8.2lf %s&quot;&nbsp; \ <br />GPRINT:cdefe:AVERAGE:&quot;Average\:%8.2lf %s&quot;&nbsp; \ <br />GPRINT:cdefe:MAX:&quot;Maximum\:%8.2lf %s\n&quot;</td></tr></tbody></table><br /><br /><font size="2">Thanks in advance for the help <img src="http://forums.cacti.net/images/smiles/icon_smile.gif" border="0" /> </font></span>