KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Scripts for monitoring Citrix XenServer

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Library
View previous topic :: View next topic  
Author Message
Michael Siepen



Joined: 14 Sep 2009
Posts: 13
Location: Germany

PostPosted: Mon Sep 14, 2009 1:43 am    Post subject: Scripts for monitoring Citrix XenServer Reply with quote

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:
#!/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:
#!/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:
#!/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";
}
Back to top
View user's profile Send private message
Michael Siepen



Joined: 14 Sep 2009
Posts: 13
Location: Germany

PostPosted: Mon Sep 14, 2009 1:43 am    Post subject: Reply with quote

Checks free space on a storage repository:
Code:
#!/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:
#!/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";
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index