#!/usr/bin/perl
# version 1.1, 27.06.97, philippe.simonet@swisstelecom.com
$outFile = 'distrib.html';
$mode = 'd';
$title = 'Mrtg Trafic Distribution';
$width = 300; $height = 160;
$count = 8;
$period = 'day';
$refreshInt=120; $refreshSeconds = $refreshInt * 60;
$theDate=localtime(time);
###########################################################
# read config files
$i = 0;
open(CFG, "mrtg.cfg") || die "Couldn't read mrtg.cfg";
while () {
$_ =~ tr/A-Z/a-z/;
if (/^maxbytes\[(.*)\]: (\d*).*/i) {
$maxbytes{$1} = $2;
#print $maxbytes{$1};
}
if (/^pagetop\[(.*)\]: (.*)/i) {
$pagetop{$1} = $2;
#print $pagetop{$1}, "\n";
}
}
close (CFG);
foreach $i ( keys %pagetop ) {
next if ($maxbytes{$i} eq undef);
next if ($pagetop{$i} eq undef);
for ($j = 0; $j < $count; $j++ ) {
$distr{$i}[$j][0] = 0;
$distr{$i}[$j][1] = 0;
$tot{$i} = 0;
}
open ( PIPE, "distrib -i $i.log -o $i.dist.$mode.gif -t $mode -w $width -h $height -r $maxbytes{$i} -d $count |" );
while ( ) {
if ( /(\d*):(\d*),(\d*).*/ ) {
$distr{$i}[$1][0] = $2;
$distr{$i}[$1][1] = $3;
}
}
for ($j = 0; $j < $count; $j++ ) {
$tot{$i} += ($j+1) * ($distr{$i}[$j][0] + $distr{$i}[$j][1]);
}
close ( PIPE );
}
###########################################################
# open files
open(OUT, ">$outFile") || die "Couldn't create $outFile";
open(SCORE, ">distrib.txt") || die "Couldn't create distrib.txt";
###########################################################
# print html head
$expTime=&expistr;
print OUT <
$title
$title ($theDate)
These graphs presents the trafic distribution information for last $period, based on data collected each 5 minutes by MRTG.
They are refreshed each $refreshInt minutes. (green = input traffic, blue = output).
Darker is the color, bigger is the trafic. Bigger is the rectangle, bigger is the time when the traffic was effective.
Top 10 interfaces for last $period
All trafic distribution for last $period
Vertical scale: % of time/
Horizontal scale: % of Maxbyte
| maxbytes |
pagetop |
target |
URL |
EOF
foreach $i ( sort by_number (keys %pagetop) ) {
next if ($maxbytes{$i} eq undef);
next if ($pagetop{$i} eq undef);
print SCORE "$i:";
for ($j=0; $j < ($count-1); $j++) {
print SCORE $distr{$i}[$j][0], "/", $distr{$i}[$j][1], ",";
}
print SCORE $distr{$i}[$count-1][0], "/", $distr{$i}[$count-1][1], "\n";
print OUT <
$maxbytes{$i} |
$pagetop{$i} $pc $post |
$i, score $tot{$i} |
 |
EOF
}
print OUT <