no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | monitors:xen [2009/11/23 06:13] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Xen Monitor ====== | ||
+ | |||
+ | ^ Author | [[ andrew@eiknet.com | Andrew Rankin ]] | | ||
+ | ^ Compatibility | Xymon 4.2 | | ||
+ | ^ Requirements | Python, Python-libvirt, | ||
+ | ^ Download | http:// | ||
+ | ^ Last Update | 2007-09-25 | | ||
+ | |||
+ | ===== Description ===== | ||
+ | |||
+ | Xen Monitoring script - This script is handy in that it sends information from the Dom0 on behalf of the DomUs. | ||
+ | |||
+ | |||
+ | ===== Installation ===== | ||
+ | === Client side === | ||
+ | |||
+ | On the Dom0: | ||
+ | |||
+ | - Install mi-vt.py into the < | ||
+ | - Modify mi-vt.py setting the bbhome, domain & hobbit_server variables | ||
+ | - Modify your clientlaunch.cfg, | ||
+ | |||
+ | < | ||
+ | # data from libvirt for virtual machines | ||
+ | [vt] | ||
+ | ENVFILE $HOBBITCLIENTHOME/ | ||
+ | CMD $HOBBITCLIENTHOME/ | ||
+ | LOGFILE $HOBBITCLIENTHOME/ | ||
+ | INTERVAL 5m | ||
+ | </ | ||
+ | |||
+ | === Server side === | ||
+ | |||
+ | * N/A | ||
+ | |||
+ | ===== Source ===== | ||
+ | ==== mi-vt.py ==== | ||
+ | <hidden onHidden=" | ||
+ | <code python> | ||
+ | |||
+ | # | ||
+ | ##### | ||
+ | # | ||
+ | # Created by Andrew Rankin (andrew [at] eiknet.com). | ||
+ | # Monitors current virtual machines on a Dom0 using libvirt and relays its findings to hobbit. | ||
+ | # | ||
+ | # Parts of this script were borrowed from libvirt example python scripts. | ||
+ | # | ||
+ | ##### | ||
+ | |||
+ | import libvirt | ||
+ | import sys | ||
+ | import os | ||
+ | import time | ||
+ | import socket | ||
+ | |||
+ | # Test to see if we are running xen. | ||
+ | if not os.access("/ | ||
+ | sys.exit(1) | ||
+ | |||
+ | ############### | ||
+ | |||
+ | bbhome = '/ | ||
+ | bbtest = ' | ||
+ | domain = ', | ||
+ | hobbit_server = ' | ||
+ | test_explanation = ' | ||
+ | status = {} | ||
+ | color = {} | ||
+ | hobbittime = time.strftime(" | ||
+ | domains = [] | ||
+ | DATA = {} | ||
+ | status_info = {} | ||
+ | |||
+ | ############### | ||
+ | |||
+ | # Connect to hypervisor | ||
+ | conn = libvirt.openReadOnly(None) | ||
+ | if conn == None: | ||
+ | print ' | ||
+ | sys.exit(1) | ||
+ | |||
+ | # Get a list of Domains | ||
+ | try: | ||
+ | domains = conn.listDomainsID() | ||
+ | except: | ||
+ | print ' | ||
+ | sys.exit(1) | ||
+ | |||
+ | # Get Physical systems specs | ||
+ | try: | ||
+ | (model, memory, cores, mhz, nodes, sockets, cpus, threads) = conn.getInfo() | ||
+ | except: | ||
+ | print ' | ||
+ | sys.exit(1) | ||
+ | |||
+ | DATA[socket.gethostname()] = "Host Server Specs\nMB Memory: %s\nNum CPUs: %s\nNum Cores: %s\nCPU MHz: %s\n\n" | ||
+ | %( memory, cpus, cores, mhz ) | ||
+ | |||
+ | for dom in domains: | ||
+ | info = conn.lookupByID(dom).info() | ||
+ | hostname = conn.lookupByID(dom).name() | ||
+ | dom_hostname = socket.gethostname() | ||
+ | percentmem = float() | ||
+ | state = str() | ||
+ | | ||
+ | if hostname == " | ||
+ | hostname = dom_hostname | ||
+ | |||
+ | # Warn on states | ||
+ | if info[0] == 1: | ||
+ | status[hostname] = bbtest + " OK" | ||
+ | color[hostname] = " | ||
+ | state = " | ||
+ | elif info[0] == 2: | ||
+ | status[hostname] = bbtest + " OK" | ||
+ | color[hostname] = " | ||
+ | state = " | ||
+ | elif info[0] == 3: | ||
+ | status[hostname] = bbtest + " Domain Paused" | ||
+ | color[hostname] = " | ||
+ | state = " | ||
+ | elif info[0] == 4: | ||
+ | status[hostname] = bbtest + " Domain Crashed" | ||
+ | color[hostname] = " | ||
+ | state = " | ||
+ | elif info[0] == 5: | ||
+ | status[hostname] = bbtest + " Domain Dying" | ||
+ | color[hostname] = " | ||
+ | state = " | ||
+ | elif info[0] == 6: | ||
+ | status[hostname] = bbtest + " Domain Shutdown" | ||
+ | color[hostname] = " | ||
+ | state = " | ||
+ | |||
+ | # more obvious explanation of colors | ||
+ | if color[hostname] != " | ||
+ | status_info[hostname] = " | ||
+ | | ||
+ | # Dom0 to carry warnings from its DomUs | ||
+ | if status_info[dom_hostname] == "": | ||
+ | status_info[dom_hostname] += "&" | ||
+ | status[dom_hostname] = status[hostname] | ||
+ | color[dom_hostname] = color[hostname] | ||
+ | else: | ||
+ | status_info[hostname] = "" | ||
+ | |||
+ | # Convert to MB | ||
+ | info[1] = info[1] / 1024 | ||
+ | info[2] = info[2] / 1024 | ||
+ | |||
+ | # Either Figure % memory or if less than 0, set to no max | ||
+ | if info[1] >= 0: | ||
+ | percentmem = ((float(info[2]) / memory) * 100) | ||
+ | else: | ||
+ | percentmem = ((float(info[2]) / memory) * 100) | ||
+ | info[1] = memory | ||
+ | |||
+ | if conn.lookupByID(dom).name() != " | ||
+ | # Create our hobbit data for this host | ||
+ | DATA[hostname] = " | ||
+ | %( state, percentmem, info[1], info[2], info[3] ) | ||
+ | # Create our hobbit data for the Dom0, this contains all data from all Virts | ||
+ | DATA[dom_hostname] += hostname+" | ||
+ | | ||
+ | # Push the dom0 name back on the end. | ||
+ | DATA[hostname] += " | ||
+ | |||
+ | # Send away! | ||
+ | for key in DATA.keys(): | ||
+ | command = " | ||
+ | %( bbhome, hobbit_server, | ||
+ | |||
+ | try: | ||
+ | os.system(command) | ||
+ | except: | ||
+ | print " | ||
+ | |||
+ | sys.exit(0) | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Known Bugs and Issues ===== | ||
+ | |||
+ | ===== To Do ===== | ||
+ | * Add CPU Time Tracking | ||
+ | |||
+ | ===== Credits ===== | ||
+ | * Andrew Rankin | ||
+ | * Tom Georgoulias | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * **2007-09-25** | ||
+ | * Initial release | ||