🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: dnet.inet
Article #313

sendmail-Statistik

#313
From: Michael Schmidt
Date: Mon, 01 Jul 1991 11:30
143 lines
3786 bytes
>>>>> About sendmail-Statistik, Thomas Anlauf said:

Thomas> hat jemand ein Programm (oder weiss, wo ich ein solches
Thomas> bekommen kann), das mir Statistiken ueber ein- und ausgehende
Thomas> Mail (Anzahl, Zustellungszeiten, etc.) aus dem syslog-File
Thomas> einer Sun erstellt?

Kommt spaet, aber es kommt. (:-)

	Michael Schmidt

--
#! /usr/local/perl/bin/perl

# Print a weekly summary of email activity.  Written by Paul Vixie, DEC

$logdir = "/var/log";
$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,$client,$qid,@rest) = split;
	@rest=split(/, /,join(' ',@rest));
	$date = sprintf("%s %2d", $mon, $dd) if ($date eq "");
	if ($client =~ /sendmail\[[0-9]+\]:/) {
		if ($rest[0] =~ /^from=/ && $rest[1] =~ /^size=(\d+)/) {
			$msgs++;
			$bytes += $1;
		} elsif ($rest[0] =~ /^to=/) {
			if ($rest[2] =~ /Deferred/) {
				if ($deferred{$qid}) {
					next;
				} else {
					$deferred{$qid}++;
				}
			}
			$rest[1] =~ /^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[2] =~ /^stat=(.+)(.*)/;
			$stat = $1." ".$2;
			$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;
}
Technical Details
Message-ID: <9107011130.AA20836@athene.uni-paderborn.de>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!UNI-PADERBORN.DE!michael
References: michael@UNI-PADERBORN.DE (Michael Schmidt)

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 13322c,6c08e599012ebfcd,start
X-Google-Attributes: gid13322c,public
X-Google-ArrivalTime: 1991-07-01 05:32:35 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!UNI-PADERBORN.DE!michael
From: michael@UNI-PADERBORN.DE (Michael Schmidt)
Newsgroups: dnet.inet
Subject: sendmail-Statistik
Message-ID: <9107011130.AA20836@athene.uni-paderborn.de>
Date: 1 Jul 91 11:30:40 GMT
References: michael@UNI-PADERBORN.DE (Michael Schmidt)
Organization: The Internet
Lines: 143