Révision 41fedbb2
Use /bin/bash for bash script, and save with UNIX line breaks
| plugins/network/hfsc_sep | ||
|---|---|---|
| 1 |
#!/bin/sh |
|
| 2 |
# |
|
| 3 |
# Munin plugin for HFSC Traffic Shaping Statistics UP/DOWN |
|
| 4 |
# |
|
| 5 |
# It shows the download and upload statistic graph of a used net bandwidth per a user. |
|
| 6 |
# |
|
| 7 |
# This plugin was tailored to the HFSC solution |
|
| 8 |
# presented at http://www.elessar.one.pl/article_kernel2.6.php |
|
| 9 |
# |
|
| 10 |
# You can find the plugin description and the installation notes here: |
|
| 11 |
# http://www.elessar.one.pl/article_munin.php |
|
| 12 |
# |
|
| 13 |
### |
|
| 14 |
# Written by Rafal Rajs |
|
| 15 |
# Date: 2007/06/19 |
|
| 16 |
# Email: elessar1@poczta.wp.pl |
|
| 17 |
# WWW: http://www.elessar.one.pl |
|
| 18 |
### |
|
| 19 |
|
|
| 20 |
# path to the file with global defs |
|
| 21 |
. /etc/scripts/globals |
|
| 22 |
|
|
| 23 |
# imported from HFSC script |
|
| 24 |
# set class numbers |
|
| 25 |
|
|
| 26 |
N_CLASS_D_1=70 |
|
| 27 |
N_CLASS_D_2=100 |
|
| 28 |
N_CLASS_U_1=130 |
|
| 29 |
N_CLASS_U_2=160 |
|
| 30 |
SH_TMP="/etc/scripts/tmp1.txt" |
|
| 31 |
|
|
| 32 |
if [ "$1" = "config" ]; then |
|
| 33 |
|
|
| 34 |
echo "graph_title HFSC Traffic Shaping Stats - UP/DOWN" |
|
| 35 |
echo 'graph_vlabel bytes DOWN(-)/UP(+) per ${graph_period}'
|
|
| 36 |
echo 'graph_width 450' |
|
| 37 |
echo 'graph_category network' |
|
| 38 |
|
|
| 39 |
j=1 |
|
| 40 |
|
|
| 41 |
while [ $j -le $L_USERS ] |
|
| 42 |
do |
|
| 43 |
echo "${USERNAMES[${j}]}_down.label ${USERNAMES[${j}]}"
|
|
| 44 |
echo "${USERNAMES[${j}]}_down.type COUNTER"
|
|
| 45 |
echo "${USERNAMES[${j}]}_down.graph no"
|
|
| 46 |
|
|
| 47 |
if [ $j == 1 ]; then |
|
| 48 |
echo "${USERNAMES[${j}]}_down.draw AREA"
|
|
| 49 |
else |
|
| 50 |
echo "${USERNAMES[${j}]}_down.draw STACK"
|
|
| 51 |
fi; |
|
| 52 |
|
|
| 53 |
echo "${USERNAMES[${j}]}_down.info Stats for ${USERNAMES[${j}]} - ${USER_IP[${j}]}"
|
|
| 54 |
echo "${USERNAMES[${j}]}_down.min 0"
|
|
| 55 |
echo "${USERNAMES[${j}]}_down.max 130000"
|
|
| 56 |
|
|
| 57 |
echo "${USERNAMES[${j}]}_up.label ${USERNAMES[${j}]}"
|
|
| 58 |
echo "${USERNAMES[${j}]}_up.type COUNTER"
|
|
| 59 |
echo "${USERNAMES[${j}]}_up.negative ${USERNAMES[${j}]}_down"
|
|
| 60 |
|
|
| 61 |
if [ $j == 1 ]; then |
|
| 62 |
echo "${USERNAMES[${j}]}_up.draw AREA"
|
|
| 63 |
else |
|
| 64 |
echo "${USERNAMES[${j}]}_up.draw STACK"
|
|
| 65 |
fi; |
|
| 66 |
|
|
| 67 |
echo "${USERNAMES[${j}]}_up.info Stats for ${USERNAMES[${j}]} - ${USER_IP[${j}]}"
|
|
| 68 |
echo "${USERNAMES[${j}]}_up.min 0"
|
|
| 69 |
echo "${USERNAMES[${j}]}_up.max 30000"
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
j=$[$j+1] |
|
| 73 |
|
|
| 74 |
done; |
|
| 75 |
|
|
| 76 |
#customized colours |
|
| 77 |
echo 'Serwer_down.colour 000000' |
|
| 78 |
echo 'Serwer_up.colour 000000' |
|
| 79 |
|
|
| 80 |
exit 0 |
|
| 81 |
|
|
| 82 |
fi; |
|
| 83 |
|
|
| 84 |
#### DOWNLOAD |
|
| 85 |
|
|
| 86 |
temp1=`/sbin/tc -s class show dev imq0 > $SH_TMP` |
|
| 87 |
|
|
| 88 |
while read line |
|
| 89 |
do |
|
| 90 |
test_hfsc=`echo $line | grep "hfsc"` |
|
| 91 |
|
|
| 92 |
j=1 |
|
| 93 |
|
|
| 94 |
while [ $j -le $L_USERS ] |
|
| 95 |
do |
|
| 96 |
case $test_hfsc in |
|
| 97 |
|
|
| 98 |
*hfsc[\ ]1:$[$N_CLASS_D_1+$j]*) |
|
| 99 |
# check N_CLASS_D_1 stats for every user |
|
| 100 |
read line |
|
| 101 |
temp1=`echo $line | awk '{ print $2; }'`
|
|
| 102 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
|
| 103 |
# echo "N_CLASS_D_1="$temp1 |
|
| 104 |
# echo "N_CLASS_D_1_SUM "$j" ="${STAT_USER[$j]}
|
|
| 105 |
;; |
|
| 106 |
*hfsc[\ ]1:$[$N_CLASS_D_2+$j]*) |
|
| 107 |
# check N_CLASS_D_2 stats for every user |
|
| 108 |
read line |
|
| 109 |
temp1=`echo $line | awk '{ print $2; }'`
|
|
| 110 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
|
| 111 |
# echo "N_CLASS_D_2="$temp1 |
|
| 112 |
# echo "N_CLASS_D_2_SUM "$j" ="${STAT_USER[$j]}
|
|
| 113 |
;; |
|
| 114 |
esac |
|
| 115 |
|
|
| 116 |
j=$[$j+1] |
|
| 117 |
|
|
| 118 |
done; |
|
| 119 |
|
|
| 120 |
done < $SH_TMP |
|
| 121 |
|
|
| 122 |
|
|
| 123 |
#### |
|
| 124 |
|
|
| 125 |
j=1 |
|
| 126 |
while [ $j -le $L_USERS ] |
|
| 127 |
do |
|
| 128 |
echo ${USERNAMES[${j}]}"_down.value "${STAT_USER[$j]}
|
|
| 129 |
j=$[$j+1] |
|
| 130 |
done; |
|
| 131 |
|
|
| 132 |
#reset values |
|
| 133 |
|
|
| 134 |
j=1 |
|
| 135 |
while [ $j -le $L_USERS ] |
|
| 136 |
do |
|
| 137 |
STAT_USER[$j]=0 |
|
| 138 |
j=$[$j+1] |
|
| 139 |
done; |
|
| 140 |
|
|
| 141 |
#### UPLOAD |
|
| 142 |
|
|
| 143 |
temp1=`/sbin/tc -s class show dev imq1 > $SH_TMP` |
|
| 144 |
|
|
| 145 |
while read line |
|
| 146 |
do |
|
| 147 |
test_hfsc=`echo $line | grep "hfsc"` |
|
| 148 |
|
|
| 149 |
j=1 |
|
| 150 |
|
|
| 151 |
while [ $j -le $L_USERS ] |
|
| 152 |
do |
|
| 153 |
case $test_hfsc in |
|
| 154 |
|
|
| 155 |
*hfsc[\ ]1:$[$N_CLASS_U_1+$j]*) |
|
| 156 |
# check N_CLASS_U_1 stats for every user |
|
| 157 |
read line |
|
| 158 |
temp1=`echo $line | awk '{ print $2; }'`
|
|
| 159 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
|
| 160 |
# echo "N_CLASS_U_1="$temp1 |
|
| 161 |
# echo "N_CLASS_U_1_SUM "$j" ="${STAT_USER[$j]}
|
|
| 162 |
;; |
|
| 163 |
*hfsc[\ ]1:$[$N_CLASS_U_2+$j]*) |
|
| 164 |
# check N_CLASS_U_2 stats for every user |
|
| 165 |
read line |
|
| 166 |
temp1=`echo $line | awk '{ print $2; }'`
|
|
| 167 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
|
| 168 |
# echo "N_CLASS_U_2="$temp1 |
|
| 169 |
# echo "N_CLASS_U_2_SUM "$j" ="${STAT_USER[$j]}
|
|
| 170 |
;; |
|
| 171 |
esac |
|
| 172 |
|
|
| 173 |
j=$[$j+1] |
|
| 174 |
|
|
| 175 |
done; |
|
| 176 |
|
|
| 177 |
done < $SH_TMP |
|
| 178 |
|
|
| 179 |
j=1 |
|
| 180 |
while [ $j -le $L_USERS ] |
|
| 181 |
do |
|
| 182 |
echo ${USERNAMES[${j}]}"_up.value "${STAT_USER[$j]}
|
|
| 183 |
j=$[$j+1] |
|
| 184 |
done; |
|
| 185 |
|
|
| 186 |
|
|
| 187 |
## clean temp file |
|
| 188 |
temp1=`echo "" > $SH_TMP` |
|
| 189 |
|
|
| 1 |
#!/bin/bash |
|
| 2 |
# |
|
| 3 |
# Munin plugin for HFSC Traffic Shaping Statistics UP/DOWN |
|
| 4 |
# |
|
| 5 |
# It shows the download and upload statistic graph of a used net bandwidth per a user. |
|
| 6 |
# |
|
| 7 |
# This plugin was tailored to the HFSC solution |
|
| 8 |
# presented at http://www.elessar.one.pl/article_kernel2.6.php |
|
| 9 |
# |
|
| 10 |
# You can find the plugin description and the installation notes here: |
|
| 11 |
# http://www.elessar.one.pl/article_munin.php |
|
| 12 |
# |
|
| 13 |
### |
|
| 14 |
# Written by Rafal Rajs |
|
| 15 |
# Date: 2007/06/19 |
|
| 16 |
# Email: elessar1@poczta.wp.pl |
|
| 17 |
# WWW: http://www.elessar.one.pl |
|
| 18 |
### |
|
| 19 |
|
|
| 20 |
# path to the file with global defs |
|
| 21 |
. /etc/scripts/globals |
|
| 22 |
|
|
| 23 |
# imported from HFSC script |
|
| 24 |
# set class numbers |
|
| 25 |
|
|
| 26 |
N_CLASS_D_1=70 |
|
| 27 |
N_CLASS_D_2=100 |
|
| 28 |
N_CLASS_U_1=130 |
|
| 29 |
N_CLASS_U_2=160 |
|
| 30 |
SH_TMP="/etc/scripts/tmp1.txt" |
|
| 31 |
|
|
| 32 |
if [ "$1" = "config" ]; then |
|
| 33 |
|
|
| 34 |
echo "graph_title HFSC Traffic Shaping Stats - UP/DOWN" |
|
| 35 |
echo 'graph_vlabel bytes DOWN(-)/UP(+) per ${graph_period}'
|
|
| 36 |
echo 'graph_width 450' |
|
| 37 |
echo 'graph_category network' |
|
| 38 |
|
|
| 39 |
j=1 |
|
| 40 |
|
|
| 41 |
while [ $j -le $L_USERS ] |
|
| 42 |
do |
|
| 43 |
echo "${USERNAMES[${j}]}_down.label ${USERNAMES[${j}]}"
|
|
| 44 |
echo "${USERNAMES[${j}]}_down.type COUNTER"
|
|
| 45 |
echo "${USERNAMES[${j}]}_down.graph no"
|
|
| 46 |
|
|
| 47 |
if [ $j == 1 ]; then |
|
| 48 |
echo "${USERNAMES[${j}]}_down.draw AREA"
|
|
| 49 |
else |
|
| 50 |
echo "${USERNAMES[${j}]}_down.draw STACK"
|
|
| 51 |
fi; |
|
| 52 |
|
|
| 53 |
echo "${USERNAMES[${j}]}_down.info Stats for ${USERNAMES[${j}]} - ${USER_IP[${j}]}"
|
|
| 54 |
echo "${USERNAMES[${j}]}_down.min 0"
|
|
| 55 |
echo "${USERNAMES[${j}]}_down.max 130000"
|
|
| 56 |
|
|
| 57 |
echo "${USERNAMES[${j}]}_up.label ${USERNAMES[${j}]}"
|
|
| 58 |
echo "${USERNAMES[${j}]}_up.type COUNTER"
|
|
| 59 |
echo "${USERNAMES[${j}]}_up.negative ${USERNAMES[${j}]}_down"
|
|
| 60 |
|
|
| 61 |
if [ $j == 1 ]; then |
|
| 62 |
echo "${USERNAMES[${j}]}_up.draw AREA"
|
|
| 63 |
else |
|
| 64 |
echo "${USERNAMES[${j}]}_up.draw STACK"
|
|
| 65 |
fi; |
|
| 66 |
|
|
| 67 |
echo "${USERNAMES[${j}]}_up.info Stats for ${USERNAMES[${j}]} - ${USER_IP[${j}]}"
|
|
| 68 |
echo "${USERNAMES[${j}]}_up.min 0"
|
|
| 69 |
echo "${USERNAMES[${j}]}_up.max 30000"
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
j=$[$j+1] |
|
| 73 |
|
|
| 74 |
done; |
|
| 75 |
|
|
| 76 |
#customized colours |
|
| 77 |
echo 'Serwer_down.colour 000000' |
|
| 78 |
echo 'Serwer_up.colour 000000' |
|
| 79 |
|
|
| 80 |
exit 0 |
|
| 81 |
|
|
| 82 |
fi; |
|
| 83 |
|
|
| 84 |
#### DOWNLOAD |
|
| 85 |
|
|
| 86 |
temp1=`/sbin/tc -s class show dev imq0 > $SH_TMP` |
|
| 87 |
|
|
| 88 |
while read line |
|
| 89 |
do |
|
| 90 |
test_hfsc=`echo $line | grep "hfsc"` |
|
| 91 |
|
|
| 92 |
j=1 |
|
| 93 |
|
|
| 94 |
while [ $j -le $L_USERS ] |
|
| 95 |
do |
|
| 96 |
case $test_hfsc in |
|
| 97 |
|
|
| 98 |
*hfsc[\ ]1:$[$N_CLASS_D_1+$j]*) |
|
| 99 |
# check N_CLASS_D_1 stats for every user |
|
| 100 |
read line |
|
| 101 |
temp1=`echo $line | awk '{ print $2; }'`
|
|
| 102 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
|
| 103 |
# echo "N_CLASS_D_1="$temp1 |
|
| 104 |
# echo "N_CLASS_D_1_SUM "$j" ="${STAT_USER[$j]}
|
|
| 105 |
;; |
|
| 106 |
*hfsc[\ ]1:$[$N_CLASS_D_2+$j]*) |
|
| 107 |
# check N_CLASS_D_2 stats for every user |
|
| 108 |
read line |
|
| 109 |
temp1=`echo $line | awk '{ print $2; }'`
|
|
| 110 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
|
| 111 |
# echo "N_CLASS_D_2="$temp1 |
|
| 112 |
# echo "N_CLASS_D_2_SUM "$j" ="${STAT_USER[$j]}
|
|
| 113 |
;; |
|
| 114 |
esac |
|
| 115 |
|
|
| 116 |
j=$[$j+1] |
|
| 117 |
|
|
| 118 |
done; |
|
| 119 |
|
|
| 120 |
done < $SH_TMP |
|
| 121 |
|
|
| 122 |
|
|
| 123 |
#### |
|
| 124 |
|
|
| 125 |
j=1 |
|
| 126 |
while [ $j -le $L_USERS ] |
|
| 127 |
do |
|
| 128 |
echo ${USERNAMES[${j}]}"_down.value "${STAT_USER[$j]}
|
|
| 129 |
j=$[$j+1] |
|
| 130 |
done; |
|
| 131 |
|
|
| 132 |
#reset values |
|
| 133 |
|
|
| 134 |
j=1 |
|
| 135 |
while [ $j -le $L_USERS ] |
|
| 136 |
do |
|
| 137 |
STAT_USER[$j]=0 |
|
| 138 |
j=$[$j+1] |
|
| 139 |
done; |
|
| 140 |
|
|
| 141 |
#### UPLOAD |
|
| 142 |
|
|
| 143 |
temp1=`/sbin/tc -s class show dev imq1 > $SH_TMP` |
|
| 144 |
|
|
| 145 |
while read line |
|
| 146 |
do |
|
| 147 |
test_hfsc=`echo $line | grep "hfsc"` |
|
| 148 |
|
|
| 149 |
j=1 |
|
| 150 |
|
|
| 151 |
while [ $j -le $L_USERS ] |
|
| 152 |
do |
|
| 153 |
case $test_hfsc in |
|
| 154 |
|
|
| 155 |
*hfsc[\ ]1:$[$N_CLASS_U_1+$j]*) |
|
| 156 |
# check N_CLASS_U_1 stats for every user |
|
| 157 |
read line |
|
| 158 |
temp1=`echo $line | awk '{ print $2; }'`
|
|
| 159 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
|
| 160 |
# echo "N_CLASS_U_1="$temp1 |
|
| 161 |
# echo "N_CLASS_U_1_SUM "$j" ="${STAT_USER[$j]}
|
|
| 162 |
;; |
|
| 163 |
*hfsc[\ ]1:$[$N_CLASS_U_2+$j]*) |
|
| 164 |
# check N_CLASS_U_2 stats for every user |
|
| 165 |
read line |
|
| 166 |
temp1=`echo $line | awk '{ print $2; }'`
|
|
| 167 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
|
| 168 |
# echo "N_CLASS_U_2="$temp1 |
|
| 169 |
# echo "N_CLASS_U_2_SUM "$j" ="${STAT_USER[$j]}
|
|
| 170 |
;; |
|
| 171 |
esac |
|
| 172 |
|
|
| 173 |
j=$[$j+1] |
|
| 174 |
|
|
| 175 |
done; |
|
| 176 |
|
|
| 177 |
done < $SH_TMP |
|
| 178 |
|
|
| 179 |
j=1 |
|
| 180 |
while [ $j -le $L_USERS ] |
|
| 181 |
do |
|
| 182 |
echo ${USERNAMES[${j}]}"_up.value "${STAT_USER[$j]}
|
|
| 183 |
j=$[$j+1] |
|
| 184 |
done; |
|
| 185 |
|
|
| 186 |
|
|
| 187 |
## clean temp file |
|
| 188 |
temp1=`echo "" > $SH_TMP` |
|
| 189 |
|
|
Formats disponibles : Unified diff