[mrtg-developers] php code for 95th percentile

Paul Chvostek paul+mrtg at it.ca
Tue Feb 19 10:18:46 MET 2002


I've set "Extension[_]: php" and written a block of PHP code which I
can add to any PageTop for which I want to include a 95th percentile
of log entries.  (Yes, I know I should be doing this with rrd; just
consider this an exercise. ;> )

What I've written works nicely as far as it goes, but I can't seem to
figure out how to build a template that will include a referral to the
raw log file.  The PageTop includes:

  <? if ($f=fopen('/u/mrtg/151sw3_fa0_10.log','r')) {
	while (!feof($f)) {
		$line=explode(" ",fgets($f,80));
		if ($line[0]>(time()-86400*7)&&$line[4]>0) {
	natsort($p); reset($p);
	while (list($key,$val)=each($p)) $n[]=$val;
	$i=intval($c * 0.95);
	print " <tr><td>7-day 95th %:</td>";
	printf("<td>%.2f kbps (%s samples)</td></tr>",8*$p[$i]/1024,$c);
  } ?>

Any thoughts?

  Paul Chvostek                                             <paul at it.ca>
  Operations / Development / Abuse / Whatever       vox: +1 416 598-0000
  it.canada                                            http://www.it.ca/

Unsubscribe mailto:mrtg-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:mrtg-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/mrtg-developers

More information about the mrtg-developers mailing list