Scripts for monitoring Citrix XenServer

If you have information, script, utility, or idea that can be useful for HostMonitor community, you welcome to share information in this forum.
Post Reply
Michael Siepen
Posts: 13
Joined: Mon Sep 14, 2009 1:28 am
Location: Germany

Scripts for monitoring Citrix XenServer

Post by Michael Siepen »

Hi,

here are some scripts we're using to monitor our Citrix XenServers. As I am not a programmer they maybe not as elegant as they can be, but they serve our needs.

How many virtual machines are running on a host or pool:

Code: Select all

#!/bin/bash
xe vm-list power-state=running | grep running > /tmp/vmlist
COUNT=`wc -l < /tmp/vmlist`
if [ "$COUNT" -lt "$1" ]
  then
    echo "ScriptRes:Bad:"$COUNT
  else
    echo "ScriptRes:Ok:"$COUNT
  fi
This one checks cpu load on a host or pool:

Code: Select all

#!/usr/bin/perl

$limit = $ARGV[0];
$i = 0;
$LAST = 0;
my @LOAD;

`xe host-cpu-list | grep uuid > /tmp/cpulist`;

open(DATEI, "</tmp/cpulist") || die "Datei nicht gefunden";
my @Zeilen = <DATEI>;
close(DATEI);

foreach (@Zeilen) {
	chomp($_);
	}

foreach(@Zeilen) {
	$_ =~ s/uuid \( RO\)           : //;
	push(@NeueZeilen,$_)
	}

foreach(@NeueZeilen) {
	$AUFRUF = 'xe host-cpu-param-get uuid='.$NeueZeilen[$i].' param-name=utilisation';
	$LOAD[$i] = qx($AUFRUF);
	$i++;
	}
	
for ($j = 0; $j <= $i; $j++) {	
	$LAST=$LAST+$LOAD[$j];
	}

$LAST=$LAST/$i;

$LAST=sprintf("%.3f", $LAST);
$LAST=$LAST*100;
if ($LAST > $limit) {
print "ScriptRes:Bad:".$LAST." %";
} else {
print "ScriptRes:Ok:".$LAST." %";
}
Checks for free physical memory:

Code: Select all

#!/usr/bin/perl
$limit = $ARGV[0];
chomp($str = `xe host-list params=memory-free`);
$membyte = substr($str,23,length($str)-23);
$memkbyte = $membyte/1024;
$memmbyte = $memkbyte/1024;
$memgbyte = $memmbyte/1024;
$memfree = sprintf("%.3f", $memgbyte);
if ($memmbyte > $limit) {
print "ScriptRes:Ok:".$memfree." GB";
} else {
print "ScriptRes:Bad:".$memfree." GB";
}
Michael Siepen
Posts: 13
Joined: Mon Sep 14, 2009 1:28 am
Location: Germany

Post by Michael Siepen »

Checks free space on a storage repository:

Code: Select all

#!/usr/bin/perl
$limit = $ARGV[0];
chomp($belegt = `xe sr-param-get uuid=$ARGV[1] param-name=physical-utilisation`);
chomp($total = `xe sr-param-get uuid=$ARGV[1] param-name=physical-size`);
$membyte = $total - $belegt;
$memkbyte = $membyte/1024;
$memmbyte = $memkbyte/1024;
$memgbyte = $memmbyte/1024;
$memfree = sprintf("%.3f", $memgbyte);
if ($memmbyte > $limit) {
print "ScriptRes:Ok:".$memfree." GB";
} else {
`xe message-create name="Speicherplatz auf SR" body="Speicherplatz auf dem genannten SR ist fast erschoepft. Noch $memfree GB verfuegbar" priority=1 sr-uuid=$ARGV[1]`;
print "ScriptRes:Bad:".$memfree." GB";
}
Checks if a specific virtual machine is running:

Code: Select all

#!/usr/bin/perl

`xe vm-list name-label=$ARGV[0] power-state=running > /tmp/vm.run`;

if (-z "/tmp/vm.run") {
print "ScriptRes:Bad:".$ARGV[0]." läuft nicht";
} else {
print "ScriptRes:Ok:".$ARGV[0]." läuft";
}
Post Reply