Cacti 95th value seems to be wrong? Checked by hand
James Bensley <[email protected]> Thu, 19 Dec 2013 11:34:31 +0000
| Newsgroups | gmane.network.cacti.user |
|---|---|
| Message-ID | <CAAWx_pWo=UGoze7UGQPukn7A_yu4h_mQsdGYFYpSuADBZgzcAQ@mail.gmail.com> |
Hi All,
Cacti is generating the following graph with a 95th percentile value
of 6.04Mbps;
http://i.imgur.com/4K4waiz.png
I am generating data from the same data source by hand (using RRDTools
on the command line, and a PHP script to calculate the 95th percentile
value for me). I have produced the following graph;
http://i.imgur.com/O9Xo1Do.png
It's all the same except the 95th percentile is a little higher at
6.33Mbps. The more traffic the interface is parsing though the larger
that few percent discrepency is. I have checked various Cacti
generated graphs against what I have generated on the CLI and the
descrepancy is always there.
Below is the code that calculates the 95th percentile for me. I have
been over and over it and can't see any reason why it would be
incorrect or over estimating the 95th percentile value. I have checked
by hand, by dumping the values from an rrd file in plain text, sorting
them and picking out the higher values etc; my script is correct.
The Cacti graph template has the ususal |95:bits:6:max:2| value for
the 95th percentile calculation. Has anyone validated this code or
queried it before? Has anyone else found it to not match what they are
getting when calculting the 95th them selves?
Many thanks,
James.
PHP Code for 95th value calculation;
// Blank out a file and dump this months values from rrd file
exec("echo \"\" > $rrdtmpfile");
exec("rrdtool fetch -s $start -e $end $rrd AVERAGE > $rrdtmpfile");
// remove the titles from the rrd output
exec("sed -i 1,+1d $rrdtmpfile");
// Blank out a new file for sorting into max values
exec("echo \"\" > $rrdtmpfile"."_max");
// Open file for writing and sort it
$handle_in = fopen("$rrdtmpfile", "r");
$handle_out = fopen("$rrdtmpfile"."_max", "w");
$lastin = 0.0;
$innow = 0;
$lastout = 0.0;
$outnow = 0;
$average = 0;
$samples = 0;
// Here we run through each line and get the large value of
traffic_in or traffic_out and write this to the new file
while(!feof($handle_in)) {
$line = fgets($handle_in);
$values = explode(" ", $line);
if($values[1]=="nan") {
$innow = $lastin;
} else {
$innow = sprintf("%f", $values[1]);
$lastin = $innow;
}
if($values[2]=="nan") {
$outnow = $lastout;
} else {
$outnow = sprintf("%f", $values[2]);
$lastout = $outnow;
}
if($innow >= $outnow) {
fwrite($handle_out, $innow."\n");
$average=$average+$innow;
} else {
fwrite($handle_out, $outnow."\n");
$average=$average+$outnow;
}
$samples=$samples+1;
}
fclose($handle_in);
fclose($handle_out);
//Calculate an average
$average=$average/$samples;
// Now we have filled ./rrd_values_max with the MAX value from
each time period,
// sort them in desending order
exec("sort -g -r $rrdtmpfile"."_max > $rrdtmpfile"."_max_sorted");
// Remove any blank lines (typically there is one on the end)
exec("sed '/^$/d' $rrdtmpfile"."_max_sorted >
$rrdtmpfile"."_max_sorted_trim");
// Get the highest/max value from the first line of the file
$max = shell_exec("head -n 1 $rrdtmpfile"."_max_sorted_trim");
// Ge the lowest/minimum value from the last line of the file
$min = shell_exec("tail -n 1 $rrdtmpfile"."_max_sorted_trim");
// Count the number of lines of rrd values
$linecount = shell_exec("grep -c ^ $rrdtmpfile"."_max_sorted_trim");
// Get 5 percent of the line count value, round it down with floor()
$fivepc = floor(($linecount/100)*5);
// Now read the value from the line, 5% down from the top of the
line count of the file
$ninetyfifth = shell_exec("awk -v n1=$fivepc 'NR==n1'
$rrdtmpfile"."_max_sorted_trim");
$ninetyfifth = trim($ninetyfifth);
// Round it up
//$ninetyfifth = ceil($ninetyfifth);
// Convert to bps,kbps,mbps
$ninetyfifthbps = ceil(($ninetyfifth*8));
$ninetyfifthkbps = round(($ninetyfifthbps/1000), 2);
$ninetyfifthmbps = round(($ninetyfifthkbps/1000), 2);
$rrdcmd = "/usr/bin/rrdtool graph $tmpfolder/$graphname ".
"--imgformat=PNG ".
"--start=$start ".
"--end=$end ".
"--title='$graphtitle' ".
"--rigid ".
"--base=1000 ".
"--height=120 ".
"--width=500 ".
"--alt-autoscale-max ".
"--lower-limit=0 ".
"COMMENT:\"From ".date("Y-m-d H", $start)."\:".date(i,
$start)."\:".date(s, $start).
" to ".date("Y-m-d H", $end)."\:".date(i,
$end)."\:".date(s, $end)."\c\" ".
"COMMENT:\" \c\" ".
"--vertical-label='bits per second' ".
"--slope-mode ".
"--font TITLE:10: ".
"--font AXIS:8: ".
"--font LEGEND:7: ".
"--font UNIT:8: ".
"DEF:in=\"$rrd\":traffic_in:MAX ".
"DEF:out=\"$rrd\":traffic_out:MAX ".
"VDEF:inbytesavg=in,AVERAGE ".
"VDEF:outbytesavg=out,AVERAGE ".
"CDEF:inbytesmod=in,UN,inbytesavg,in,IF ".
"CDEF:outbytesmod=out,UN,outbytesavg,out,IF ".
"CDEF:speedin=in,8,* ".
"CDEF:speedout=out,8,* ".
"VDEF:intotal=inbytesmod,TOTAL ".
"VDEF:outtotal=outbytesmod,TOTAL ".
"AREA:speedin#00CF00FF:\"Inbound\" ".
"GPRINT:speedin:LAST:\"Current\:%8.2lf %s\" ".
"GPRINT:speedin:AVERAGE:\"Average\:%8.2lf %s\" ".
"GPRINT:speedin:MAX:\"Maximum\:%8.2lf %s\" ".
"GPRINT:intotal:\"Total In\:%8.2lf %s\" ".
"COMMENT:\" \c\" ".
"LINE1:speedout#002A97FF:\"Outbound\" ".
"GPRINT:speedout:LAST:\"Current\:%8.2lf %s\" ".
"GPRINT:speedout:AVERAGE:\"Average\:%8.2lf %s\" ".
"GPRINT:speedout:MAX:\"Maximum\:%8.2lf %s\" ".
"GPRINT:outtotal:\"Total Out\:%8.2lf %s \c\" ".
"COMMENT:\" \c\" ".
"HRULE:$ninetyfifthbps#FF0000FF:\"95th Percentile\" ".
"COMMENT:\"($ninetyfifthmbps mbit in+out)\c\" ".
"PRINT:intotal:\"%8.2lf%SBs In\" ".
"PRINT:outtotal:\"%8.2lf%SBs Out\" ".
"PRINT:speedin:AVERAGE:\"%8.2lf%sbps In\" ".
"PRINT:speedout:AVERAGE:\"%8.2lf%sbps Out\" ".
"PRINT:speedin:MAX:\"%8.2lf%sbps In\" ".
"PRINT:speedout:MAX:\"%8.2lf%sbps Out\" ";
exec ($rrdcmd, $cmdout);
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk