Nagios plugin sample for Xen Enterprise

23 Sep 2008 Nagios plugin sample for Xen Enterprise

I’ve been experimenting with Nagios recently and one of the BioTeam services I really want to keep an eye on is our Xen Enterprise virtualization platform. We have 2 licensed servers running the Xen Enterprise 4 hypervisor and since they share a common storage pool “resource” we are able to do live migration of VMs between physical servers. Nothing fancy but it gives us more administrative flexibility as well as reliability for the more important VMs we instantiate.

A quick google search for Nagios plugins designed to monitor Xen instances turns up a script from Novell that seems to be intended for the open-source version of Xen in that it only runs the command “xm list” in order to generate output.

The “xm” binary does not exist on our Xen Enterprise 4 hypervisors — the related command on our system seems to be “xe” which takes a heck of a lot more command-line arguments it seems than “xm“.

With a bit of hacking around, this is the command I want to run on our hypervisors – it simply lists the name of every detected VM that has a power-state switch set to “running”:

# xe vm-list params=name-label power-state=running

Nothing fancy, all I want to do is count the number of running VMs across both hypervisors and set a warning or critical Nagios alert if the number of “powered on” VMs goes below a certain threshold.

Using one of the standard plugin scripts, a sample script that does what I need would look something like this:



if [ "$PARM2" != "-c" -o "$CRIT" == "" ]; then
echo "Usage: $0 -w <warning> -c <critical>"
# Nagios exit code 3 = status UNKNOWN = orange

if [ "$PARM1" != "-h" ]; then
exit 3
echo ""
echo " -w = Minimum Number of Xen VMs to activate a warning message."
echo " -c = Number of Xen VMs to activate a critical message."
echo " -h = This help message."
exit 3

RUNNING=$(xe vm-list params=name-label power-state=running | awk '/:/{print $5}')
NBVMS=$(echo $RUNNING | wc -w)
SHORT=$(echo $RUNNING | awk '{sub(/$/," ");print}' )

#echo "Xen Running ="$NBVMS
#echo "SHORT =" $SHORT

if [ "$NBVMS" -le "$CRIT" ]; then
echo "Critical Xen VMs Usage - Only $NBVMS VMs in running state: $SHORT "
# Nagios exit code 2 = status CRITICAL = red
exit 2
else if [ "$NBVMS" -le "$WARN" ]; then
echo "Warning Xen VMs Usage - Only $NBVMS Vms in running state: $SHORT "
# Nagios exit code 1 = status WARNING = yellow
exit 1
echo "OK: Xen Enterprise - $NBVMS (power-state='running') VMs across all hypervisors.
Running VM list: $SHORT "
# Nagios exit code 0 = status OK = green
exit 0

Related Posts
Filter by
Post Page
Publications News Articles Science Featured Employee Posts
Sort by

AI in Healthcare: Lessons Learned From Moffitt Cancer Center, Mayo Clinic

Stan Gloss, founding partner at BioTeam, interviewed Ross Mitchell about how he has applied AI to healthcare
2021-12-02 06:54:08


More AWS HPC launches: FSx for Lustre and Elastic Fabric Adapter for MPI

Among the dizzying array of launches at this year’s
2018-11-30 14:42:18


, ,
  • pawel
    Posted at 16:56h, 21 April Reply

    Why don’t just do simple ping of xen VM’s (I presume that it has it’s own IP address)? If no response – critical.

  • Best way to monitor a Grid of computers?
    Posted at 02:27h, 29 November Reply

    […] is an example over here. April 21, 2010 9:28 am Ward I thought he meant monetize. April 21, 2010 9:46 am […]

  • Danny
    Posted at 06:58h, 07 February Reply

    I must be reading this script wrong, because I can only see it exit with return code 3. Both branches of the “if !-h” check have an exit 3…

Post A Comment