2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Plugins xen_*: fix shellcheck issues

This commit is contained in:
Lars Kruse 2018-08-01 23:51:11 +02:00
parent 0987cf33a2
commit 4b4a6a01e1
4 changed files with 55 additions and 64 deletions

View File

@ -28,9 +28,9 @@ fi
if [ "$1" = "config" ]; then if [ "$1" = "config" ]; then
if [ ! -e $statefile ]; then if [ ! -e "$statefile" ]; then
touch $statefile touch "$statefile"
fi fi
echo 'graph_title Xen Domain Utilisation' echo 'graph_title Xen Domain Utilisation'
echo 'graph_args --base 1000 -l 0 --upper-limit 100 --rigid' echo 'graph_args --base 1000 -l 0 --upper-limit 100 --rigid'
@ -39,26 +39,24 @@ if [ "$1" = "config" ]; then
echo 'graph_category Virtualization' echo 'graph_category Virtualization'
echo 'graph_info This graph shows how many percent of the CPU time was used by each domain' echo 'graph_info This graph shows how many percent of the CPU time was used by each domain'
xm list | grep -v "^Name .* Time(s)$" | \ xm list | grep -v "^Name .* Time(s)$" | while read -r name domid mem cpu state time console; do
while read name domid mem cpu state time console; do name=$(echo "$name" | sed -e"s/[-.]/_/g")
name=`echo $name | sed -e"s/[-.]/_/g"` TEST=$(grep "^${name}$" "$statefile" | wc -l)
TEST=`less $statefile | grep "^${name}$" | wc -l` if [ "$TEST" -ne 1 ]; then
if [ $TEST -ne 1 ]; then echo "$name" >> "$statefile"
echo "$name" >> $statefile fi
fi done
done
FIRST=1 FIRST=1
cat $statefile | sort | \ sort < "$statefile" | while read -r name; do
while read name; do
echo "$name.label $name" echo "$name.label $name"
echo "$name.type COUNTER" echo "$name.type COUNTER"
if [ $FIRST -eq 1 ]; then if [ "$FIRST" -eq 1 ]; then
echo "$name.draw AREA" echo "$name.draw AREA"
FIRST=0 FIRST=0
else else
echo "$name.draw STACK" echo "$name.draw STACK"
fi fi
echo "$name.min 0" echo "$name.min 0"
echo "$name.max 100" echo "$name.max 100"
echo "$name.info % of the CPU time spent for $name" echo "$name.info % of the CPU time spent for $name"
@ -66,12 +64,10 @@ if [ "$1" = "config" ]; then
exit 0 exit 0
fi fi
xm list | grep -v "^Name .* Time(s)$" | \ # shellcheck disable=SC2034
while read name domid mem cpu state time console; do xm list | grep -v "^Name .* Time(s)$" | while read -r name domid mem cpu state time console; do
name=`echo $name | sed -e "s/[-.]/_/g"` name=$(echo "$name" | sed -e "s/[-.]/_/g")
# only seconds # scale 60s/60s => 100%/60s
time=`echo $time | sed -e "s/\..//"` time=$(echo "$time" | awk '{print ($1 * 100 / 60) }')
# scale 60s/60s => 100%/60s
time=`echo "$time*100/60" | bc`
echo "$name.value $time" echo "$name.value $time"
done done

View File

@ -31,11 +31,10 @@ if [ "$1" = "config" ]; then
echo 'graph_vlabel MB' echo 'graph_vlabel MB'
echo 'graph_category Virtualization' echo 'graph_category Virtualization'
echo 'graph_info This graph shows of many mS wall time where used by a domain' echo 'graph_info This graph shows of many mS wall time where used by a domain'
# xm info | while read name bla value; do echo "$name $value"; done "$XM" info | while read -r name bla value; do
$XM info | while read name bla value; do # total_memory 2047
#total_memory 2047 # free_memory 1476
#free_memory 1476 name=$(echo "$name" | sed -e"s/-/_/")
name=`echo $name | sed -e"s/-/_/"`
if [ "$name" = "total_memory" ]; then if [ "$name" = "total_memory" ]; then
echo "$name.label $name" echo "$name.label $name"
@ -55,13 +54,10 @@ if [ "$1" = "config" ]; then
exit 0 exit 0
fi fi
$XM info | while read name bla value; do # shellcheck disable=SC2034
name=`echo $name | sed -e"s/-/_/"` "$XM" info | while read -r name bla value; do
if [ "$name" = "total_memory" ]; then name=$(echo "$name" | sed -e"s/-/_/")
echo "$name.value $value" if [ "$name" = "total_memory" ] || [ "$name" = "free_memory" ]; then
fi
if [ "$name" = "free_memory" ]; then
echo "$name.value $value" echo "$name.value $value"
fi fi
done done

View File

