1

sendmail 8.14.4

I want to setup monitoring to track how many queued messages I have on my sendmail server.

As per a somewhat related linux question I understand that the most efficient way to count raw files in a directory is \ls -afq | wc -l but I'd like something that returns a count of messages. Since sendmail stores queued messages in two parts (df and qf files) this can be misleading.

Mike B
  • 11,871
  • 42
  • 107
  • 168
  • can't test it right now, but you want something like `mailq | grep "Total requests"` – glenn jackman Sep 28 '17 at 22:30
  • @glennjackman Thanks for the suggestion. I thought about something similar but that seems like it would require a lot of administrative overhead... because the mailq command would be generating details on error, last retry time, sender, etc -- even if it was filtered out later. – Mike B Sep 28 '17 at 22:47
  • 2
    Unless your mail queue is corrupted you should have an equal number of `qf` and `df` files, so why not just count one of them? Such as `ls -afq qf* | wc -l` – chicks Sep 28 '17 at 23:31
  • @chicks Fair enough - that's probably the easiest. If you want to submit as an answer, I'll upvote. :-) – Mike B Sep 29 '17 at 18:37

1 Answers1

1

Unless your mail queue is corrupted you should have an equal number of qf and df files, so why not just count one of them? Such as:

ls -afq qf* | wc -l
chicks
  • 3,793
  • 10
  • 27
  • 36
  • **WARNING**: AFAIR older sendmail releases contained script to purge left behind garbage files from the queue directory. It may help to periodically compare "basic count" with results reported by `mailq`. – AnFi Sep 30 '17 at 07:07
  • 1
    @AndrzejA.Filip Noted, however the concern here is that if the queue is large, the `mailq` command would consume extra system resources gathering extra information that may not be necessary for the purpose of getting a raw count. The idea is to use this metric for a monitoring tool/dashboard. I'll update the original post to include the version of sendmail. – Mike B Oct 04 '17 at 18:24
  • And just to finish the thought here in case other folks stumble across this: the complete command might look something like: `ls -afq /var/spool/mqueue/qf* | wc -l` where `/var/spool/mqueue/` is your queue directory. I mention this because running the command remotely wouldn't necessarily execute from the queue directory itself. – Mike B Oct 09 '17 at 16:35