DX Application Performance Management

  • 1.  Problem with EPAgent

    Posted Sep 15, 2017 10:58 AM

    Hi guys,

     

    i like to know if anyone can help me...

     

    I need to monitor the connections in time_wait, close_wait and established of my server,
    I am creating a perl script to make this collection, but I always get this error,
    I wonder if anyone has already gone through this?

     

    Perl script:

     

    use FindBin;
    use lib ("$FindBin::Bin", "$FindBin::Bin/lib/perl", "$FindBin::Bin/../lib/perl");
            
    use Wily::PrintMetric;

     

    my $fileSystemConn5Command1 = `netstat -ano |find /C "CLOSE_WAIT"`;
          Wily::PrintMetric::printMetric( type        => 'IntCounter',
                                          resource    => 'fileSystemConn5',
                                          name        => 'conexoes_em_close_wait',
                                          value       => $fileSystemConn5Command1,
                                       );

     

    ERROR MESSAGE:

    9/15/17 11:21:50 AM BRT [ERROR] [EPAgent.EPAgent CONNECTION_CLOSE_WAIT] Error starting plugin process: Cannot run program "c:/program files/CA APM/epagent/epaplugins/windows/Connection_close_wait.pl": CreateProcess error=193, %1 is not a valid Win32 application



  • 2.  Re: Problem with EPAgent

    Broadcom Employee
    Posted Sep 15, 2017 01:57 PM

    Cross-posting to APM Dev. 



  • 3.  Re: Problem with EPAgent

    Broadcom Employee
    Posted Sep 16, 2017 06:45 PM

    Yeah, I probably should've put my responses there in hindsight.



  • 4.  Re: Problem with EPAgent

    Broadcom Employee
    Posted Sep 16, 2017 12:52 PM

    The short answer is the perl interpreter either is not resolving the script name properly, possibly because you have spaces in the path (avoid that like the plague with perl and shell scripts on windows) and/or because you have a quoted string inside the backticks. Any time you use backticks, you're at the mercy of the shell or command line interpreter, not perl. Best practice - keep anything inside backticks as simple as possible, be careful with quoting and escaping special characters, and test it separately.

     

    The longer answer is that this is not a very perlish solution. It looks like you have a bat file that you want to use as an EPAgent script, which is fine in general, but when converting from bat file to perl script you have to consider what
    it's doing. Perl is awesome at string matching, so rather than pipe the output of "netstat -ano" to windows find, iterate over the lines returned by netstat with perl and match to your hearts content. Better yet, go check https://metacpan.org to see if a module already exists that does what you want.

     

    Also, you're not doing any checking on the output of the shell command. It could return nothing, an error or something unexpected, any of which would cause it to give invalid data to the EPAgent.

     

    One last thing. When I get an unfamiliar error, the first thing I do is simply copy and paste it into Google. I pasted "CreateProcess error=193, %1 is not a valid Win32 application" into Google and found hundreds of on point responses, including this one.

     

    https://support.microsoft.com/en-ca/help/812486/event-id-7000-and-1-is-not-a-valid-win32-application-error-message-whe 

     

    Cheers,
    Barry



  • 5.  Re: Problem with EPAgent

    Broadcom Employee
    Posted Sep 16, 2017 12:56 PM
    use strict;

    use FindBin;
    use lib ( "$FindBin::Bin", "$FindBin::Bin/lib/perl", "$FindBin::Bin/../lib/perl" );
    use Wily::PrintMetric;

    my $netstatCmd = 'netstat -ano';
    my @response = `$netstatCmd`;
    my $CLOSE_WAIT_COUNT = 0;

    foreach my $line (@response)
    {
    $CLOSE_WAIT_COUNT++ if $line =~ /CLOSE_WAIT/;
    }

    Wily::PrintMetric::printMetric( type => 'IntCounter',
    resource => 'fileSystemConn5',
    name => 'conexoes_em_close_wait',
    value => $CLOSE_WAIT_COUNT,
    );


  • 6.  Re: Problem with EPAgent

    Broadcom Employee
    Posted Sep 16, 2017 01:21 PM
    my $fileSystemConn5Command1 = `netstat -ano |find /C "CLOSE_WAIT"`;

    Try this instead:

    # define my command to execute
    my $fileSystemConn5Command1 = "netstat -ano|find /C \"CLOSE_WAIT\"";
    # execute command
    my $results = `$fileSystemConn5Command1`;

    Now use Wily::PrintMetric::printMetric to send $results:

    Wily::PrintMetric::printMetric(  type => 'IntCounter',
                                     resource => 'fileSystemConn5',
                                     subresource => '',
                                     name => 'conexoes_em_close_wait',
                                     value =>$results,
                                  )

    here's what my test Perl program looks like:

    #!/usr/bin/perl
    use FindBin;
    use lib ("$FindBin::Bin", "$FindBin::Bin/lib/perl", "$FindBin::Bin/../lib/perl");
           
    use Wily::PrintMetric;

    use strict;
    use warnings;

    my $netstatCommand = "netstat -ano|find /C \"CLOSE_WAIT\"";
    my $results = `$netstatCommand`;


    Wily::PrintMetric::printMetric( type        => 'IntCounter',
                                    resource    => 'fileSystemConn5',
                                    subresource => 'CLOSE_WAIT',
                                    name        => 'conexoes_em_close_wait',
                                    value       => $results,
                                  )

    Here is the result:

    <metric type="IntCounter" name="fileSystemConn5|CLOSE_WAIT:conexoes_em_close_wait" value="21" />


  • 7.  Re: Problem with EPAgent

    Broadcom Employee
    Posted Sep 16, 2017 06:27 PM

    If you want to get really clever, do this:

    #!/usr/bin/perl
    use FindBin;
    use lib ("$FindBin::Bin", "$FindBin::Bin/lib/perl", "$FindBin::Bin/../lib/perl");
           
    use Wily::PrintMetric;

    use strict;
    use warnings;
    use feature qw(say);
    use Scalar::Util qw(looks_like_number);

    my (%hash, @keys);

    # command to execute
    my $netstatCommand = "netstat -ano";
    # execute command
    my @netstatResults = `$netstatCommand`;

    # start counting results after skipping the first 4 lines of output
    foreach my $i (4..$#netstatResults) {
        chomp $netstatResults[$i]; # remove EOL char
        # remove leading & trailing spaces
        $netstatResults[$i] =~ s/^\s+//;
        $netstatResults[$i] =~ s/\s+$//;
        #print "line:$netstatResults[$i]\n"; ## for debugging purposes only
        # split string on spaces; only keep value #4
        my (undef,undef,undef,$str,undef) = split /\s+/, $netstatResults[$i], 5;
        # check if scalar is defined, not blank, and doesn't look like a number
        if (defined $str && length $str > 0 && !looks_like_number($str)) {
            #print "string:$str\n"; ## for debugging purposes only
            $hash{$str}{count}++;
            push @keys, $str if $hash{$str}{count} == 1;
        }
    }

    for my $stat (@keys) {
        # The following two lines will print out the connection states &
        # the number of unique occurrences for debugging purposes only
        #say join "\t", $stat,
        #    $hash{$stat}{count};
       
        # print the results
        Wily::PrintMetric::printMetric( type        => 'IntCounter',
                                        resource    => 'NETSTAT',
                                        subresource => 'Connection State',
                                        name        => $stat,
                                        value       => $hash{$stat}{count},
                                      );
    }

    Here's the output:

    <metric type="IntCounter" name="NETSTAT|Connection State:LISTENING" value="70" />
    <metric type="IntCounter" name="NETSTAT|Connection State:ESTABLISHED" value="65" />
    <metric type="IntCounter" name="NETSTAT|Connection State:CLOSE_WAIT" value="2" />
    <metric type="IntCounter" name="NETSTAT|Connection State:TIME_WAIT" value="6" />


  • 8.  Re: Problem with EPAgent

    Posted Sep 19, 2017 08:32 AM

    Thank you guys, this really helped me a lot.



  • 9.  Re: Problem with EPAgent

    Posted Jul 19, 2018 09:09 AM

    it was really helpful to get more out from epagent.

     

    thanks all !