Outils pour utilisateurs

Outils du site


user:pascal_cabaud:blog:virtualbox_et_munin

VirtualBox et Munin

Plugin pour voir l'usage du CPU :

#!/bin/bash
 
dir="/data/images"
export VBOX_USER_HOME="/data/vm-conf"
export PATH=/sbin:/bin:/usr/bin:/usr/sbin
 
let i=0
for vm in $(VBoxManage list vms|sed -e '/^"/!d; s/^"//g; s/"\ .*//g;'); do
        vm_state=$(lsof |grep $dir/$vm.vdi|awk '{ print $2 }')
        if [ X$vm_state != "X" ]; then
                VMX[$i]=$vm
                let i=$i+1
        fi
done
 
if [ "$1" = "autoconf" ]; then
        echo yes
        exit 0
fi
 
if [ "$1" = "config" ]; then
        echo 'graph_title VirtualBox CPU-Load'
        echo 'graph_category VirtualBox'
 
        let i=0
        while [ $i -lt ${#VMX[*]} ]
        do
                NAME=${VMX[i]}
                echo $NAME.label $NAME|sed -e 's/-/_/g;'
                i=`expr $i + 1`
        done
        exit 0
fi
 
i=0
while [ $i -lt ${#VMX[*]} ]
do
        NAME=${VMX[i]}
        PID=$(lsof |grep $dir/$NAME.vdi|awk '{ print $2 }')
        CPU=$(ps -o %cpu -p $PID --no-header | sed -e 's/\.[0-9]//g;')
        echo $NAME".value" $CPU|sed -e 's/-/_/g;'
        i=`expr $i + 1`
done

Plugin pour voir la consommation mémoire :

#!/bin/bash
 
dir="/data/images"
export VBOX_USER_HOME="/data/vm-conf"
export PATH=/sbin:/bin:/usr/bin:/usr/sbin
 
let i=0
for vm in $(VBoxManage list vms|sed -e '/^"/!d; s/^"//g; s/"\ .*//g;'); do
        vm_state=$(lsof |grep $dir/$vm.vdi|awk '{ print $2 }')
        if [ X$vm_state != "X" ]; then
                VMX[$i]=$vm
                let i=$i+1
        fi
done
mem_total=$(head -1 /proc/meminfo|awk '{ print $2 }')
 
if [ "$1" = "autoconf" ]; then
        echo yes
        exit 0
fi
 
if [ "$1" = "config" ]; then
        echo 'graph_title VirtualBox Memory Usage'
        echo "graph_args --base 1024 --upper-limit $mem_total -l 0"
        echo 'graph_category VirtualBox'
 
        let i=0
        while [ $i -lt ${#VMX[*]} ]
        do
                NAME=${VMX[i]}
                echo $NAME.label $NAME|sed -e 's/-/_/g;'
                i=`expr $i + 1`
        done
        exit 0
fi
 
i=0
while [ $i -lt ${#VMX[*]} ]
do
        NAME=${VMX[i]}
        PID=$(lsof |grep $dir/$NAME.vdi|awk '{ print $2 }')
        MEM=`ps -o vsz -p $PID --no-header`
        echo $NAME."value" $MEM|sed -e 's/-/_/g;'
        i=`expr $i + 1`
done
user/pascal_cabaud/blog/virtualbox_et_munin.txt · Dernière modification: 2009/07/13 19:27 par Pascal Cabaud