[tpop3d-discuss] bandwidth statistics

Chris Lightfoot chris at ex-parrot.com
Mon, 19 Aug 2002 12:59:59 +0100


Scratching an itch, I wrote a trivial program to do
bandwidth stats from tpop3d logs:

#!/usr/bin/perl -w
$num = $ARGV[0];
$num ||= 10;

%sess = ( );
%recv = ( );
%send = ( );

while (<STDIN>) {
    if (m#tpop3d.+client \[.+\]([^(]+).+ (\d+)/(\d+) bytes read/written#) {
        ++$sess{$1};
        $recv{$1} += $2;
        $send{$1} += $3;
    }
}

my @top = sort { $send{$b} <=> $send{$a} } keys %send;
print <<EOF;
User                                             Times  Received  Sent
------------------------------------------------ ------ --------- ---------
EOF
foreach (@top[0..$num - 1]) {
    printf("%48s (% 4d) % 9d % 9d\n", $_, $sess{$_}, $recv{$_}, $send{$_});
}

-- it prints the top $num users, sorted by amount of
traffic sent. I'll put this in the distribution. You need
to be running 1.4.2 or the current CVS version to use
this.

-- 
``I shouldn't say `I don't think so,' although that's what I think.''
  (Donald Rumsfeld)