|
Packit |
667938 |
Using Mailstats with MRTG
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# 17/04/97: These files are based on a post
|
|
Packit |
667938 |
# made to the MRTG discussion list.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# I was then asked if I would contribute them to the distribution.
|
|
Packit |
667938 |
# Now I've cleaned up one or two minor things, but the message below
|
|
Packit |
667938 |
# is essentially the same as the distribution I have contributed.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# I also posted this to comp.mail.sendmail some time back.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# rachel polanskis <r.polanskis@nepean.uws.edu.au>
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
This is some experimenting I have done using sendmail and mrtg.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
Currently I am using Solaris 2.5.1 as the mailhost, and then plotting
|
|
Packit |
667938 |
the goodies using mrtg-2.0 on Linux 1.2.13 and displaying the graphs
|
|
Packit |
667938 |
on the linux box.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
There are some caveats on my method for plotting these charts:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
1: I use a previously undefined port and run the Solaris
|
|
Packit |
667938 |
/bin/mailstats program out of inetd.
|
|
Packit |
667938 |
For this reason, I can only assume the mailstat on Solaris
|
|
Packit |
667938 |
works - I have tried no other platforms.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
* Q: Is there a security risk involved in running Solaris Mailstat
|
|
Packit |
667938 |
out of inetd?
|
|
Packit |
667938 |
|
|
Packit |
667938 |
2: You must have Perl-5.002 or better installed on the plotting host.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
3: You must have MRTG-2.0 installed - you must know how to use it!
|
|
Packit |
667938 |
|
|
Packit |
667938 |
4: I am only interested in SMTP connections, and my scripts only
|
|
Packit |
667938 |
plot In and Out, since mrtg can only plot 2 lines per graph.
|
|
Packit |
667938 |
If you want any more than that - experiment! And then tell me
|
|
Packit |
667938 |
since I am only learning.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
Here goes:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
1: Ensure you have "/bin/mailstat" on your system.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
2: Enable "/etc/mail/sendmail.st"
|
|
Packit |
667938 |
To do this you can just make sure the entry for "sendmail.st" in
|
|
Packit |
667938 |
"sendmail.cf" is uncommented, and then do the command:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# touch /etc/mail/sendmail.st
|
|
Packit |
667938 |
|
|
Packit |
667938 |
And restart sendmail:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# /etc/init.d/sendmail stop
|
|
Packit |
667938 |
# /etc/init.d/sendmail start
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
3: Create the following shell-script:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#!/bin/sh
|
|
Packit |
667938 |
# smtp-stats: exec Solaris mailstats
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
if [ -x "/bin/mailstats" ]
|
|
Packit |
667938 |
then
|
|
Packit |
667938 |
exec /bin/mailstats -f/etc/mail/sendmail.st
|
|
Packit |
667938 |
fi
|
|
Packit |
667938 |
|
|
Packit |
667938 |
I run this out of /opt/local/bin, and call it "smtp-stats"
|
|
Packit |
667938 |
|
|
Packit |
667938 |
4: Now add the following to /etc/services:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# /etc/services
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
smtp-stats 7256/tcp # smtp-stats
|
|
Packit |
667938 |
|
|
Packit |
667938 |
I used port 7256 as it was undefined. You might like to select something
|
|
Packit |
667938 |
else.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
5: Add the following to /etc/inetd.conf:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# /etc/inetd.conf
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
smtp-stats stream tcp nowait root \
|
|
Packit |
667938 |
/opt/local/bin/smtp-stats smtp-stats
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
***Ensure that the above is all on *one* line. The sample above
|
|
Packit |
667938 |
is broken on 2 lines for legibility!!
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
6: Restart inetd
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
7: Test the port. you should see the following:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# telnet localhost 7256
|
|
Packit |
667938 |
Trying 127.0.0.1...
|
|
Packit |
667938 |
Connected to localhost.
|
|
Packit |
667938 |
Escape character is '^]'.
|
|
Packit |
667938 |
Statistics from Thu Feb 27 01:12:47 1997
|
|
Packit |
667938 |
M msgsfr bytes_from msgsto bytes_to Mailer
|
|
Packit |
667938 |
0 0 0K 96 393K prog
|
|
Packit |
667938 |
3 34 94K 0 0K local
|
|
Packit |
667938 |
5 93 474K 31 47K esmtp
|
|
Packit |
667938 |
========================================
|
|
Packit |
667938 |
T 127 568K 127 440K
|
|
Packit |
667938 |
Connection closed by foreign host.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
OK!!
|
|
Packit |
667938 |
|
|
Packit |
667938 |
The line we are interested in is line 5: The "esmtp" line.
|
|
Packit |
667938 |
This is the line we will use to get our stats.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
You might want to adjust this depending on how many mailer progs
|
|
Packit |
667938 |
you use...
|
|
Packit |
667938 |
|
|
Packit |
667938 |
I find the Totals to be useless, since it includes a lot of filtering
|
|
Packit |
667938 |
from procmail. I am only interested in SMTP connections...
|
|
Packit |
667938 |
|
|
Packit |
667938 |
####################################
|
|
Packit |
667938 |
Stage 2: MRTG
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
Here is a perl script I wrote to glom the values of the "esmtp" line (5)
|
|
Packit |
667938 |
and massage them into something mrtg understands.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
A file called "mailstats.old" is written to /tmp
|
|
Packit |
667938 |
to allow for doing my sums.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
I am a Perl Newbie - please don't be offended at my code.
|
|
Packit |
667938 |
I would like it if someone can help me with better methods one day!
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#!/usr/bin/perl
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# rachel polanskis - 240297
|
|
Packit |
667938 |
# this script relies on the sendmail.st file being activated.
|
|
Packit |
667938 |
# the data is called via "mailstats" which comes with SunOS/Solaris.
|
|
Packit |
667938 |
# mailstats is run out of inetd, on port 7256.
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
require 5.002;
|
|
Packit |
667938 |
use strict;
|
|
Packit |
667938 |
use Socket;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my ($remote, $port, $iaddr, $paddr, $proto, $line, $count, $oldfrm, $oldto, $curfrm, $curto, $msgsfrm, $msgsto, $a, $b, $c, $d);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
##
|
|
Packit |
667938 |
# open the old stats file for reading - we use this to get the differences
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
open (OLD,"
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# read the old data
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
while (<OLD>) {
|
|
Packit |
667938 |
if ($. == "1") {
|
|
Packit |
667938 |
$count = $_;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
($oldfrm, $oldto) = split (' ',$count);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
close (OLD);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
##
|
|
Packit |
667938 |
# Straight out of the blue Camel - pp. 349
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Change these next 2 lines to suit yourself.
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
$remote = "juno";
|
|
Packit |
667938 |
$port = "7256";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
if ($port =~ /\D/) {$port = getservbyname ($port, 'tcp')}
|
|
Packit |
667938 |
die "No port" unless $port;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$iaddr = inet_aton($remote) or die "no host: $remote";
|
|
Packit |
667938 |
$paddr = sockaddr_in($port, $iaddr);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$proto = getprotobyname ('tcp');
|
|
Packit |
667938 |
|
|
Packit |
667938 |
socket (SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
|
|
Packit |
667938 |
connect (SOCK, $paddr) or die "connect: $!";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
##
|
|
Packit |
667938 |
# munge the output data
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
while (<SOCK>) {
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($. == "5" ) {
|
|
Packit |
667938 |
$line = $_;
|
|
Packit |
667938 |
($a, $curfrm, $b, $curto, $c, $d) = split(' ',$line);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# do some sums
|
|
Packit |
667938 |
$msgsfrm = $curfrm - $oldfrm;
|
|
Packit |
667938 |
$msgsto = $curto - $oldto;
|
|
Packit |
667938 |
chomp $msgsfrm;
|
|
Packit |
667938 |
chomp $msgsto;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# open the old file for overwrite
|
|
Packit |
667938 |
open (OLD,">/tmp/mailstat.old") or die "can't open file!\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# print the data for mrtg
|
|
Packit |
667938 |
print "$msgsfrm\n$msgsto\n1\njuno\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# print the data to the old file
|
|
Packit |
667938 |
print OLD "$curfrm $curto\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
} #endif
|
|
Packit |
667938 |
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
close (SOCK) or die "close: $!";
|
|
Packit |
667938 |
exit;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
##########################
|
|
Packit |
667938 |
|
|
Packit |
667938 |
Now, Here is my mrtg.cfg file for mail.
|
|
Packit |
667938 |
I call it "mail.cfg"
|
|
Packit |
667938 |
I run mrtg from cron on my Linux box every 10 minutes to plot the stats.
|
|
Packit |
667938 |
It is up to the individual what they do with their own setup.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Mail: MRTG.cfg file for sendmail stats on mailhost.
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
|
|
Packit |
667938 |
WorkDir: /usr/local/etc/httpd/htdocs/stats/mrtg
|
|
Packit |
667938 |
Interval: 10
|
|
Packit |
667938 |
#---------------------------------------------------------------
|
|
Packit |
667938 |
Target[mail]: `/usr/local/bin/mrtg/mailstats`
|
|
Packit |
667938 |
MaxBytes[mail]: 150
|
|
Packit |
667938 |
Options[mail]: gauge
|
|
Packit |
667938 |
Title[mail]: Juno Sendmail Statistics
|
|
Packit |
667938 |
PageTop[mail]: Juno Sendmail Statistics
|
|
Packit |
667938 |
XSize[mail]: 500
|
|
Packit |
667938 |
Supress[mail]: my
|
|
Packit |
667938 |
YSize[mail]: 200
|
|
Packit |
667938 |
WithPeak[mail]: dwmy
|
|
Packit |
667938 |
YLegend[mail]: No. of messages
|
|
Packit |
667938 |
ShortLegend[mail]: messages
|
|
Packit |
667938 |
LegendI[mail]: Incoming:
|
|
Packit |
667938 |
LegendO[mail]: Outgoing:
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
That's it!!
|
|
Packit |
667938 |
|
|
Packit |
667938 |
You should have no problems running this stuff if you follow my
|
|
Packit |
667938 |
instructions.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
Any comments, advice or interesting suggestions
|
|
Packit |
667938 |
would be much appreciated.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
Do with my little hack as you like, as long as the developers
|
|
Packit |
667938 |
of sendmail, perl, and mrtg get some credit, as well as lil ol me
|
|
Packit |
667938 |
for dreaming this up!!!
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
have fun...
|
|
Packit |
667938 |
|
|
Packit |
667938 |
rachel polanskis <r.polanskis@nepean.uws.edu.au> 17/04/97
|
|
Packit |
667938 |
|