Perl Get Active Queue Size (NetXMS/PRTG Use case)

The following Perl script gets the size of the Postfix Active queue and outputs it.
(Used for queue monitoring on our NMS via SSH sensors, but might be useful in your environment)

#!/usr/bin/env perl
use strict;
use warnings;
use Symbol;
sub count {
my ($dir) = @_;
my $dh = gensym();
my $c = 0;
opendir($dh, $dir) or die "$0: opendir: $dir: $!\n";
while (my $f = readdir($dh)) {
if ($f =~ m{^[A-F0-9]{5,}$}) {
} elsif ($f =~ m{^[A-F0-9]$}) {
$c += count("$dir/$f");
closedir($dh) or die "closedir: $dir: $!\n";
return $c;
my $qdir = `postconf -h queue_directory`;
chdir($qdir) or die "$0: chdir: $qdir: $!\n";
printf count("active\n");

The output from this is extremely short – just the queue size, nothing else.

[root@home kscripts]# ./
[root@home kscripts]#

Previous Article

Leave a Reply

Your email address will not be published. Required fields are marked *.

You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>