#!/bin/bash
# Pandora FMS Agent plugin for VirtualBOX Monitoring
# This plugin should be executed with the permissions of the running VBox server
# (Usually not root).
for vm in `VBoxManage list vms | grep "\"" | awk '{ print $1 }' | tr -d "\""`
do
vm_usercpu=`VBoxManage metrics query $vm CPU/Load/User:avg | tail -1 | awk '{ print $3 }' | tr -d "%"`
vm_kernelcpu=`VBoxManage metrics query $vm CPU/Load/Kernel:avg | tail -1 | awk '{ print $3 }' | tr -d "%"`
vm_ram=`VBoxManage metrics query $vm RAM/Usage/Used:avg | tail -1 | awk '{ print $3 }' | tr -d "%"`
vm_status=`VBoxManage showvminfo $vm | grep State | grep "running" | wc -l`
if [ $vm_status == 0 ]
then
vm_usercpu=0
vm_kernelcpu=0
vm_ram=0
fi
echo ""
echo "VM.$vm.STATE"
echo "generic_proc"
echo "$vm_status"
echo ""
echo ""
echo "VM.$vm.CPU_USER"
echo "generic_data"
echo "$vm_usercpu"
echo ""
echo ""
echo "VM.$vm.CPU_KERNEL"
echo "generic_data"
echo "$vm_kernelcpu"
echo ""
echo ""
echo "VM.$vm.RAM"
echo "generic_data"
echo "$vm_ram"
echo ""
done