First, you need to create a directory under <epagent_install_dir>/epaplugins. Call this whatever you like.
For my example, I'm calling it ‘qmon'.
Place your Perl program in this new directory.
Update your EPA properties file to the location of the new directory by setting up a new stateless plugin
# you can append or prepend your new plugin to an already existing list of plugins
introscope.epagent.plugins.stateless.names=QMON
# use the fully qualified path to your plugin for this command property
introscope.epagent.stateless.QMON.command=perl <epagent_install_dir>/epaplugins/qmon/postqueue-monitor.pl
# this delay can be as small as 15 seconds or as long as you like
# try to use intervals of 15 seconds to match how APM processes data
introscope.epagent.stateless.QMON.delayInSeconds=900
Here is the code for you to test. Test this by running it just from Perl first to make sure the output looks correct.
#!/usr/bin/perl
# postfix queue/s size
# author:
use FindBin;
use lib ("$FindBin::Bin", "$FindBin::Bin/../lib/perl");
use Wily::PrintMetric;
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;
}
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'PostFix',
subresource => '',
name => 'Incoming',
value => count("incoming"),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'PostFix',
subresource => '',
name => 'Active',
value => count("active"),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'PostFix',
subresource => '',
name => 'Deferred',
value => count("deferred"),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'PostFix',
subresource => '',
name => 'Hold',
value => count("hold"),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'PostFix',
subresource => '',
name => 'Corrupt',
value => count("corrupt"),
);