Article
Contents:
- Introduction
- Xen Virtual Machine Monitor
- CHECK_XENVM Plugin
- CHECK_XENVM Configuration
- Editing Sudoers
- Testing the Nagios Plugin
- Xen Migrating Monitoring Examples
Introduction
This document describes a Nagios plugin — a "Xen Virtual Machine Monitor" which can be easily integrated in an existing Nagios system environment.
SUSE Linux Enterprise Server (SLES10) features Server Virtualization with Xen. When using "Xen paravirtualization or full virtualization" in the Data Center for Server Consolidation, one will discover soon the powerful Xen option of migrating Xen virtual machines (VMs) from one physical server to another. Furthermore when using "Xen Live Migration" Xen VMs can be moved under fully load from one machine to another, while the services on the VM keeps running without noticeable interruption for the users.
Migrating Xen VMs between physical servers requires new management and monitoring tools when server virtualization is used within the Data Center. According to Novell's vision of Data Center Automation the
Novell ZENworks Orchestrator is the answer and the solution for Xen Management and Monitoring within the enterprise. ZENworks Orchestrator serves as the "brain" that allows policy-based automation, that automates the process of deploying and managing virtual data center assets, as well as dynamically provisioning workloads and ensuring business continuity.
The described Nagios plugin for Xen does not eliminate the need of a Xen Management tool, when using serveral Xen Servers running multiple Xen VMs each in your enterprise. It just provides a view on the Xen Host Servers to know where your Xen VMs are actual running. According to the Nagios functionallity defining up to three return values, you are able to define a minimum number of running Xen VMs, which are expected to run in the productive Xen system environment on the Xen Hypervisors — the physical SLES10 servers. Depending on the configured values for the "Xen Virtual Machine Monitor" plugin, Nagios diplays green (OK), yellow (WARNING) or red (CRITICAL) status, when using the Nagios Web interface as shown below.
Xen Virtual Machine Monitor
The Nagios plugin check_xenvm is based of a simple shell script which performs the "xm list" command and returns the Xen VM names back to Nagios. The script should be self-explanatory for everybody, so feel free to adapt it to your own needs and flavor. The input and return values of check_xenvm correspond to the common used Nagios plugin interface, where the plugin can be called with a threshold to trigger a warning or critical message, which is returned by the Nagios plugin when the check on the server was performed.
Here is a sample output of the "xm list" command:
# xm list Name ID Mem(MiB) VCPUs State Time(s) Domain-0 0 256 1 r----- 742.1 xen-vm1 1 512 2 ------ 824.5 xen-vm2 2 256 2 ------ 660.6
When installing check_xenvm on your servers, you will of course only run the plugin on the physical servers and not on the Xen VMs.
Note: According to your Nagios configuration you need to check as which user nagios, and if used the nrpe daemon runs on your system. Normally you will run Nagios as user nagios. The point is that the check_xenvm plugin executes the Xen command "xm list" which needs to be run with root permissions, otherwise the plugin will fail. For further information see section "Editing Sudoers".
CHECK_XENVM Plugin
The check_xenvm Nagios plugin is shown below in this section. Just copy & paste the shell script and put the plugin below the path /usr/lib/nagios/plugins.
Here is an overview about the necessary steps:
- Login as root
- e.g. "vi /usr/lib/nagios/plugins/check_xenvm"
- cut and paste the following lines below
- save file
- chmod 755 /usr/lib/nagios/plugins/check_xenvm
#!/bin/sh
#
# COPYRIGHT : (c) 2006 SUSE Linux GmbH. All rights reserved.
#
# AUTHOR : Axel Schmidt
#
# BELONGS TO : NLPOS/SLEPOS/Xen Nagios Integration
#
# DESCRIPTION : Runs "xm list" and returns the available xen vms
#
# $Revision: 1.0 $
#
# Permission to use, copy, modify, distribute, and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation.
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHOR OR SUSE BE LIABLE FOR ANY CLAIM, DAMAGES
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.
PARM1=$1
WARN=$2
PARM2=$3
CRIT=$4
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
else
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
fi
fi
RUNNING=$(sudo /usr/sbin/xm list | awk '!/[DN]/ {print $1 }')
NBVMS=$(echo $RUNNING | wc -w)
HNAME=$(hostname)
#echo "Xen Running =" $RUNNING
if [ "$NBVMS" -le "$CRIT" ]; then
echo "Critical Xen VMs Usage - Total NB: $NBVMS - detected VMs: $RUNNING"
# Nagios exit code 2 = status CRITICAL = red
exit 2
else if [ "$NBVMS" -le "$WARN" ]; then
echo "Warning Xen VMs Usage - Total NB: $NBVMS - detected VMs: $RUNNING"
# Nagios exit code 1 = status WARNING = yellow
exit 1
else
echo "OK: Xen Hypervisor \"$HNAME\" is running Xen VMs: $RUNNING"
# Nagios exit code 0 = status OK = green
exit 0
fi
fi
CHECK_XENVM Configuration
The Nagios plugin for Xen is designed to run on the Xen Hypervisor the physical Xen servers to monitor the running Xen VMs. Therefore we have to add the check_xenvm service to the corresponding Nagios configuration files for all physical servers while monitoring all Xen available machines with Nagios. The Nagios configuration files are located below the path /etc/nagios.
Example entry for /etc/nagios/checkcommands.cfg:
# added for Xen VM Monitoring
define command{
command_name check_xen_vm
command_line $USER1$/check_xenvm -w $ARG1$ -c $ARG2$
}Example entry for /etc/nagios/services.cfg:
define service{
use generic-service
host_name localhost
service_description Xen Virtual Machine Monitor
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 60
notification_period 24x7
check_command check_xen_vm!2!0
}or when using the Nagios Remote Plugin Executor (NRPE):
define service{
use generic-service
host_name webprod02.mydomain.com,
webprod03.mydomain.com,
webprod04.mydomain.com,
webprod05.mydomain.com
service_description Xen Virtual Machine Monitor
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 960
notification_period 24x7
check_command check_nrpe!check_xen
}Example entry for /etc/nagios/nrpe.cfg:
command[check_xen]=/usr/lib/nagios/plugins/check_xenvm -w 2 -c 0
Editing Sudoers
The "sudo" configuration file specifies what a user may execute as another user and can be used for adding system function calls like "/usr/sbin/xm list" that requires root permissions. After sudoers is configured, the user, e.g. nagios may execute "sudo /usr/sbin/xm list" without being asked to type in the root password. Adapt the sudoers entry to your Nagios or NRPE configuration!
To edit /etc/sudoers perform the following steps:
- Login as root
- Execute: visudo1
- Add the following line:
nagios ALL=(ALL) NOPASSWD:/usr/sbin/xm list - Save changes and exit visudo
Testing the Nagios Plugin
Here is a short summary of the necessary steps needed to run the Nagios plugin for Xen within your Nagios system environment:
- Provide the Nagios plugin /usr/lib/nagios/plugins/check_xenvm on all Xen Host servers.
- Edit the Nagios configuration files below /etc/nagios to provide check_xenvm as monitoring service for all Xen Host server.
- Edit /etc/sudoers to alow your Nagios and/or NRPE daemon to execute the "xm list" command.
- Restart the Nagios and/or NRPE daemon to activate your changes:
/etc/init.d/nagios restart
/etc/init.d/nrpe restart - Launch the nagios GUI at http://<Nagios Server IP address>/nagios/
- Have fun!
Xen Migrating Monitoring Examples
The picture below demonstrate the Nagios monitoring view, when the two Xen virtual machines xen-vm1 and xen-vm4 are migrating from the Xen Server webprod04 to webprod05.
Note that the check_xenvm command is only executed every 5 minutes as configured in the Nagios services.cfg file. Therefore the "xm top" display from webprod04 of the first sceenshot below only shows the remaining xen_vm4 machine, before it was finally moved and migrated to webprod05. The "xm top" display from webprod05 shows all available Xen VMs (xen-vm1 to xen_vm4), where xen_vm4 is shown in the state paused (p) and the other Xen VMs are in the state running (r) or blocked (b = the vcpu is awaiting for an external event to happen).
The second screenshot demonstrates the result after the check_xenvm command was performed again — 5 minutes later. All Xen VMs are shown running (state "r" or "b") on the webprod05 Xen server. The red critical entries for the servers webprod03 and webprod04 state, that there are actual no Xen VMs running on these servers, asuming when using a Xen virtualization environment, that at least one VM is running on each Xen Hypervisor.
Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).
It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.
Related Articles
- Monthly Market Update: Cloud Archiving | May 2010
- A CUPS PDF Printer for your SUSE Linux Enterprise Desktop
- Installing Audit Server on 64-bit Machine with 64-bit eDirectory
- Loyal GroupWise Users Need Complimentary Hosted Applications
- PartnerNet Opportunity Management System - Planned Outage: May 16 - May 17
User Comments
- Be the first to comment! To leave a comment you need to Login or Register
- 10410 reads





0