blob: c5bbfbb7b857ecd6446bb31120e422a649eb9bbd (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#!/bin/sh
# Author: mario manno <projects@manno.name>
# Description: measure traffic for all xen hosts
#
# 16.07.2008: improved the Plugin by Puzzle ITC to
# enable the traffic monitoring for domains
# with more than 1 one interface
# If there is more than one device, the domainname
# will get the vif name appended.
#
#%# family=auto
#%# capabilities=autoconf
# we cache xm list for 5 min for perfomance reasons
((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE '^\/var\/lib\/munin\/plugin-state\/xm_list\.state$') && \
[ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || \
/usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state
if [ "$1" = "autoconf" ]; then
if which xm > /dev/null ; then
echo yes
else
echo "no (xm not found)"
exit 1
fi
if [ -r /proc/net/dev ]; then
echo yes
else
echo "no (/proc/net/dev not found)"
exit 1
fi
exit 0
fi
if [ "$1" = "config" ]; then
echo 'graph_title Xen Traffic'
echo 'graph_vlabel bits received (-) / sent (+) per ${graph_period}'
echo 'graph_args --base 1024 -l 0'
echo 'graph_category xen'
DOMAINS=$(cat /var/lib/munin/plugin-state/xm_list.state | awk '{print $1}' | egrep -v "^(Name|Domain-0)")
for dom in $DOMAINS; do
# we update network devices only twice an hour
((find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin -30 > /dev/null 2>&1) && \
[ `cat /var/lib/munin/plugin-state/xm_net_$dom.state | wc -l` -gt 0 ]) || \
(/usr/sbin/xm network-list $dom |\
egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state)
devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state)
real_name=$( echo $dom | sed -e's/-/_/g' )
name=$real_name
for dev in $devs; do
if [ ${#devs} -gt 1 ]; then
name=$real_name"_"`echo $dev | sed 's/\./\_/'`
fi
echo $name'Down.label received'
echo $name'Down.type COUNTER'
echo $name'Down.graph no'
echo "${name}Down.cdef ${name}Down,8,*"
echo "${name}Up.label ${name}"
echo $name'Up.type COUNTER'
echo "${name}Up.negative ${name}Down"
echo "${name}Up.cdef ${name}Up,8,*"
done
done
exit 0
fi
DOMAINS=$(cat /var/lib/munin/plugin-state/xm_list.state | awk '{print $1}' | egrep -v "^(Name|Domain-0)")
for dom in $DOMAINS; do
# we update network devices only twice an hour
((find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin -30 > /dev/null 2>&1) && \
[ `cat /var/lib/munin/plugin-state/xm_net_$dom.state | wc -l` -gt 0 ]) || \
(/usr/sbin/xm network-list $dom |\
egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state)
devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state)
real_name=$( echo $dom | sed -e's/-/_/g' )
name=$real_name
for dev in $devs; do
if [ ${#devs} -gt 1 ]; then
name=$real_name"_"`echo $dev | sed 's/\./\_/'`
fi
awk -v name="$name" -v interface="$dev" \
'BEGIN { gsub(/\./, "\\.", interface) } \
$1 ~ "^" interface ":" {
split($0, a, /: */); $0 = a[2]; \
print name"Down.value " $1 "\n"name"Up.value " $9 \
}' \
/proc/net/dev
done
done
|