26.2 Statistics
The
sendmail
program provides the ability to gather information
that can be used to produce valuable statistics. As you will see,
the 26.2.1 The sendmail.st File
The
sendmail
program can maintain
an ongoing record of
the total number and total sizes of all outgoing
and incoming mail messages handled by each delivery agent.
This ability is enabled by using the
OS
The
/etc/sendmail.st
Just declaring the
% Note that the gathering of statistics can later be turned off merely by renaming or removing the file.
If the 26.2.2 Viewing Statistics: mailstatsThe mailstats program is supplied with sendmail to provide a convenient way to print the contents of the sendmail.st file. The output of the mailstats program varies depending on the version of sendmail installed. For V8.8 sendmail the output looks like this:
Statistics from Fri May 10 11:23:55 1996 M msgsfr bytes_from msgsto bytes_to Mailer 1 0 0K 43 5913K *file* 3 26 546K 96 639K local 4 421 2996K 3271 78233K smtp ======================================== T 447 3542K 3410 84785K
The first line shows the time
the statistics file was begun.
The lines that follow show the number of messages
and the total size in kilobytes of those messages both received
( 26.2.3 Using cron for Daily and Weekly StatisticsThe mailstats program prints the contents of the sendmail.st file, but it does not zero the counters in that file. To clear (zero) that file, you need to truncate it. One easy way to truncate the sendmail.st file is
% When sendmail discovers an empty sendmail.st file, it begins gathering statistics all over again. One use for truncation is to collect daily reports from mailstats . Consider the following simple shell script:
#!/bin/sh ST=/etc/sendmail.st MS=/usr/ucb/mailstats if [ -s $ST -a -f $MS ]; then $MS | mail -s "Daily mail stats" postmaster cp /dev/null $ST fi exit 0
When run, this script checks to see whether a nonempty
sendmail.st
file
and program
mailstats
exist. If they do,
mailstats
is run, printing the statistics, which are then mailed
to
0 0 * * * sh /usr/ucb/mailstats.script >/dev/null 2>&1
Here, Some versions of mailstats allow you to specify a different location for the statistics file. The form of that specification varies with the version of sendmail being run (see mailstats (8)). Yours may look like one of the following:
%
If your version of
mailstats
allows a different location
(and name) for the statistics file, you can
move that file to the new location by revising the
OS/var/log/statlog Note that V8 mailstats (8) automatically parses the configuration file to find the location of its statistics file. Moving and renaming the statistics file allows one to automatically collect daily copies of that file. Consider the following variation on the previous shell script:
#!/bin/sh DIR=/var/log ST=statlog MS=/usr/ucb/mailstats if [ -d $DIR ]; then cd $DIR if [ -s $ST -a -f $MS ]; then test -f ${ST}.5 && mv ${ST}.5 ${ST}.6 test -f ${ST}.4 && mv ${ST}.4 ${ST}.5 test -f ${ST}.3 && mv ${ST}.3 ${ST}.4 test -f ${ST}.2 && mv ${ST}.2 ${ST}.3 test -f ${ST}.1 && mv ${ST}.1 ${ST}.2 test -f ${ST}.0 && mv ${ST}.0 ${ST}.1 test -f ${ST} && mv ${ST} ${ST}.0 touch ${ST} $MS -f $DIR/${ST}.0 | mail -s "Daily mail stats" postmaster fi fi exit 0
As before, the statistics are mailed to |
|