Tracking Sendmail Load Issues

Posted on February 17th, 2006 in system administration by Russ

Perl Cookbook, Second Edition

I was making a case yesterday that sendmail/mimedefang/clamd/spamassassin weren’t causing a heavy load on our systems. I had to back up my claims with some cold facts, so here’s what I put together.
First, I ran “sar” to get the system activity report; it’s some statistics that are taken every 10 minutes throughout a day on our Fedora Core 4 server. Then I grepped for today’s mail information in the maillog file (grep ^Feb\ 16 maillog) and saved it to another file. Then I ran this script to match total processed mail messages against the system activity report; I ran the script and saved the output in a file, then used “paste sarreport mailreport > foo” to get the whole report.

Sometimes my tools are just too much fun.


open( FH, "maillog.stripped");

# set default values
my $remote=$relay=$file=$local=$total=0;
my $avgtotal=$avgremote=$avglocal=$avgrelay=$avgfile=0;
my $totals=$remotes=$locals=$relays=$files=0;
my $stattime="00:00";
my $checktime="00:00";

# print these spaces to match the loadinfo sheet
print "\n";
print "\tMessages/min (10min avg)\n";
while(>fh< >){
# only need the mailer= lines
if (m/mailer=/) {
$line=$_;
# we know where the date stamp lives
# whichever mail item this is, increment that mailer count
# this was originally a minute-by-minute script, then broke it u
p for 10 min avg.
$checktime=substr( $line, 7, 5);
if ( $checktime eq $stattime ) {
if ( m/mailer=local/ ) { $local++; }
elsif ( m/mailer=esmtp/ ) { $remote++; }
elsif ( m/mailer=relay/ ) { $relay++; }
else { $file++; };
}
else {
# calculate totals etc
$total=$remote+$local+$relay+$file;
my( $hour, $minute ) = split /:/, $stattime;
# if we're at the 10 minute marke, print out the averages
if ( $minute % 10 == 0 ) {
$avgtotal=$totals/10 ;
$avgremote=$remotes/10;
$avglocal=$locals/10;
$avgrelay=$relays/10;
$avgfile=$files/10;
# print "$stattime|\t$avgtotal\t$avgremote\t$avglo
cal\t$avgrelay\t$avgfile\n";
print "\t$avgtotal\t$stattime\n";
$totals=$remotes=$locals=$relays=$files=0;
}
else {
$totals += $total;
$remotes += $remote;
$locals += $local;
$relays += $relay;
$files += $file;
}

$remote=$relay=$file=$local=$total=0;
$stattime=$checktime;
}
}
}
close( FH);
(END)

Leave a comment