Inhaltsverzeichnis

Check für Linux KVM/qemu auf Basis von Proxmox

Die Idee dabei ist, dass das überwacht wird was WÄHREND des Inventory an VMs läuft. Kommt eine VM dazu dann wird ein „-II“ nötig. Ausserdem werden Perfomancedaten für CPU-Last und Ram gesammelt.

Client-Check

/usr/lib/check_mk_agent/plugins/mh_qemu

#!/bin/sh

# check_mk check f. LSI Controller
#
# 10/2010 Matthias Henze
# 03/2014 MH: an Wheezy angepasst
# Lizenz: GPL v2

# sampel output
#       101 oracle               stopped    1024               8.00 0         
#       102 server               running    3072              50.00 2634      
#       103 monitoring           running    2048              32.00 5139      
#       104 nagios               running    1024              32.00 9030

if which qm >/dev/null ; then
    echo '<<<qemu>>>'
    qm list | grep -v VMID | while read L
    do
        PID=$(echo $L | awk -- '{print $6}')
        if [ $PID -gt 0 ]; then
            DATA=$(top -p $PID -n 1 -b | tail -n 1 | awk -- '{print $9" "$10}')
        else
            DATA=""
        fi
        echo $L" "$DATA
    done
fi

Neue Version für neues TOP:

#!/bin/sh
 
# check_mk check f. LSI Controller
#
# 10/2010 Matthias Henze
# Lizenz: GPL v2
 
# sampel output
#       101 oracle               stopped    1024               8.00 0         
#       102 server               running    3072              50.00 2634      
#       103 monitoring           running    2048              32.00 5139      
#       104 nagios               running    1024              32.00 9030
 
if which qm >/dev/null ; then
    echo '<<<qemu>>>'
    qm list | grep -v VMID | while read L
    do
        PID=$(echo $L | awk -- '{print $6}')
        if [ $PID -gt 0 ]; then
            DATA=$(top -p $PID -n 1 -b | tail -n 1 | awk -- '{print $9" "$10}')
        else
            DATA=""
        fi
        echo $L" "$DATA
    done
fi

Plugin

local/share/check_mk/checks/qemu

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# check_mk check f. LSI Controlle
#
# 12/2010 Matthias Henze
# Lizenz: GPL v2


# Example output from agent:
#<<<qemu>>>
#      VMID NAME                 STATUS     MEM(MB)    BOOTDISK(GB) PID      CUP  RAM
#       101 oracle               stopped    1024               8.00 0         0    0
#       102 server               running    3072              50.00 2634      0    0
#       103 monitoring           running    2048              32.00 5139      0    0
#       104 nagios               running    1024              32.00 9030      0    0



# 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[0]
            inventory.append( (vm, None) )
    return inventory

# check
def check_qemu(item, param, info):
    for line in info:
        perfdata = []
        if line[0] == item:
            name = line[1]
            status = line[2]
            ram = line[4]
            infotext = "%s  (id: %s, name: %s)" % (status, item, name)
            if status == "running":
                perfdata.append( ( "CPU%", int(round(float(line[6]))) ) )
                perfdata.append( ( "RAM%", int(round(float(line[7]))) ) )
                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, "QEMU VM %s", 1, inventory_qemu)