From 6745e860ee13b9456b17cdad4999b6808146ad78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ermal=20Lu=E7i?= Date: Fri, 25 Dec 2009 21:52:46 +0000 Subject: Simplify a lot the code of rate extracting. --- usr/local/www/bandwidth_by_ip.php | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'usr') diff --git a/usr/local/www/bandwidth_by_ip.php b/usr/local/www/bandwidth_by_ip.php index 8fc29e4..b85db4f 100755 --- a/usr/local/www/bandwidth_by_ip.php +++ b/usr/local/www/bandwidth_by_ip.php @@ -30,7 +30,7 @@ $intip = explode (".", $intip); //use class A subnet to make sure we capture all traffic on specified interface $intsubnet = $intip[0] . ".0.0.0/8"; -exec("rate -i {$real_interface} -nlq 1 -A -c {$intsubnet}", $listedIPs); +exec("rate -i {$real_interface} -nlq 1 -Aa 10 -c {$intsubnet} | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $5, $8, $11 }'", $listedIPs); unset($bandwidthinfo); unset($receivebytesarray); @@ -44,30 +44,9 @@ for ($x=2; $x<12; $x++){ // echo $bandwidthinfo; $emptyinfocounter = 1; if ($bandwidthinfo != "") { - $splitinfo = explode ("|",$bandwidthinfo); - $receivebytesarray = explode(" ",$splitinfo[0]); + $infoarray = explode (":",$bandwidthinfo); //print IP of host; - echo $receivebytesarray[0] . ";"; - - //skip empty array elements until first element found with data - while ($receivebytesarray[$emptyinfocounter] == "") - { - $emptyinfocounter++; - } - //print received bytes for host - echo $receivebytesarray[$emptyinfocounter] . ";"; - - $transmitbytesarray = explode(" ",$splitinfo[1]); - - $emptyinfocounter = 1; - - //skip empty array elements until first element found with data - while ($transmitbytesarray[$emptyinfocounter] == "") - { - $emptyinfocounter++; - } - //print transmitted bytes for host - echo $transmitbytesarray[$emptyinfocounter] . "|"; + echo $infoarray[0] . ";" . $infoarray[1] . ";" . $infoarray[2] . "|"; //mark that we collected information $someinfo = true; -- cgit v1.1