Version 2 (modified by jonmills, 7 years ago)

--

Overview

Part of being able to accurately monitor a Eucalyptus cluster is being able to monitor what the KVM hypervisor is doing on the Node Controllers. This page will show you how to set up a Check_MK native service check for the KVM hypervisor.

  • This assumes you have already installed the linux check_mk_agent on all your hosts.

The Qemu (KVM) plugin for check_mk_agent

* Install this on your hosts as /usr/lib/check_mk_agent/plugins/mk_qemu

if which virsh >/dev/null; then
	echo '<<<qemu>>>'
	virsh list | grep -v 'State' | grep -v '^--' | grep -v '^$' | while read L
	do
		ID=$(echo $L | awk '{print $1}')
		NAME=$(echo $L | awk '{print $2}')
		STATE=$(echo $L | awk '{print $3}')
		MEM=$(virsh dominfo $NAME | grep 'Used memory' | awk '{print $3}')
		let MEM=MEM/1024
		PID=$(ps aux | grep kvm | grep $NAME | awk '{print $2}')
		if [ $PID -gt 0 ]; then
			DATA=$(top -p $PID -n 1 -b | tail -n 2 | head -n 1 | awk -- '{print $9" "$10}')
		else
			DATA=""
		fi
		echo $ID" "$NAME" "$STATE" "$MEM" "$DATA
	done
fi

The Check_MK native 'qemu' check

  • The 'qemu' check gets installed on the monitoring host as $OMD_ROOT/share/check_mk/checks/qemu
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# based upon 'qemu' from
# 12/2010 Matthias Henze
#
# updated for libvirtd (virsh) by
# Jonathan Mills 09/2011

# Example output from agent:
# <<<qemu>>>
# 4 i-4B9008BE running 2048 4.0 2.7
# 5 i-44F608B6 running 2048 0.0 0.7




# inventory
def inventory_qemu(checkname, info):
    inventory = []
    for line in info:
        if line[2] == "running":  # only VM's running while inventory are monitored !
            vm = line[1] # we want to capture hostname, not vm id here
            inventory.append( (vm, None) )
    return inventory

# check
def check_qemu(name, param, info):
    for line in info:
        perfdata = []
        if line[1] == name:
            item = line[0]
            status = line[2]
            ram = line[3]
            infotext = "%s  (id: %s, ram: %s MB)" % (status, item, ram)
            if status == "running":
                perfdata.append( ( "CPU%", int(round(float(line[4]))) ) )
                perfdata.append( ( "RAM%", int(round(float(line[5]))) ) )
                return (0, "OK - status is " + infotext, perfdata)
            else:
                return (2, "CRITICAL - status is " + infotext, perfdata)
    return (3, "UNKNOWN - VM %s not found in agent output" % item) 

# declare the check to Check_MK
check_info['qemu'] = \
        (check_qemu, "VM %s", 1, inventory_qemu)

Using the 'qemu' check

  • You don't have to do anything special
  • Once installed, Check_MK will automatically detect all KVM virtual machines running on a host.