bandwidth.phps

<?
// bandwidth.php
// Returns current average bandwidth usage taken from a rrdtool-database
// hellfairy - http://packy.se/

function bandwidth()
{
  $data = exec('/usr/bin/rrdtool fetch /var/www/rrdtool/cbl0.rrd AVERAGE -s -2min | grep -v "nan" | tail -n1 | cut -d" " -f2-');
  $data = explode(' ', $data);
  $down = 0 + $data[0];
  $up = 0 + $data[1];
  $currdown = (round(($down / 1000000), 2)*100);
  $currup = (round(($up / 125000), 2)*100);
  return 'Downstream: '.$currdown.'%, Upstream: '.$currup.'%';
}

?>