2008-02-02 15:55:17 +01:00
|
|
|
#!/bin/sh
|
|
|
|
# Author: mario manno <projects@manno.name>
|
|
|
|
# Description: measure traffic for all xen hosts
|
|
|
|
#
|
2011-04-20 20:10:17 +02:00
|
|
|
# Changelog:
|
|
|
|
# Also handle domUs with named network interfaces.
|
|
|
|
# Ward Vandewege (ward@gnu.org), 2011-04-20
|
|
|
|
#
|
2008-02-02 15:55:17 +01:00
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
if which xm > /dev/null ; then
|
2018-08-01 23:51:50 +02:00
|
|
|
if [ -r /proc/net/dev ]; then
|
|
|
|
echo yes
|
|
|
|
else
|
|
|
|
echo "no (/proc/net/dev not found)"
|
|
|
|
fi
|
2008-02-02 15:55:17 +01:00
|
|
|
else
|
|
|
|
echo "no (xm not found)"
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
echo 'graph_title Xen Traffic'
|
2018-08-01 23:51:11 +02:00
|
|
|
# shellcheck disable=SC2016
|
2008-02-02 15:55:17 +01:00
|
|
|
echo 'graph_vlabel bits received (-) / sent (+) per ${graph_period}'
|
|
|
|
echo 'graph_args --base 1024 -l 0'
|
2014-09-06 22:28:53 +02:00
|
|
|
echo 'graph_category Virtualization'
|
2018-08-01 23:51:11 +02:00
|
|
|
DOMAINS=$(xm list | awk '{print $1}' | grep -v -E "^(Name|Domain-0)")
|
2008-02-02 15:55:17 +01:00
|
|
|
for dom in $DOMAINS; do
|
2018-08-01 23:51:11 +02:00
|
|
|
name=$( echo "$dom" | tr .- __ )
|
2008-02-02 15:55:17 +01:00
|
|
|
#echo $name"UP.label $name"
|
|
|
|
#echo $name"DOWN.label $name"
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2018-08-01 23:51:11 +02:00
|
|
|
echo "${name}Down.label received"
|
|
|
|
echo "${name}Down.type COUNTER"
|
|
|
|
echo "${name}Down.graph no"
|
2008-02-02 15:55:17 +01:00
|
|
|
echo "${name}Down.cdef ${name}Down,8,*"
|
|
|
|
echo "${name}Up.label ${name}"
|
2018-08-01 23:51:11 +02:00
|
|
|
echo "${name}Up.type COUNTER"
|
2008-02-02 15:55:17 +01:00
|
|
|
echo "${name}Up.negative ${name}Down"
|
|
|
|
echo "${name}Up.cdef ${name}Up,8,*"
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-08-01 23:51:11 +02:00
|
|
|
DOMAINS=$(xm list | awk '{print $1}' | grep -v -E "^(Name|Domain-0)")
|
2008-02-02 15:55:17 +01:00
|
|
|
for dom in $DOMAINS; do
|
2018-08-01 23:51:11 +02:00
|
|
|
dev=$( xm list "$dom" --long | awk '/vifname / { print $2 }' | sed 's/)//' )
|
|
|
|
if [ -z "$dev" ]; then
|
|
|
|
dev=$( xm network-list "$dom" | grep '^[0-9]\+' | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@')
|
|
|
|
fi
|
|
|
|
name=$( echo "$dom" | tr .- __ )
|
2008-02-02 15:55:17 +01:00
|
|
|
#awk -v name="$name" -v interface="$dev" -F'[: \t]+' \
|
|
|
|
#'{ sub(/^ */,""); if ($1 == interface) \
|
|
|
|
#print name"DOWN.value "$2"\n"name"UP.value "$10; }' /proc/net/dev
|
|
|
|
awk -v name="$name" -v interface="$dev" \
|
2018-08-01 23:51:11 +02:00
|
|
|
'BEGIN { gsub(/\./, "\\.", interface) }
|
2008-02-02 15:55:17 +01:00
|
|
|
$1 ~ "^" interface ":" {
|
2018-08-01 23:51:11 +02:00
|
|
|
split($0, a, /: */); $0 = a[2];
|
|
|
|
print name"Down.value " $1 "\n"name"Up.value " $9;
|
2008-02-02 15:55:17 +01:00
|
|
|
}' \
|
|
|
|
/proc/net/dev
|
|
|
|
done
|