Hello,
On Thu, Apr 6, 2000, 12:33:08 GMT Sergey I. Golod wrote:
>Эээ... Оно конечно по snmp можно общую статистику собрать, но меня больше
>интересует следующее:
>===================================================
>Вася Пупкин - 5мб принято/1мб передано
>Коля Плюшкин - 10 мб принято/1кб передано
>===================================================
>статистика по доменам, принято:
>mail.ru - 10mb
>chat.ru - 20 mb
>
>и т.д. и т.п.
Где-то полгода назад я писал Perl-скрипт для анализа логов, который подобную статистику собирает.
#!/usr/bin/perl -w # # A simple CommuniGatePro log analysing script. # The log files should be specified as parameters in commnad line. # Make sure you have 'Major & Failures' or lower logging level # in Message log, Enqueur, Dequeuer, Local, WebUser, SMTP, and RPOP modules. # # Please send your comments and suggestions to <support@stalker.com> #
if(@ARGV eq 0) {
print "Usage: LogAnalyse.pl log_file [log_file2 ...]\n";
exit;
}
my %MsgList; my %OrphanedList; my %PerAccountTraffic;
my ($id,$source,$src_oper,$dest,$dst_oper,$time,$size,$inQueue);
while(<>) {
my $line=$_;
if(/\[(\d+)\]/) {
$id=$1;
if(defined $MsgList{$id}) { my $data=$MsgList{$id}; ($source,$src_oper,$dest,$dst_oper,$time,$size,$inQueue)=@$data; } else { $source=$src_oper=$dest=$dst_oper=$time=$size='???';$inQueue=0;}
$source='unknown'; $src_oper=$1; /(\d\d:\d\d:\d\d\.\d\d) /; $time=substr($1,0,8); if(/(\d+) bytes/) { $size=$1; } if($src_oper eq 'fed') { /is fed as \[(\d+)\]/; $id=$1; } elsif($src_oper eq '->') { / -> \[(\d+)\]/; $id=$1; $src_oper='rule action'; } if(/ \d RPOP/) { $src_oper='RPOP'; } if(/\((.+?)\)/) { $source=PurgeName($1); }elsif(/(DEQUEUER report)/) { $source=$1; } $MsgList{$id}= [$source,$src_oper,$dest,$dst_oper,$time,$size,$inQueue]; }elsif(/ QUEUE\(\[/) { $inQueue=1; if(/(\d+) bytes/) { $size=$1; }elsif(/ deleted/) { delete $MsgList{$id}; #print "deleted: $id\n"; } }elsif(/ ACCOUNT/) { if(/ (delivered)/ || / (relayed)/) { $dst_oper=$1; /ACCOUNT\((.*)?\)/; $dest=PurgeName($1); unless($inQueue) { if($time ne '???' && $source ne '???') { print "$time Src=$source ($src_oper) To=$dest $dst_oper ($size bytes)\n"; AddToOutput($source) if(isDesired($source)); AddToInput($dest) if(isDesired($dest)); } else { /(\d\d:\d\d:\d\d\.\d\d) /; $time=$1; delete $MsgList{$id}; $OrphanedList{$id}= [$source,$src_oper,$dest,$dst_oper,$time,$size]; } delete $MsgList{$id}; } } }elsif(/ DEQUEUER \[/) { if(/ (delivered)/ || / (relayed)/) { $dst_oper=$1; /(\S*\(\S*\)?\S*)/; $dest=PurgeName($1); if($time ne '???' && $source ne '???') { print "$time Src=$source ($src_oper) To=$dest $dst_oper ($size bytes)\n"; AddToOutput($source) if(isDesired($source)); AddToInput($dest) if(isDesired($dest)); } else { /(\d\d:\d\d:\d\d\.\d\d) /; $time=$1; delete $MsgList{$id}; $OrphanedList{$id}= [$source,$src_oper,$dest,$dst_oper,$time,$size]; } }
if(%MsgList) { # print messages that were not removed from queue
print "\nGhost messages:\n";
foreach $id (keys %MsgList) {
my $data=$MsgList{$id};
($source,$src_oper,$dest,$dst_oper,$time,$size)=@$data;
print "$time id=$id Src=$source ($src_oper) To=$dest $dst_oper ($size bytes)\n";
}
}
if(%OrphanedList) { # messages with unknown origin
print "\nOrphan messages:\n";
foreach $id (keys %OrphanedList) {
my $data=$OrphanedList{$id};
($source,$src_oper,$dest,$dst_oper,$time,$size)=@$data;
print "$time id=$id Src=$source ($src_oper) To=$dest $dst_oper ($size bytes)\n";
}
}
if(%PerAccoountList) {
print "\nPer Account Traffic:\n";
foreach $id (sort keys %PerAccoountList) {
my $data=$PerAccoountList{$id};
my ($mailsIn,$bytesIn,$mailsOut,$bytesOut)=@$data;
format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>> @>>>>>> @>>>> @>>>>>>$id,$mailsIn,$bytesIn,$mailsOut,$bytesOut .
# This will be displayed on the top of the each output page. format STDOUT_TOP =
Mails Mails Address In Bytes Out Bytes ================================================ ===== ======= ===== =======.
write;
}
}
sub PurgeName { # remove prefixes from some names
my $name = $_[0];
return $1 if($name =~/LOCAL\((.*)\)/);
return $1 if($name =~/LIST\((.*)\)submit/);
return $2 if($name =~/SMTP\((.*)\)(.*)/);
return $name;
}
sub isDesired($addr) {
my $addr= $_[0];
return 1; #remove this line for the filtered output
if($addr =~/\@/) {
return 1 if($addr =~/\@mydomain\.com/); # insert your domain here
return 0;
}
return 0 if($addr =~/[\[\]\s]/); # IP address or 'Dequeuer Report'
return 1; #or 0 if you don't want mails for the main domain to be counted
}
sub AddToOutput($source) {
my $source= $_[0];
my ($mailsIn,$bytesIn,$mailsOut,$bytesOut);
if(defined $PerAccoountList{$source}) {
my $data=$PerAccoountList{$source};
($mailsIn,$bytesIn,$mailsOut,$bytesOut)=@$data;
} else {
$mailsIn=$bytesIn=$mailsOut=$bytesOut=0;
}
++$mailsOut; $bytesOut+=$size;
$PerAccoountList{$source}= [$mailsIn,$bytesIn,$mailsOut,$bytesOut];
}
sub AddToInput($dest) {
my $dest= $_[0];
my ($mailsIn,$bytesIn,$mailsOut,$bytesOut);
if(defined $PerAccoountList{$dest}) {
my $data=$PerAccoountList{$dest};
($mailsIn,$bytesIn,$mailsOut,$bytesOut)=@$data;
} else {
$mailsIn=$bytesIn=$mailsOut=$bytesOut=0;
}
++$mailsIn; $bytesIn+=$size;
$PerAccoountList{$dest}= [$mailsIn,$bytesIn,$mailsOut,$bytesOut];
}
Roman
##################################################################Вы получили это сообщение потому, что подписаны на список рассылки <CGatePro@mx.ru>.
Чтобы отписаться, отправьте сообщение на адрес <CGatePro-off@mx.ru> Чтобы переключиться в режим дайджеста - mailto:<CGatePro-digest@mx.ru> Чтобы переключиться в индексный режим - mailto:<CGatePro-index@mx.ru>Для административных запросов адрес <CGatePro-request@mx.ru> Получено Thu Apr 06 14:28:45 2000
Этот архив был сгенерирован hypermail 2.1.8 : Tue 21 Feb 2006 - 03:14:01 MSK