Gathering Statistics from syslog
The logfiles that syslog creates provide a wealth of information that can be used to examine and tune the performance of sendmail. To illustrate, we will present a simple shell script for printing daily total message volume.
In the following discussion, we will assume that
sendmail logging is enabled
(the LogLevel
option, LogLevel on page 1040, is
nonzero) and that all syslog(8)
messages for the facility mail
at level LOG_INFO are being placed
into the file
/var/log/syslog.
message_volume.sh
Each mail message that sendmail receives for delivery (excluding those processed from the queue) causes sendmail to log a message such as this:
date host sendmail[pid]: quid: from=sender, size=bytes, ...
That is, for each sender
that is logged (the from=
),
sendmail also logs the total
received size of the message in bytes
(the size=
).
By summing all the size=
lines in a
/var/log/syslog file, we can
generate the total volume of all messages received
for the period represented by that file. One way
to generate such a total is shown in the following
Bourne shell script:
#!/bin/sh LOG=/var/log/syslog TOTAL=`(echo 0; sed -e '/size=/!d' -e 's/.*size=//' -e 's/,.*/+/' $LOG; echo p; ) | dc` echo Total characters sent: $TOTAL
The sed(1) selects only
the lines in /var/log/syslog
that contain the expression size=
.[224] It then throws away all but the number
immediately following each size=
(the actual number
of bytes of each message), and appends a +
to each.
The entire sequence ...
Get sendmail, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.