[CentOS] command line bandwidth

Fri Jan 6 02:45:26 UTC 2006
Benjamin Smith <lists at benjamindsmith.com>

Here's a PHP script that I use to give me long-term, month-to-month stats on 
total bandwidth usage, run from cron every 5 minutes: 

#! /usr/bin/php -q
<?

if (!$in=`/sbin/ifconfig -a eth0`)
        die ('Error: no input from ifconfig -a call');
$now=mktime();
# RX bytes:1294815560 (1234.8 Mb)  TX bytes:3493560535
$match="/RX bytes:([0-9]+).*?TX bytes:([0-9]+)/";
if (!preg_match($match, $in, $r))
        die ('Error - no matching for input from eth1');
if (!$fp=fopen("/var/log/traffic.log", 'a'))
        die ('Error - unable to open /var/log/traffic.log');
fwrite($fp, "$now RX: ".$r[1]." TX: ".$r[2]."\n");
fclose($fp);

?>

If you want some cheezy scripts to parse the resulting data file, I can help 
you there too. =) 

-Ben 

On Thursday 05 January 2006 07:03, Andrew Rice wrote:
> Hey I was just curious if anyone knew of any scripts or command line 
programs that are out there
> that could be used to check bandwidth on a network.
> 
> 
> -- 
> Andrew Rice Jr
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos
> 

-- 
"The best way to predict the future is to invent it."
- XEROX PARC slogan, circa 1978