Postfix::Mailq - a fast and reliable mailq-like utility for postfix
version 0.01
my $mq = Postfix::Mailq::get_fast_count(); # $mq = { # active => 0, # total => 0, # incoming => 0, # deferred => 0, # # and optionally, hold # } if (! $mq) { die "Something's very wrong?"; } for (sort keys %{$mq}) { printf "%s: %-6d\n", $_, $mq->{$_}; }
This module implements a fast partial replacement for the mailq utility that comes with Postfix, where emphasis in on fast and reliable, not on complete.
mailq
It is a Postfix-specific module.
Postfix-specific
Why would you want to use a replacement for mailq?
Because the standard mailq can get very slow and unreliable if your system is under heavy I/O load.
If you use Nagios to monitor your mail queue, the nagios checks will fail if the system in under load, even if your mail queue is not stressed at all.
That sucks and must be fixed.
get_fast_count()
Gets you a fast count of the messages in the spool dirs. Checks in active, incoming, deferred/* by default.
active
incoming
deferred/*
If you want it to check in the hold directory too, then you should supply an additional get_hold option, as in:
hold
get_hold
my $mq = Postfix::Mailq::get_fast_count({ get_hold => 1 });
If your postfix spool directory is not in the default (specified by the DEFAULT_SPOOL_DIR constant, usually /var/spool/postfix, then you can specify your own with:
postfix
DEFAULT_SPOOL_DIR
/var/spool/postfix
my $mq = Postfix::Mailq::get_fast_count({ spool_dir => '/var/local/postfix/spool' });
The result is a hash reference with all counts by folder, as in:
Thanks to Bron Gondwana and the Opera Mail team for this code. I just cleaned it up and packaged it for CPAN.
Cosimo Streppone <cosimo@opera.com>
This software is Copyright (c) 2011 by Opera Software ASA.
This is free software, licensed under:
The (three-clause) BSD License
To install Postfix::Mailq, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Postfix::Mailq
CPAN shell
perl -MCPAN -e shell install Postfix::Mailq
For more information on module installation, please visit the detailed CPAN module installation guide.