summaryrefslogtreecommitdiff
path: root/munin/vm_du_
blob: 5564c4428325a26b2e327b1829a7ac23344c5482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# -*- sh -*-

MUNIN_LIBDIR=${MUNIN_LIBDIR:-/usr/share/munin}
. $MUNIN_LIBDIR/plugins/plugin.sh

BASE=/srv/vmstore

VM=${0##*vm_du_}
#VM=${VM//_/.}

case $1 in
    autoconf)
        if [[ -d "$BASE" ]]; then
            echo yes
            exit 0
        else
            echo "no ($BASE not found)"
            exit 0
        fi
        ;;
    suggest)
        if [[ -d "$BASE" ]]; then
            find "$BASE" -mindepth 1 -maxdepth 1 -type d -a ! -name lost+found -printf '%f\n' # | tr . _
        fi
        exit 0
        ;;
    config)
        echo "graph_title disk usage VM $VM"
        echo 'graph_args --base 1024 --lower-limit 0'
        echo 'graph_vlabel bytes'
        echo 'graph_category disk'
        echo 'graph_total Total'

        find "$BASE/$VM" -mindepth 1 -maxdepth 1 -type f |
        while read fn; do
            label="${fn##*/}"
            label=${label//./_}
            name=${label//-/_}
            echo "$name.label $label"
            echo "$name.cdef $name,1024,*"
        done
        exit 0
        ;;
esac

find "$BASE/$VM" -mindepth 1 -maxdepth 1 -type f -printf '%f %k\n' |
while read fn du; do
  fn=${fn//[.-]/_}
  echo "$fn.value $du"
done