1216a7d521000670ca6e5c481b5424050df678b3
[puppet_munin.git] / files / plugins / xen_traffic_all
1 #!/bin/sh
2 # Author: mario manno <projects@manno.name>
3 # Description: measure traffic for all xen hosts
4 #
5 #%# family=auto
6 #%# capabilities=autoconf
7
8 if [ "$1" = "autoconf" ]; then
9     if which xm > /dev/null ; then
10         echo yes
11     else
12         echo "no (xm not found)"
13         exit 1
14     fi
15     if [ -r /proc/net/dev ]; then
16         echo yes
17     else
18         echo "no (/proc/net/dev not found)"
19         exit 1
20     fi
21     exit 0
22 fi
23
24 if [ "$1" = "config" ]; then
25     echo 'graph_title Xen Traffic'
26     echo 'graph_vlabel bits received (-) / sent (+) per ${graph_period}'
27     echo 'graph_args --base 1024 -l 0'
28     echo 'graph_category xen'
29     DOMAINS=$(xm list | awk '{print $1}' | egrep -v "^(Name|Domain-0)")
30     for dom in $DOMAINS; do
31         name=$( echo $dom | sed -e's/-/_/g' )
32         #echo $name"UP.label $name"
33         #echo $name"DOWN.label $name"
34         
35         echo $name'Down.label received'
36         echo $name'Down.type COUNTER'
37         echo $name'Down.graph no'
38         echo "${name}Down.cdef ${name}Down,8,*"
39         echo "${name}Up.label ${name}"
40         echo $name'Up.type COUNTER'
41         echo "${name}Up.negative ${name}Down"
42         echo "${name}Up.cdef ${name}Up,8,*"
43     done
44     exit 0
45 fi
46
47 DOMAINS=$(xm list | awk '{print $1}' | egrep -v "^(Name|Domain-0)")
48 for dom in $DOMAINS; do
49     dev=$( xm network-list $dom |\
50         egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@')
51     name=$( echo $dom | sed -e's/-/_/g' ) 
52     #awk -v name="$name" -v interface="$dev" -F'[: \t]+' \
53     #'{ sub(/^ */,""); if ($1 == interface) \
54     #print name"DOWN.value "$2"\n"name"UP.value "$10; }' /proc/net/dev
55     awk -v name="$name" -v interface="$dev" \
56         'BEGIN { gsub(/\./, "\\.", interface) } \
57         $1 ~ "^" interface ":" {
58             split($0, a, /: */); $0 = a[2]; \
59             print name"Down.value " $1 "\n"name"Up.value " $9 \
60         }' \
61         /proc/net/dev
62 done
63