DX Application Performance Management

Expand all | Collapse all

NEW BRANCH: EPAgent - Running perl script

Haruhiko Davis

Haruhiko DavisMar 26, 2018 11:52 AM

  • 1.  NEW BRANCH: EPAgent - Running perl script

    Posted Mar 26, 2018 11:44 AM

    Davis, 

     

    Do you have any sample for it ?

     

    Thanks, 

    Roberto



  • 2.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Mar 26, 2018 11:52 AM


  • 3.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Mar 26, 2018 11:53 AM

    In the future, I'd recommend you learn and use Perl instead. We already provide a module that will do the formatting for you. Use any of the provided plugins that come with EPA for examples.



  • 4.  Re: NEW BRANCH: EPAgent - Running perl script

    Posted Mar 26, 2018 02:20 PM

    I tried to use in this format 
    printf '<metric type="IntCounter", value="PostFix:Corrupt: %s',count("corrupt").'"/>\n'; but I cannot see the metrics due to the following error [ERROR] [EPAgent] Metric data from plugin 'Plugin POSTFIX' is invalid: <metric type="I ntCounter", value="PostFix:Incoming: 0"/>\n<metric type="IntCounter", value="PostFix:Active: 0"/>\n<metric typ e="IntCounter", value="PostFix:Deferred: 0"/>\n<metric type="IntCounter", value="PostFix:Bounced: 0"/>\n<metri c type="IntCounter", value="PostFix:Hold: 0"/>\n<metric type="IntCounter", value="PostFix:Corrupt: 0"/>\n



  • 5.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Mar 26, 2018 03:50 PM

    It should look like this:

     

    cntCorrupt=count("corrupt")

    echo "<metric type=\"IntCounter\" name=\"PostFix:Corrupt\” value=\"$cntCorrupt\"/>"
    or

    printf "<metric type=\"IntCounter\" name=\"PostFix:Corrupt\" value=\"%s"\/>\n" count("corrupt") 



  • 6.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Mar 26, 2018 03:51 PM


  • 7.  Re: NEW BRANCH: EPAgent - Running perl script

    Posted Mar 27, 2018 10:41 AM

    Hi Davis, 

     

    I tried to use this way but I am receiving the error below 

    Backslash found where operator expected at.line 29, near ""<metric type=\"IntCounter\",name=\"PostFix:Active\" value=\"%s"\"

     

    printf "<metric type=\"IntCounter\",name=\"PostFix:Incoming\"value=\"%s"\/>\n" count("incoming")

     

    Could you please help on this  ?



  • 8.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Mar 27, 2018 10:47 AM

    Try removing the newline ("\n”)  at the end of printf



  • 9.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Mar 27, 2018 10:48 AM

    You also need to remove the commas (",”)



  • 10.  Re: NEW BRANCH: EPAgent - Running perl script

    Posted Mar 27, 2018 10:56 AM

    I tried the line below but the issue is remaining 

     

    printf "<metric type=\"IntCounter\",name=\"PostFix:Incoming\"value=\"%s"\/> count("incoming")



  • 11.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Mar 27, 2018 11:05 AM

    You need to remove the commas:

     

    printf "<metric type=\"IntCounter\",name=\"PostFix:Incoming\"value=\"%s"\/> count("incoming")

     

    Also, it looks like you're missing a double-quote after the end of the XML:

     

    printf "<metric type=\"IntCounter\" name=\"PostFix:Incoming\" value=\"%s\"\/>" count("incoming")

     

    If you get another error after trying the last printf statement, please post the full error message.

     



  • 12.  Re: NEW BRANCH: EPAgent - Running perl script

    Posted Mar 27, 2018 11:14 AM

    Please see the error below 

     

    Bareword found where operator expected at ./postqueue-monitor.pl line 28, near ""<metric type=\"IntCounter\" name=\"PostFix:Incoming\" value=\"%s\"\/>" count"
    (Missing operator before count?)
    syntax error at ./postqueue-monitor.pl line 28, near ""<metric type=\"IntCounter\" name=\"PostFix:Incoming\" value=\"%s\"\/>" count"
    Execution of ./postqueue-monitor.pl aborted due to compilation errors.

     

    Also it is my script below 

     

    #!/usr/bin/env perl

    # postfix queue/s size
    # author:

    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 "<metric type=\"IntCounter\" name=\"PostFix:Incoming\" value=\"%s\"\/>" count("incoming")
    printf "<metric type=\"IntCounter\" name=\"PostFix:Active\" value=\"%s\"\/>" count("active")
    printf "<metric type=\"IntCounter\" name=\"PostFix:Deferred\" value=\"%s\"\/>" count("deferred")
    printf "<metric type=\"IntCounter\" name=\"PostFix:Hold\" value=\"%s\"\/>" count("hold")
    printf "<metric type=\"IntCounter\" name=\"PostFix:Corrupt\" value=\"%s\"\/>" count("corrupt")



  • 13.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Mar 27, 2018 12:43 PM

    Thanks for posting the code.

    Now that I know you're using Perl, I'll rewrite this for you.



  • 14.  Re: NEW BRANCH: EPAgent - Running perl script

    Posted Apr 03, 2018 04:37 PM

    Hi Davis, 

     

    Have you any news regarding this ?

     

    Thanks, 

    Roberto



  • 15.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Apr 03, 2018 04:44 PM

    Sorry, I will have an update for you shortly. I had some other priority requests come up.



  • 16.  Re: NEW BRANCH: EPAgent - Running perl script

    Broadcom Employee
    Posted Apr 04, 2018 11:47 PM

    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"),

                                  );



  • 17.  Re: NEW BRANCH: EPAgent - Running perl script

    Posted Apr 05, 2018 11:20 AM

    Hi Davis, 

     

     

    It  worked sucessfully. 

     

    Thanks for your help .  

    Roberto Borges