Created
June 30, 2014 01:38
-
-
Save alice-xu/cf3d075f684116feb53a to your computer and use it in GitHub Desktop.
Virtual Machine monitoring script for Zabbix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# virsh_vm_stats.sh: | |
# Virtual Machine monitoring script for Zabbix | |
# | |
# $1: Virtual Machine dom-uuid | |
# | |
# script settings. | |
export LANG='en_US.UTF-8' | |
cd `dirname $0` | |
source ./zbx_functions | |
DOM_UUID="$1" | |
[ -z "${DOM_UUID}" ] && echo "ERROR: dom-uuid is not provided." && exit 1 | |
POLLING_TIME=$( date '+%s' ) | |
RESULT=$( virsh dominfo "${DOM_UUID}" 2> /dev/null ) | |
[ -z "${RESULT}" ] && echo "ERROR: could not get dom-info for DOM_UUID:${DOM_UUID}." && exit 1 | |
VM_OS_TYPE=$( echo "${RESULT}" | grep 'OS Type:' | sed -e 's/.*: *//g' ) | |
[ -z "${VM_OS_TYPE}" ] && VM_OS_TYPE='unknown' | |
VM_STATE=$( echo "${RESULT}" | grep 'State:' | sed -e 's/.*: *//g' ) | |
[ -z "${VM_STATE}" ] && VM_STATE='unknown' | |
VM_CPUS=$( echo "${RESULT}" | grep 'CPU(s):' | sed -e 's/.*: *//g' ) | |
[ -z "${VM_CPUS}" ] && VM_CPUS='0' | |
VM_CPU_TIME=$( echo "${RESULT}" | grep 'CPU time:' | sed -e 's/.*: *//g' -e 's/s$//g' ) | |
[ -z "${VM_CPU_TIME}" ] && VM_CPU_TIME='0' | |
VM_MAX_MEMORY=$( echo "${RESULT}" | grep 'Max memory:' | sed -e 's/.*: *//g' -e 's/ kB//g' ) | |
[ -z "${VM_MAX_MEMORY}" ] && VM_MAX_MEMORY='0' | |
VM_USED_MEMORY=$( echo "${RESULT}" | grep 'Used memory:' | sed -e 's/.*: *//g' -e 's/ kB//g' ) | |
[ -z "${VM_USED_MEMORY}" ] && ='0' | |
VM_PERSISTENT=$( echo "${RESULT}" | grep 'Persistent:' | sed -e 's/.*: *//g' ) | |
[ -z "${VM_PERSISTENT}" ] && VM_PERSISTENT='unknown' | |
VM_AUTOSTART=$( echo "${RESULT}" | grep 'Autostart:' | sed -e 's/.*: *//g' ) | |
[ -z "${VM_AUTOSTART}" ] && VM_AUTOSTART='unknown' | |
{ | |
echo "\"${DOM_UUID}\" script.virsh_vm_stats.os_type ${POLLING_TIME} \"${VM_OS_TYPE}\"" | |
echo "\"${DOM_UUID}\" script.virsh_vm_stats.state ${POLLING_TIME} \"${VM_STATE}\"" | |
echo "\"${DOM_UUID}\" script.virsh_vm_stats.cpus ${POLLING_TIME} ${VM_CPUS}" | |
echo "\"${DOM_UUID}\" script.virsh_vm_stats.cpu_time ${POLLING_TIME} ${VM_CPU_TIME}" | |
echo "\"${DOM_UUID}\" script.virsh_vm_stats.max_memory ${POLLING_TIME} ${VM_MAX_MEMORY}" | |
echo "\"${DOM_UUID}\" script.virsh_vm_stats.used_memory ${POLLING_TIME} ${VM_USED_MEMORY}" | |
echo "\"${DOM_UUID}\" script.virsh_vm_stats.persistent ${POLLING_TIME} \"${VM_PERSISTENT}\"" | |
echo "\"${DOM_UUID}\" script.virsh_vm_stats.autostart ${POLLING_TIME} \"${VM_AUTOSTART}\"" | |
} | zbx_bulk_sender 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment