[tpop3d-discuss] Traffic-Accounting

Jens Liebchen (ppp-design) jens at ppp-design.de
Tue, 20 Aug 2002 08:35:08 +0200


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi everybody,

I have written a small perl script for doing traffic accounting via
cronjob. If you like it, just use it (Chris, if you want to, you are
free to add it to the tpop3d-package). I am not a perl guru, but it is
working good (and fast enough) here.

Jens Liebchen
ppp-design

- --------------snip----------------------


#!/usr/bin/perl
#
# Calculating pop3-traffic per domain
# Jens Liebchen ppp-design jens@ppp-design.de
#
# Usage cat logfile | pop3-traffic.pl
#
# based on:
# Study Postfix relay behavior
# Miguel A.L. Paraz <map@iphil.net> 20000406

use strict;

my (%client_size);


while (my $line = <STDIN>) {
    if (my ($client, $in, $out) = ($line =~ m!tpop3d.*:
connections_post_select: client \[[\d]+\].*[\d]+\@(.*)\(.*\): dis
connected; ([\d]+)/([\d]+) bytes read/written\n!)) {
        $client_size{$client} += $in + $out;
        }
}

my @entry;
foreach my $client (keys (%client_size)) {
    push (@entry, [$client, $client_size{$client}]);
}

foreach my $ce (sort { -($a->[1] <=> $b->[1]) } @entry) {
    printf "%10d %s\n", $ce->[1], $ce->[0];
}



- --
ppp-design
http://www.ppp-design.de
Public-Key: http://www.ppp-design.de/pgp/ppp-design.asc
Fingerprint: 5B02 0AD7 A176 3A4F CE22  745D 0D78 7B60 B3B5 451A
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Weitere Infos: siehe http://www.gnupg.org

iD8DBQE9YeMbDXh7YLO1RRoRAqE9AKCy4UiSHbJdNjOjQuq6e81LRe0ybQCg4sQ2
qi27fwNS9NX9bBrDaxYIpCQ=
=oFxd
-----END PGP SIGNATURE-----