php code for 95th percentile

Paul Chvostek <[email protected]> Tue, 19 Feb 2002 04:18:46 -0500
Newsgroups gmane.network.mrtg.devel
Message-ID <[email protected]>

Hiya.

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) {
			$p[]=$line[3];
			$p[]=$line[4];
			$c+=2;
		}
	}
	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);
	fclose($f);
  } ?>

Any thoughts?

-- 
  Paul Chvostek                                             <[email protected]>
  Operations / Development / Abuse / Whatever       vox: +1 416 598-0000
  it.canada                                            http://www.it.ca/


--
Unsubscribe mailto:[email protected]?subject=unsubscribe
Help        mailto:[email protected]?subject=help
Archive     http://www.ee.ethz.ch/~slist/mrtg-developers