root / plugins / virtualization / virtualbox_ram_usage @ 81db94e2
Historique | Voir | Annoter | Télécharger (2,36 ko)
| 1 | 9ed92290 | nagyrobi | #!/bin/bash |
|---|---|---|---|
| 2 | # |
||
| 3 | # evaluate the current ram usage of every vm running on this host |
||
| 4 | # |
||
| 5 | # Date: 2011-09-09 |
||
| 6 | # Author: Gerald Schnabel ger@ldschnabel.de |
||
| 7 | # |
||
| 8 | # Usage: Place in /etc/munin/plugins (or link it there using ln -s) |
||
| 9 | # |
||
| 10 | # This plugin has to run with the same user like the VirtualBox Server rans |
||
| 11 | # Update munin plugin-conf.d/munin-node file with |
||
| 12 | # [virtualbox_ram] |
||
| 13 | # user VIRTUAL_BOX_SERVER_USER |
||
| 14 | # |
||
| 15 | # Parameters understood: |
||
| 16 | # |
||
| 17 | # config (required) |
||
| 18 | # autoconf (optional - used by munin-config) |
||
| 19 | # |
||
| 20 | # Versions |
||
| 21 | # 2013-05-25 robi fix for handling vm names with dots and dashes; scale graph size by the max memory available; display GB on scales and legend |
||
| 22 | # 2011-09-22 ger@ldschnabel.de fix for handling vm names with spaces and setup metric period to get values |
||
| 23 | # 2011-09-09 ger@ldschnabel.de initial version |
||
| 24 | |||
| 25 | # Todo: sort |
||
| 26 | # readarray -t sorted < <(printf '%s\0' "${array[@]}" | sort -z | xargs -0n1)
|
||
| 27 | # see http://stackoverflow.com/questions/7442417/how-to-sort-an-array-in-bash |
||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | if [ "$1" = "autoconf" ]; then |
||
| 32 | echo yes |
||
| 33 | exit 0 |
||
| 34 | fi |
||
| 35 | |||
| 36 | if [ "$1" = "config" ]; then |
||
| 37 | RAMTOT=`free -b | grep Mem | awk '{print $2}'`
|
||
| 38 | echo 'graph_title Memory usage of virtual machines' |
||
| 39 | echo "graph_args --base 1024 -r --lower-limit 0 --upper-limit $RAMTOT --units-exponent 9" |
||
| 40 | echo 'graph_vlabel GB' |
||
| 41 | echo 'graph_info This graph shows the ram usage of every single VM process.' |
||
| 42 | e3899a30 | Gabriele Pohl | echo 'graph_category Virtualization' |
| 43 | 9ed92290 | nagyrobi | echo 'graph_period second' |
| 44 | I=0 |
||
| 45 | vboxmanage list vms | sed -r 's/^\"(.*)\" \{.*\}$/\1/' | while read VM_NAME; do
|
||
| 46 | VM_NAME_PRINT=`echo -e "${VM_NAME}" | sed 's/[^A-Za-z0-9_]/_/g'`
|
||
| 47 | echo "${VM_NAME_PRINT}.label ${VM_NAME}"
|
||
| 48 | echo "${VM_NAME_PRINT}.cdef ${VM_NAME_PRINT},1024,*"
|
||
| 49 | if [ ${I} -eq 0 ]; then
|
||
| 50 | echo "${VM_NAME_PRINT}.draw AREA"
|
||
| 51 | else |
||
| 52 | echo "${VM_NAME_PRINT}.draw STACK"
|
||
| 53 | fi |
||
| 54 | I=$(( I + 1 )) |
||
| 55 | done |
||
| 56 | exit 0 |
||
| 57 | fi |
||
| 58 | |||
| 59 | vboxmanage metrics setup --period 5 --samples 3 |
||
| 60 | sleep 5 |
||
| 61 | |||
| 62 | vboxmanage list vms | sed -r 's/^\"(.*)\" \{.*\}$/\1/' | while read VM_NAME; do
|
||
| 63 | VM_NAME_PRINT=`echo -e "${VM_NAME}" | sed 's/[^A-Za-z0-9_]/_/g'` # s/[.]/_/g;s/[ ]/_/g;s/[-]/_/g
|
||
| 64 | vboxmanage metrics query "${VM_NAME}" RAM/Usage/Used | grep -E "^${VM_NAME}" | sed -r 's/^.* ([0-9]+) kB$/'''${VM_NAME_PRINT}'''.value \1/'
|
||
| 65 | done |
