[mrtg] Cfg for Total Bandwidth -script

Niko Itajarvi niko.itajarvi at satabaana.net
Wed Nov 12 17:39:06 MET 2003


I found a Perl-script that will show how much in and out bandwidth you have
used.
The thing is, I dont know how to make a config-file for this. Can someone help 
me out?

Here's the script:

#!/usr/bin/perl

@a=split(/[:\s]+/,qx(grep eth0 /proc/net/dev));
$f="%.0f";
$fmt="$f\n$f\n1\neth0 total traffic\n";

open(TXT, "tmpfile");
@jeps=<TXT>;
close(TXT);
chomp(@jeps);
$nowin=$a[2]-$yup[2];
$nowout=$a[10]-$yup[3];
# When Linux's counter goes to zero, this will fix it
if($nowin<0){
        $nowin=10000;
}
if($nowout<0){
        $nowout=10000;
}
$totin=$yup[0]+$nowin;
$totout=$yup[1]+$nowout;
open(TXT,">tmpfile");
print TXT "$totin\n$totout\n$a[2]\n$a[10]\n";
close(TXT);
$totin/=(1024*1024);
$totout/=(1024*1024);
$s=sprintf $fmt,$totin,$totout;
print $s;
print STDERR $s;


The output is:

1105
926
1
eth0 total traffic
1105
926
1
eth0 total traffic

Ran again:

1106
933
1
eth0 total traffic
1106
933
1
eth0 total traffic


I've tried some cfg-files of my own but nothing has worked so far.

Thanks!


Niko Itajarvi

--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list