root / plugins / virtualization / virtualbox_cpu_user @ aa59ca8b
Historique | Voir | Annoter | Télécharger (1,88 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 3 |
# evaluate the current cpu usage of every vm running on this host |
| 4 |
# separated by time spend in user mode and kernel mode |
| 5 |
# |
| 6 |
# Date: 2011-09-09 |
| 7 |
# Author: Gerald Schnabel ger@ldschnabel.de |
| 8 |
# |
| 9 |
# Usage: Place in /etc/munin/plugins (or link it there using ln -s) |
| 10 |
# |
| 11 |
# This plugin has to run with the same user like the VirtualBox Server rans |
| 12 |
# Update munin plugin-conf.d/munin-node file with |
| 13 |
# [virtualbox_cpu] |
| 14 |
# user VIRTUAL_BOX_SERVER_USER |
| 15 |
# |
| 16 |
# Parameters understood: |
| 17 |
# |
| 18 |
# config (required) |
| 19 |
# autoconf (optional - used by munin-config) |
| 20 |
# |
| 21 |
# Versions |
| 22 |
# 2013-05-25 robi fix for handling vm names with dots and dashes; separate Kernel and User CPU graphs |
| 23 |
# 2011-09-22 ger@ldschnabel.de fix for handling vm names with spaces and setup metric period to get values |
| 24 |
# 2011-09-09 ger@ldschnabel.de initial version |
| 25 |
|
| 26 |
|
| 27 |
if [ "$1" = "autoconf" ]; then |
| 28 |
echo yes |
| 29 |
exit 0 |
| 30 |
fi |
| 31 |
|
| 32 |
if [ "$1" = "config" ]; then |
| 33 |
echo 'graph_title User CPU used by virtual machines' |
| 34 |
echo "graph_args --base 1000 -r --lower-limit 0 " |
| 35 |
echo 'graph_vlabel %' |
| 36 |
echo 'graph_scale no' |
| 37 |
echo 'graph_info This graph shows the percentage of processor time spent in user mode by the every single VM process.' |
| 38 |
echo 'graph_category virtualbox' |
| 39 |
echo 'graph_period second' |
| 40 |
vboxmanage list vms | sed -r 's/^\"(.*)\" \{.*\}$/\1/' | while read VM_NAME; do
|
| 41 |
VM_NAME_PRINT=`echo -e "${VM_NAME}" | sed 's/[^A-Za-z0-9_]/_/g'`
|
| 42 |
echo "${VM_NAME_PRINT}_user.label ${VM_NAME}"
|
| 43 |
done |
| 44 |
exit 0 |
| 45 |
fi |
| 46 |
|
| 47 |
vboxmanage metrics setup --period 5 --samples 3 |
| 48 |
sleep 5 |
| 49 |
|
| 50 |
vboxmanage list vms | sed -r 's/^\"(.*)\" \{.*\}$/\1/' | while read VM_NAME; do
|
| 51 |
VM_NAME_PRINT=`echo -e "${VM_NAME}" | sed 's/[^A-Za-z0-9_]/_/g'`
|
| 52 |
vboxmanage metrics query "${VM_NAME}" CPU/Load/User | grep -E "^${VM_NAME}" | sed -r 's/^.*([0-9]+\.[0-9]+)%/'''${VM_NAME_PRINT}'''_user.value \1/'
|
| 53 |
done |
| 54 |
|
