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
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." %";
}
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";
}