DX Application Performance Management

  • 1.  Epagent Script for KVM Monitoring

    Posted Mar 03, 2014 11:03 AM

    Hello Everyone,

    I recently needed to get some stats into Wily for KVMs installed on Linux Redhat servers, so I wrote a simple Perl script to get and publish the metrics.

    It publishes three metrics to Wily :

    1) KVM Host Status ( value 1 for running)
    2) JVM VM status for each VM running (value 1 for running)
    3) Total VMs found on the Host

    The code for the Epagent plugin is below, probably not the greatest code, but a starting point.

    From this I have been able to setup alerts on KVM hosts with less that the number of VMs running, totals of VMs in operation etc.

     

    ########################################################################
    # Introscope EPAgent Plugin Script - Report KVM VM Status
    ########################################################################

    #import our modules
    use FindBin;
    use lib ("$FindBin::Bin", "$FindBin::Bin/../lib/perl");
    use epaplugins::lib::perl::Wily::PrintMetric;
    use Sys::Hostname;
    use strict;

    my $count = 0;
    my $host = hostname;

    Wily::PrintMetric::printMetric( type        => 'IntAverage',
                                                  resource    => 'Kvm-host',
                                                  subresource => $host,
                                                  name        => 'Running',
                                                  value       => 1,
                                                );

    my @vms = `ps -ef | grep qemu-kvm | awk -F' ' '{print $17}' | grep -v grep`;
    my $vm;

    foreach $vm (@vms) {
          my $pos=index($vm,'mv00');
          my $vmname=substr($vm,$pos-3,10);
          $count = $count + 1;
          Wily::PrintMetric::printMetric( type        => 'IntAverage',
                                                        resource    => 'Kvm-vm',
                                                        subresource => $vmname,
                                                        name        => 'Running',
                                                        value       => 1,
                                                      );
    }

    # Add in a total found for the kvm host.....
    Wily::PrintMetric::printMetric( type        => 'IntAverage',
                                                  resource    => 'Kvm-host',
                                                  subresource => $host,
                                                  name        => 'TotalVMs',
                                                  value       => $count,
                                                );



  • 2.  RE: Epagent Script for KVM Monitoring

    Broadcom Employee
    Posted Mar 06, 2014 01:45 PM

    Nice job!

    I will add just a couple few of suggestions:

    • You do not need to declare 'my $vm' on a separate line; just do that in the foreach loop
      • foreach my $vm (@vms) {
    • You can also modify your use statement at line 8
      • use Wily::PrintMetric;
    • Move your counter to the bottom of the loop and use Perl-style incrementor
      • $count++;
    • Just count the array size (no add'l math here since it's not looking at index numbers)
      • $count = scalar (@vms);


  • 3.  RE: Epagent Script for KVM Monitoring

    Broadcom Employee
    Posted Mar 13, 2014 03:14 PM

    Nick,

    I'm going to change your thread from a question to just an information posting.