Article View: comp.mail.misc
Article #1425Re: Need mqueue/syslog* Summary Scripts
From: Paul A Vixie
Date: Thu, 19 Jul 1990 15:59
Date: Thu, 19 Jul 1990 15:59
135 lines
3533 bytes
3533 bytes
Here's what we use to summarize our syslogs at decwrl.
#! /usr/local/bin/perl
$logdir = "/usr/spool/mqueue";
$secperday = 24 * 60 * 60;
$shortdelay = $secperday / 2;
$K = 1024;
format q_top =
Syslog Input: (total) (mail11) Output Statistics:
File Date Msgs Kbytes AvgSz Sndrs Rcips Sent AvgDelay Dferd Que'd Other
.
format q_line =
@< @<<<<< @>>>> @>>>>> @>>>> @>>>> @>>>> @>>>> @>>>>>>> @>>>> @>>>> @>>>>
$logfn,$date,$msgs,$kbytes,$avgsiz,$m11sndr,$m11rcip,$sent,$avgdly,$dferd,$queued,$other
.
$^ = "q_top";
$~ = "q_line";
chdir($logdir) || die "can't chdir to $logdir: $!";
foreach $logfn (<syslog.*>) {
open(stdin, "<$logfn") || die "can't open $logfn: $!";
&mailstats();
close(stdin);
$logfn =~ s/^.*\./\./;
write();
}
exit(0);
sub mailstats {
($msgs,$bytes,$delay,$m11sndr,$m11rcip) = (0,0,0,0,0);
$date = "";
%stati = ();
while (<>) {
($mon,$dd,$time,$host,$pid,$client,@rest) = split;
$date = sprintf("%s %2d", $mon, $dd) if ($date eq "");
if ($client eq "sendmail:") {
$qid = $rest[0];
if ($rest[1] =~ /^from=/ && $rest[2] =~ /^size=(\d+)/) {
$msgs++;
$bytes += $1;
} elsif ($rest[1] =~ /^to=/) {
if ($rest[3] =~ /Deferred/) {
if ($deferred{$qid}) {
next;
} else {
$deferred{$qid}++;
}
}
$rest[2] =~ /^delay=([^,]+)/;
$md = $1;
$d = 0;
if ($md =~ /(\d+)\+(.+)/) {
$d += $md * $secperday;
$md =~ s/\d+\+//;
}
$md =~ /^delay=(\d+):(\d+):(\d+)/;
$d += ($1 * 3600 + $2 * 60 + $3);
$delay += $d if ($d < $shortdelay);
$rest[3] =~ /^stat=(.+)/;
$stat = $1." ".join(" ", @rest[4..$#rest]);
$stati{$stat}++;
}
}
if ($client eq "mail11d:") {
if ($rest[0] =~ /^from=/) {
$m11sndr++;
} elsif ($rest[0] =~ /^to=/) {
$m11rcip++;
}
}
}
#printf "total input: %d msgs, %dKB (%d bytes avg)\n",
# $msgs, $bytes/$K, $bytes/$msgs;
#printf "mail11 input: %d senders (msgs), %d recips\n",
# $mail11_senders, $mail11_recips;
if ($msgs == 0) {
$avgdly = &fmt_time(0);
} else {
$avgdly = &fmt_time($delay / $msgs);
}
$kbytes = int(0.5+$bytes/$K);
if ($msgs == 0) {
$avgsiz = 0;
} else {
$avgsiz = int(0.5+$bytes/$msgs);
}
$sent = $stati{"Sent "};
($dferd, $other, $queued) = (0, 0, 0);
foreach $stat (keys(%stati)) {
next if ($stat eq "Sent ");
if ($stat eq "queued ") {
$queued += $stati{$stat};
next;
}
if ($stat =~ /^Deferred/) {
$dferd += $stati{$stat};
next;
}
$other += $stati{$stat};
}
return;
}
sub fmt_time {
local($t) = @_;
local($s) = int($t);
local($h) = int($s / 3600); $s -= $h*3600;
local($m) = int($s / 60); $s -= $m*60;
local($x) = "";
if ($s || $m || $h) {
$x = sprintf("%02d", $s) .$x;
}
if ($m || $h) {
$x = sprintf("%02d:", $m) .$x;
}
if ($h) {
$x = sprintf("%2d:", $h) .$x;
}
return $x;
}
--
Paul Vixie
DEC Western Research Lab <vixie@wrl.dec.com>
Palo Alto, California ...!decwrl!vixie
Technical Details
Message-ID:
<VIXIE.90Jul19115945@volition.pa.dec.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!decwrl!bacchus.pa.dec.com!vixieReferences:
<1990Jul13.211326.8393@uncecs.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!decwrl!bacchus.pa.dec.com!vixie From: vixie@decwrl.dec.com (Paul A Vixie) Newsgroups: comp.mail.misc,comp.mail.sendmail Subject: Re: Need mqueue/syslog* Summary Scripts Message-ID: <VIXIE.90Jul19115945@volition.pa.dec.com> Date: 19 Jul 90 15:59:45 GMT References: <1990Jul13.211326.8393@uncecs.edu> Sender: news@wrl.dec.com (News) Organization: DEC Western Research Lab Lines: 135 In-Reply-To: khj@uncecs.edu's message of 13 Jul 90 21:13:26 GMT