NickEngland1309652

Epagent Script for KVM Monitoring

Discussion created by NickEngland1309652 on Mar 3, 2014
Latest reply on Mar 13, 2014 by Hiko_Davis

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

Outcomes