NAME
Postfix::Mailq - a fast and reliable mailq-like utility for postfix
VERSION
version 0.01
SYNOPSIS
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->{$_};
}
DESCRIPTION
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.
It is a Postfix-specific
module.
MOTIVATION
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.
FUNCTIONS
get_fast_count()
Gets you a fast count of the messages in the spool dirs. Checks in active
, incoming
, deferred/*
by default.
If you want it to check in the hold
directory too, then you should supply an additional get_hold
option, as in:
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:
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:
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->{$_};
}
THANKS
Thanks to Bron Gondwana and the Opera Mail team for this code. I just cleaned it up and packaged it for CPAN.
AUTHOR
Cosimo Streppone <cosimo@opera.com>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2011 by Opera Software ASA.
This is free software, licensed under:
The (three-clause) BSD License