EmailGeneral ComputingLinuxTech

Perl Get Active Queue Size – NetXMS scripts

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,}$}) {
++$c;
} 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`;
chomp($qdir);
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.


[[email protected] kscripts]# ./queue-metrics-active.pl
0
[[email protected] kscripts]#

Leave a Reply

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