1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-25 18:38:30 +00:00

Cleanup suggested by maintainer

* family should be auto, not manual
* Combine multiple sed scripts into a single script
* Double quote sh variable dereferences
* Don't use deprecated backquotes
This commit is contained in:
Nye Liu 2016-11-05 14:52:03 -07:00
parent 2d13d2a50d
commit 6cb9ba170f

View file

@ -9,17 +9,17 @@
# Magic markers (optional - used by munin-config and some installation # Magic markers (optional - used by munin-config and some installation
# scripts): # scripts):
# #
#%# family=manual #%# family=auto
#%# capabilities=autoconf suggest #%# capabilities=autoconf suggest
DEVICE=${0##*/tc_} DEVICE=${0##*/tc_}
mytc() { mytc() {
/sbin/tc -s class show dev $1 | tr "\n" "|" | sed "s/ \+/ /g" | sed "s/ |/|/g" | sed "s/| /|/g" | sed "s/||/\n/g" | sed "s/|/ /g" | tr ":" "_" | grep -v -i sfq | sort -n /sbin/tc -s class show dev "$1" | tr "\n" "|" | sed -e "s/ \+/ /g; s/ |/|/g; s/| /|/g; s/||/\n/g; s/|/ /g" | tr ":" "_" | grep -v -i sfq | sort -n
} }
case $1 in case "$1" in
autoconf) autoconf)
if [ -r /proc/net/dev ]; then if [ -r /proc/net/dev ]; then
echo yes echo yes
@ -36,13 +36,11 @@ case $1 in
split($0, a, /: */); split($0, a, /: */);
gsub(/^ +/,"",a[1]); gsub(/^ +/,"",a[1]);
if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev
# egrep '^ *(eth|tap|bond|wlan|ath|ra|sw)[0-9]+:' /proc/net/dev | cut -f1 -d: | sed 's/ //g'
fi fi
exit 0 exit 0
;; ;;
config) config)
echo "graph_order `mytc $DEVICE | awk '{ print $2 "_" $3 }' | tr "\n" " "`" echo "graph_order $(mytc "$DEVICE" | awk '{ print $2 "_" $3 }' | tr "\n" " ")"
echo "graph_title $DEVICE TC traffic" echo "graph_title $DEVICE TC traffic"
echo 'graph_args --base 1000' echo 'graph_args --base 1000'
echo 'graph_vlabel bits per ${graph_period}' echo 'graph_vlabel bits per ${graph_period}'
@ -50,7 +48,7 @@ case $1 in
echo "graph_info This graph shows the TC classes traffic of the $DEVICE network interface. Please note that the traffic is shown in bits per second, not bytes." echo "graph_info This graph shows the TC classes traffic of the $DEVICE network interface. Please note that the traffic is shown in bits per second, not bytes."
# the root(s) # the root(s)
mytc $DEVICE | grep -v " parent " | tr "_" " " | awk '{ mytc "$DEVICE" | grep -v " parent " | tr "_" " " | awk '{
print $2 "_" $3 "_" $4 ".label " $2 "/" $3 ":" $4; print $2 "_" $3 "_" $4 ".label " $2 "/" $3 ":" $4;
print $2 "_" $3 "_" $4 ".type DERIVE"; print $2 "_" $3 "_" $4 ".type DERIVE";
print $2 "_" $3 "_" $4 ".min 0"; print $2 "_" $3 "_" $4 ".min 0";
@ -58,7 +56,7 @@ case $1 in
}' }'
# TODO: only AREASTACK things with no children # TODO: only AREASTACK things with no children
# the child(s) # the child(s)
mytc $DEVICE | grep " parent " | tr "_" " " | awk '{ mytc "$DEVICE" | grep " parent " | tr "_" " " | awk '{
print $2 "_" $3 "_" $4 ".label " $2 "/" $3 ":" $4; print $2 "_" $3 "_" $4 ".label " $2 "/" $3 ":" $4;
print $2 "_" $3 "_" $4 ".type DERIVE"; print $2 "_" $3 "_" $4 ".type DERIVE";
print $2 "_" $3 "_" $4 ".min 0"; print $2 "_" $3 "_" $4 ".min 0";
@ -70,13 +68,13 @@ case $1 in
esac esac
# the root(s) # the root(s)
mytc $DEVICE | grep -v " parent " | awk '{ mytc "$DEVICE" | grep -v " parent " | awk '{
split(substr($0, match($0, /[0-9]+ [Bb]ytes/)), a, " "); split(substr($0, match($0, /[0-9]+ [Bb]ytes/)), a, " ");
print $2 "_" $3 ".value " a[1]; print $2 "_" $3 ".value " a[1];
}' }'
# the child(s) # the child(s)
mytc $DEVICE | grep " parent " | awk '{ mytc "$DEVICE" | grep " parent " | awk '{
split(substr($0, match($0, /[0-9]+ [Bb]ytes/)), a, " "); split(substr($0, match($0, /[0-9]+ [Bb]ytes/)), a, " ");
print $2 "_" $3 ".value " a[1]; print $2 "_" $3 ".value " a[1];
}' }'