Best way to measure sendmail queue depth?

Greg Matthews gmatt at
Fri Jun 30 16:49:36 IST 2006

Furnish, Trever G wrote:
> I've been checking sendmail inbound queue depth using a simple readdir
> and dividing the number of entries by two.  This is checked every five
> minutes by Nagios with a 10-second timeout -- because of the timeout and
> the frequency with which I want to do the check, I can't just use, for
> example:
>     mailq |head -1
> ...because under heavy flow conditions the mailq command takes WAY too
> long to parse the entire set of queue files and generates too much load.
> I always realized dividing the number of files in the queue by two was
> only a rough guess, but I didn't realize there could be so much
> disparity between that number and the number of messages listed by
> mailq.  With mailq reporting 6 messages in the inbound queue, the
> directory actually contains 477 files!
> Mailq's result seems to match the count of files starting with a
> lowercase "q".  I also have about the same number of files starting with
> an uppercase "Q".  The rest of the files are df files, most of them
> without any corresponding q file.

I've reported a steadily growing in-queue here before and it is these 
"orphaned" df files that are the culprit. I have made sure my systems 
use the posix file locking as suggested but still I see a steady 
increase in the number of orphaned data files. I use the attached script 
to get rid of them. This script does more than just check for the age of 
the file, it also checks whether it really is orphaned. It also doesnt 
remove files outright, just moves them. If the directory you move them 
to is on the same partition, this operation is lightening fast (if that 
is important - personally, I have seperate /var and /var/spool partitions).

The stopping and starting of MailScanner is probably unnecessarily paranoid.

> Any idea what's going on?  Previously I expected to find files that
> started with qf, df, xf, and tf (not Q), and to always have pairs of
> files.  Obviously my expectation was pretty far off. :-)
> --
> Trever

Greg Matthews           01491 692445
Head of UNIX/Linux, iTSS Wallingford

This message (and any attachments) is for the recipient only. NERC
is subject to the Freedom of Information Act 2000 and the contents
of this email and any reply you make may be disclosed by NERC unless
it is exempt from release under the Act. Any material supplied to
NERC may be stored in an electronic records management system.

-------------- next part --------------
# clean up orphaned df* files in
# no known cause for these files yet.

/etc/init.d/MailScanner stop

sleep 2

file=`find $dir -mtime +1`
for i in ${file}
    do m=`basename ${i}`
    if [ ! -e "${dir}/qf${j}" ]; then
	mv ${i} /var/tmp/
df -hl

/etc/init.d/MailScanner start

exit 0

More information about the MailScanner mailing list