@ -7,8 +7,8 @@
#%# capabilities=autoconf suggest #%# capabilities=autoconf suggest
DOMAIN=$( basename $0 | sed 's/^xen_traffic_//g' ) DOMAIN=$( basename "$0" | sed 's/^xen_traffic_//g' )
NAME=$( echo $DOMAIN | sed -e's/-/_/g' ) NAME=$( echo "$DOMAIN" | sed -e's/-/_/g' )
if [ "$1" = "autoconf" ]; then if [ "$1" = "autoconf" ]; then
if which xm > /dev/null ; then if which xm > /dev/null ; then
@ -27,12 +27,13 @@ if [ "$1" = "autoconf" ]; then
fi fi
if [ "$1" = "suggest" ]; then if [ "$1" = "suggest" ]; then
xm list | awk '{print $1}' | egrep -v "^(Name|Domain-0)" xm list | awk '{print $1}' | grep -v -E "^(Name|Domain-0)"
exit 0 exit 0
fi fi
if [ "$1" = "config" ]; then if [ "$1" = "config" ]; then
echo "graph_title Xen Traffic for $NAME" echo "graph_title Xen Traffic for $NAME"
# shellcheck disable=SC2016
echo 'graph_vlabel bits in (-) / out (+) per ${graph_period}' echo 'graph_vlabel bits in (-) / out (+) per ${graph_period}'
echo 'graph_args --base 1024 -l 0' echo 'graph_args --base 1024 -l 0'
echo 'graph_category Virtualization' echo 'graph_category Virtualization'
@ -47,13 +48,12 @@ if [ "$1" = "config" ]; then
exit 0 exit 0
fi fi
dev=$( xm network-list $DOMAIN | egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@') dev=$( xm network-list "$DOMAIN" | grep '^[0-9]\+' | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@')
awk -v interface="$dev" \ awk -v interface="$dev" \
'BEGIN { gsub(/\./, "\\.", interface) } \ 'BEGIN { gsub(/\./, "\\.", interface) }
$1 ~ "^" interface ":" { $1 ~ "^" interface ":" {
split($0, a, /: */); $0 = a[2]; \ split($0, a, /: */); $0 = a[2];
print "in.value " $1 "\nout.value " $9 \ print "in.value " $1 "\nout.value " $9;
}' \ }' \
/proc/net/dev /proc/net/dev

View File

@ -27,44 +27,43 @@ fi
if [ "$1" = "config" ]; then if [ "$1" = "config" ]; then
echo 'graph_title Xen Traffic' echo 'graph_title Xen Traffic'
# shellcheck disable=SC2016
echo 'graph_vlabel bits received (-) / sent (+) per ${graph_period}' echo 'graph_vlabel bits received (-) / sent (+) per ${graph_period}'
echo 'graph_args --base 1024 -l 0' echo 'graph_args --base 1024 -l 0'
echo 'graph_category Virtualization' echo 'graph_category Virtualization'
DOMAINS=$(xm list | awk '{print $1}' | egrep -v "^(Name|Domain-0)") DOMAINS=$(xm list | awk '{print $1}' | grep -v -E "^(Name|Domain-0)")
for dom in $DOMAINS; do for dom in $DOMAINS; do
name=$( echo $dom | tr .- __ ) name=$( echo "$dom" | tr .- __ )
#echo $name"UP.label $name" #echo $name"UP.label $name"
#echo $name"DOWN.label $name" #echo $name"DOWN.label $name"
echo $name'Down.label received' echo "${name}Down.label received"
echo $name'Down.type COUNTER' echo "${name}Down.type COUNTER"
echo $name'Down.graph no' echo "${name}Down.graph no"
echo "${name}Down.cdef ${name}Down,8,*" echo "${name}Down.cdef ${name}Down,8,*"
echo "${name}Up.label ${name}" echo "${name}Up.label ${name}"
echo $name'Up.type COUNTER' echo "${name}Up.type COUNTER"
echo "${name}Up.negative ${name}Down" echo "${name}Up.negative ${name}Down"
echo "${name}Up.cdef ${name}Up,8,*" echo "${name}Up.cdef ${name}Up,8,*"
done done
exit 0 exit 0
fi fi
DOMAINS=$(xm list | awk '{print $1}' | egrep -v "^(Name|Domain-0)") DOMAINS=$(xm list | awk '{print $1}' | grep -v -E "^(Name|Domain-0)")
for dom in $DOMAINS; do for dom in $DOMAINS; do
dev=$( xm list $dom --long | awk '/vifname / { print $2 }' | sed 's/)//' ) dev=$( xm list "$dom" --long | awk '/vifname / { print $2 }' | sed 's/)//' )
if [ "$dev" = "" ]; then if [ -z "$dev" ]; then
dev=$( xm network-list $dom |\ dev=$( xm network-list "$dom" | grep '^[0-9]\+' | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@')
egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@') fi
fi name=$( echo "$dom" | tr .- __ )
name=$( echo $dom | tr .- __ )
#awk -v name="$name" -v interface="$dev" -F'[: \t]+' \ #awk -v name="$name" -v interface="$dev" -F'[: \t]+' \
#'{ sub(/^ */,""); if ($1 == interface) \ #'{ sub(/^ */,""); if ($1 == interface) \
#print name"DOWN.value "$2"\n"name"UP.value "$10; }' /proc/net/dev #print name"DOWN.value "$2"\n"name"UP.value "$10; }' /proc/net/dev
awk -v name="$name" -v interface="$dev" \ awk -v name="$name" -v interface="$dev" \
'BEGIN { gsub(/\./, "\\.", interface) } \ 'BEGIN { gsub(/\./, "\\.", interface) }
$1 ~ "^" interface ":" { $1 ~ "^" interface ":" {
split($0, a, /: */); $0 = a[2]; \ split($0, a, /: */); $0 = a[2];
print name"Down.value " $1 "\n"name"Up.value " $9 \ print name"Down.value " $1 "\n"name"Up.value " $9;
}' \ }' \
/proc/net/dev /proc/net/dev
done done