Changes between Initial Version and Version 1 of OMDqemu

Show
Ignore:
Timestamp:
10/04/11 14:11:25 (8 years ago)
Author:
jonmills (IP: 152.54.8.104)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OMDqemu

    v1 v1  
     1== Overview == 
     2 
     3Part 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. 
     4 
     5 * This assumes you have already installed the linux check_mk_agent on all your hosts. 
     6  * [http://mathias-kettner.de/checkmk_linuxagent.html Read more about the Check_MK Agent] 
     7  * [http://mathias-kettner.de/check_mk_download.html Download] and install the agent on all your linux hosts... 
     8  * It runs on tcp port 6556, so make sure to open that port in your iptables firewalls... 
     9 
     10== The Qemu (KVM) plugin for check_mk_agent == 
     11 
     12* Install this on your hosts as /usr/lib/check_mk_agent/plugins/mk_qemu 
     13 
     14{{{ 
     15if which virsh >/dev/null; then 
     16        echo '<<<qemu>>>' 
     17        virsh list | grep -v 'State' | grep -v '^--' | grep -v '^$' | while read L 
     18        do 
     19                ID=$(echo $L | awk '{print $1}') 
     20                NAME=$(echo $L | awk '{print $2}') 
     21                STATE=$(echo $L | awk '{print $3}') 
     22                MEM=$(virsh dominfo $NAME | grep 'Used memory' | awk '{print $3}') 
     23                let MEM=MEM/1024 
     24                PID=$(ps aux | grep kvm | grep $NAME | awk '{print $2}') 
     25                if [ $PID -gt 0 ]; then 
     26                        DATA=$(top -p $PID -n 1 -b | tail -n 2 | head -n 1 | awk -- '{print $9" "$10}') 
     27                else 
     28                        DATA="" 
     29                fi 
     30                echo $ID" "$NAME" "$STATE" "$MEM" "$DATA 
     31        done 
     32fi 
     33}}} 
     34 
     35 
     36== The Check_MK native 'qemu' check == 
     37 
     38 * The 'qemu' check gets installed on the monitoring host as $OMD_ROOT/share/check_mk/checks/qemu 
     39 
     40{{{ 
     41#!/usr/bin/python 
     42# -*- encoding: utf-8; py-indent-offset: 4 -*- 
     43 
     44# based upon 'qemu' from 
     45# 12/2010 Matthias Henze 
     46# 
     47# updated for libvirtd (virsh) by 
     48# Jonathan Mills 09/2011 
     49 
     50# Example output from agent: 
     51# <<<qemu>>> 
     52# 4 i-4B9008BE running 2048 4.0 2.7 
     53# 5 i-44F608B6 running 2048 0.0 0.7 
     54 
     55 
     56 
     57 
     58# inventory 
     59def inventory_qemu(checkname, info): 
     60    inventory = [] 
     61    for line in info: 
     62        if line[2] == "running":  # only VM's running while inventory are monitored ! 
     63            vm = line[1] # we want to capture hostname, not vm id here 
     64            inventory.append( (vm, None) ) 
     65    return inventory 
     66 
     67# check 
     68def check_qemu(name, param, info): 
     69    for line in info: 
     70        perfdata = [] 
     71        if line[1] == name: 
     72            item = line[0] 
     73            status = line[2] 
     74            ram = line[3] 
     75            infotext = "%s  (id: %s, ram: %s MB)" % (status, item, ram) 
     76            if status == "running": 
     77                perfdata.append( ( "CPU%", int(round(float(line[4]))) ) ) 
     78                perfdata.append( ( "RAM%", int(round(float(line[5]))) ) ) 
     79                return (0, "OK - status is " + infotext, perfdata) 
     80            else: 
     81                return (2, "CRITICAL - status is " + infotext, perfdata) 
     82    return (3, "UNKNOWN - VM %s not found in agent output" % item)  
     83 
     84# declare the check to Check_MK 
     85check_info['qemu'] = \ 
     86        (check_qemu, "VM %s", 1, inventory_qemu) 
     87}}} 
     88