Results 1 to 12 of 12
  1. #1
    Join Date
    Apr 2002
    Posts
    221

    Bandwidth Monitoring

    I have a quick question:

    What script(s) could I use to keep a running total of bandwidth usage (month by month or just cumulative)? I can get stats since the server was last rebooted, and I have MRTG installed, but how do I tally numbers and calculate an actual bandwidth usage?

    Thanks

    James

  2. #2
    Join Date
    Sep 2002
    Location
    Oklahoma
    Posts
    825
    Write something using the rrndtool.
    Devon Dunham (Owner, Sharpnet/DDoS Host)
    Advanced DDoS Mitigation and Server Management Solutions

    Protecting your online infrastructure.

    Est. 1998.

  3. #3
    Join Date
    Jul 2002
    Posts
    183
    Are you using plesk?

  4. #4
    Join Date
    Apr 2002
    Posts
    221
    CPanel/WHM

    I could write a script... but something pre-made might be nice.

    James

  5. #5
    Join Date
    May 2001
    Posts
    1,593
    You can try bandmin, which does IP transfer monitoring by IP addresses.

    www.bandmin.org.

    As a matter of fact, bandmin comes with WHM/Cpanel, but (from what I can tell) isn't integrated anywhere.

    Peter

  6. #6
    Join Date
    May 2001
    Location
    Dayton, Ohio
    Posts
    4,962
    This script I believe was posted here some time ago, but the author never taged his/her work...

    PHP Code:
    <html>
        <head>
            <style type="text/css">
                H1            { font-size: 14; color: #000000; font-family: verdana, arial; }
                BODY,TD        { font-size: 12; color: #000000; font-family: verdana, arial;}
            </style>

            <title>Data Transfer</title>
        </head>

        <body bgcolor="#FFFFFF">

        <h1 align="center">Data Transfer</h1>
    <?

        
    // PATHS
        
    $log_file "/path/to/mrtg.log";
        
    $tmp_file "/path/to//mrtg2.log";

        
    // First copy the file so that we can work with it
        
    copy($log_file$tmp_file);

        
    // Figure out the day and year
        
    $month date("m"time());
        
    $year date("Y"time());

        
    // Open the file
        
    $fp fopen($tmp_file"r");
        
    $file fread($fpfilesize($tmp_file));
        
    fclose($fp);

        
    // Explode the file
        
    $data = array();
        
    $data explode("\n"$file);
        
    $data_size sizeof($data);

        
    // Variables needed to keep track of last values
        
    $last_dt = -1;
        
    $last_avgin = -1;
        
    $last_avgout = -1;
        
    $total_in 0;
        
    $total_out 0;
        
    $bytesin 0;
        
    $bytesout 0;

        
    $results = array(); // use this to store the table of information

        // Go through each line
        
    for ($x=1$x<($data_size-1); $x++) { // skip first and last line
            // break into the 5 pieces
            
    $temp trim($data[$x]);
            
    $pos strpos($temp" ");
            
    $dt substr($temp0$pos);
            
    $pos2 strpos($temp" "$pos+1);
            
    $avgin substr($temp$pos+1$pos2-$pos);
            
    $pos strpos($temp" "$pos2+1);
            
    $avgout substr($temp$pos2+1$pos-$pos2);

            if ( 
    $last_dt == -) {
                
    // this is the first iteration so dont do anything
            
    } else {
                
    // calculates bytes of transfer
                
    $bytesin $last_avgin * ($last_dt $dt); // bytes/sec * seconds
                
    $bytesout $last_avgout * ($last_dt $dt); // bytes/sec * seconds

                // add the values to the array
                
    $resultsdate("Y"$dt) ][ date("m"$dt) ][0] += $bytesin;
                
    $resultsdate("Y"$dt) ][ date("m"$dt) ][1] += $bytesout;
            }

            
    $last_dt $dt;
            
    $last_avgin $avgin;
            
    $last_avgout $avgout;

        }
        
        
    // delete the temp file
        //unlink($tmp_file);

        
    echo "<center><table border=\"0\">";
        echo 
    "  <tr bgcolor=\"#003399\">";
        echo 
    "    <td><b><font color=\"#FFFFFF\">Date</font></b></td>";
        echo 
    "    <td><b><font color=\"#FFFFFF\">Bytes In</font></b></td>";
        echo 
    "    <td><b><font color=\"#FFFFFF\">Bytes Out</font></b></td>";
        echo 
    "    <td><b><font color=\"#FFFFFF\">Total Bytes</font></b></td></tr>";

        
    // enable alternating colours
        
    $colour "#CCCCCC";
        foreach (
    $results as $year => $years) {
            foreach (
    $years as $month => $months) {
                echo 
    "<tr bgcolor=\"$colour\">";
                echo 
    "<td align=\"left\">" date("M Y",mktime(0,0,0,$month,1,$year)) ."</td>";
                echo 
    "<td align=\"right\">" number_format($months[0]/1024/1024,1) . " MB</td>";
                echo 
    "<td align=\"right\">" number_format($months[1]/1024/1024,1) . " MB</td>";
                echo 
    "<td align=\"right\">" number_format(($months[0] + $months[1])/1024/1024,1) . " MB</td>";
                echo 
    "</tr>";

                if (
    $colour == "#CCCCCC") {
                    
    $colour "#EEEEEE";
                } else {
                    
    $colour "#CCCCCC";
                }
            }
        }
        echo 
    "</table></center>";

        unset(
    $results);
        unset(
    $data);
    ?>

        </body>
    </html>
    -Mat Sumpter
    Director, Product Engagement
    Penton Media

  7. #7
    Join Date
    Aug 2002
    Location
    California
    Posts
    247
    RRDTool is good, and if you're running *nix, I reccommend Cacti--a complete PHP/MySQL frontend to rrdtool.
    argonblue.com | sales | 800.710.8004
    LA Grand Avenue, Rancho Cordova, cages, racks and power plus HE Fremont cabinets available!

  8. #8
    Join Date
    Nov 2001
    Location
    Canada
    Posts
    1,963
    bandmin rules. i use it on all my servers. very accurate, and keeps track of bw since the day you turn it on.

  9. #9
    Join Date
    May 2001
    Posts
    53
    Originally posted by clocker1996
    bandmin rules. i use it on all my servers. very accurate, and keeps track of bw since the day you turn it on.
    Have you integrated it in WHM/Cpanel?

  10. #10
    Join Date
    May 2001
    Posts
    1,593
    I don't think you can integrate bandmin into cpanel, but it shouldn't matter, since it gives nice HTML output of the bandwidth usage.

    Peter

  11. #11
    Join Date
    May 2001
    Posts
    697
    Actually, bandmin is already on your server if you run WHM/CPanel.

    Here's a shocker for ya! Go to www.anyofyourdomains.com/bandwidth/

    Heh... that's always a huge shocker to people who don't know it's there...

    After you're done being shocked that it's publically accessible, you will probably want to password protect it or just disallow it completely with .htaccess

    <edit> ok, now I see that you wanted integration with WHM/CPanel, and not just to have it installed. Sorry for the brainfart! </edit>
    Last edited by mpope; 10-02-2002 at 10:13 PM.

  12. #12
    I believe http://www.cheshire.demon.co.uk/pub/ has a script that will convert it for you.
    Multiple Image Corporation - http://www.multipleimage.com
    Diverse Solutions for Diverse Companies.
    Virtual, Dedicated & Colocated Hosting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •