Project

General

Profile

« Previous | Next » 

Revision 6745e860

Added by Ermal Luçi over 15 years ago

Simplify a lot the code of rate extracting.

View differences:

usr/local/www/bandwidth_by_ip.php
30 30
//use class A subnet to make sure we capture all traffic on specified interface
31 31
$intsubnet = $intip[0] . ".0.0.0/8";
32 32

  
33
exec("rate -i {$real_interface} -nlq 1 -A -c {$intsubnet}", $listedIPs);
33
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);
34 34

  
35 35
unset($bandwidthinfo);
36 36
unset($receivebytesarray);
......
44 44
   // echo $bandwidthinfo;
45 45
    $emptyinfocounter = 1;
46 46
    if ($bandwidthinfo != "") {
47
        $splitinfo = explode ("|",$bandwidthinfo);
48
        $receivebytesarray = explode(" ",$splitinfo[0]);
47
        $infoarray = explode (":",$bandwidthinfo);
49 48
        //print IP of host;
50
        echo $receivebytesarray[0] . ";";
51

  
52
        //skip empty array elements until first element found with data
53
        while ($receivebytesarray[$emptyinfocounter] == "")
54
        {
55
            $emptyinfocounter++;
56
        }
57
        //print received bytes for host
58
        echo $receivebytesarray[$emptyinfocounter] . ";";
59

  
60
        $transmitbytesarray = explode(" ",$splitinfo[1]);
61

  
62
        $emptyinfocounter = 1;
63

  
64
        //skip empty array elements until first element found with data
65
        while ($transmitbytesarray[$emptyinfocounter] == "")
66
        {
67
            $emptyinfocounter++;
68
        }
69
        //print transmitted bytes for host
70
        echo $transmitbytesarray[$emptyinfocounter] . "|";
49
        echo $infoarray[0] . ";" . $infoarray[1] . ";" . $infoarray[2] . "|";
71 50

  
72 51
        //mark that we collected information
73 52
        $someinfo = true;

Also available in: Unified diff