root / plugins / network / hfsc @ 17f78427
Historique | Voir | Annoter | Télécharger (3,06 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 3 |
# Munin plugin for HFSC Traffic Shaping Statistics |
| 4 |
# |
| 5 |
# It shows the general 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 |
|
| 24 |
# imported from HFSC script |
| 25 |
# set class numbers |
| 26 |
|
| 27 |
N_CLASS_D_1=70 |
| 28 |
N_CLASS_D_2=100 |
| 29 |
N_CLASS_U_1=130 |
| 30 |
N_CLASS_U_2=160 |
| 31 |
SH_TMP="/etc/scripts/tmp.txt" |
| 32 |
|
| 33 |
if [ "$1" = "config" ]; then |
| 34 |
|
| 35 |
echo "graph_title HFSC Traffic Shaping Stats" |
| 36 |
echo 'graph_vlabel bytes per ${graph_period}'
|
| 37 |
echo 'graph_category network' |
| 38 |
|
| 39 |
j=1 |
| 40 |
|
| 41 |
while [ $j -le $L_USERS ] |
| 42 |
do |
| 43 |
echo "${USERNAMES[${j}]}.label ${USERNAMES[${j}]}"
|
| 44 |
echo "${USERNAMES[${j}]}.type COUNTER"
|
| 45 |
|
| 46 |
if [ $j == 1 ]; then |
| 47 |
echo "${USERNAMES[${j}]}.draw AREA"
|
| 48 |
else |
| 49 |
echo "${USERNAMES[${j}]}.draw STACK"
|
| 50 |
fi; |
| 51 |
|
| 52 |
echo "${USERNAMES[${j}]}.info Stats for ${USERNAMES[${j}]} - ${USER_IP[${j}]}"
|
| 53 |
echo "${USERNAMES[${j}]}.min 0"
|
| 54 |
echo "${USERNAMES[${j}]}.max 130000"
|
| 55 |
|
| 56 |
j=$[$j+1] |
| 57 |
|
| 58 |
done; |
| 59 |
|
| 60 |
#customized colours |
| 61 |
echo 'Serwer.colour 000000' |
| 62 |
|
| 63 |
exit 0 |
| 64 |
|
| 65 |
fi; |
| 66 |
|
| 67 |
#### DOWNLOAD |
| 68 |
|
| 69 |
temp1=`/sbin/tc -s class show dev imq0 > $SH_TMP` |
| 70 |
|
| 71 |
|
| 72 |
while read line |
| 73 |
do |
| 74 |
test_hfsc=`echo $line | grep "hfsc"` |
| 75 |
|
| 76 |
j=1 |
| 77 |
|
| 78 |
while [ $j -le $L_USERS ] |
| 79 |
do |
| 80 |
case $test_hfsc in |
| 81 |
|
| 82 |
*hfsc[\ ]1:$[$N_CLASS_D_1+$j]*) |
| 83 |
# check N_CLASS_D_1 stats for every user |
| 84 |
read line |
| 85 |
temp1=`echo $line | awk '{ print $2; }'`
|
| 86 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
| 87 |
# echo "N_CLASS_D_1="$temp1 |
| 88 |
# echo "N_CLASS_D_1_SUM "$j" ="${STAT_USER[$j]}
|
| 89 |
;; |
| 90 |
*hfsc[\ ]1:$[$N_CLASS_D_2+$j]*) |
| 91 |
# check N_CLASS_D_2 stats for every user |
| 92 |
read line |
| 93 |
temp1=`echo $line | awk '{ print $2; }'`
|
| 94 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
| 95 |
# echo "N_CLASS_D_2="$temp1 |
| 96 |
# echo "N_CLASS_D_2_SUM "$j" ="${STAT_USER[$j]}
|
| 97 |
;; |
| 98 |
esac |
| 99 |
|
| 100 |
j=$[$j+1] |
| 101 |
|
| 102 |
done; |
| 103 |
|
| 104 |
done < $SH_TMP |
| 105 |
|
| 106 |
#### UPLOAD |
| 107 |
|
| 108 |
temp1=`/sbin/tc -s class show dev imq1 > $SH_TMP` |
| 109 |
|
| 110 |
|
| 111 |
while read line |
| 112 |
do |
| 113 |
test_hfsc=`echo $line | grep "hfsc"` |
| 114 |
|
| 115 |
j=1 |
| 116 |
|
| 117 |
while [ $j -le $L_USERS ] |
| 118 |
do |
| 119 |
case $test_hfsc in |
| 120 |
|
| 121 |
*hfsc[\ ]1:$[$N_CLASS_U_1+$j]*) |
| 122 |
# check N_CLASS_U_1 stats for every user |
| 123 |
read line |
| 124 |
temp1=`echo $line | awk '{ print $2; }'`
|
| 125 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
| 126 |
# echo "N_CLASS_U_1="$temp1 |
| 127 |
# echo "N_CLASS_U_1_SUM "$j" ="${STAT_USER[$j]}
|
| 128 |
;; |
| 129 |
*hfsc[\ ]1:$[$N_CLASS_U_2+$j]*) |
| 130 |
# check N_CLASS_U_2 stats for every user |
| 131 |
read line |
| 132 |
temp1=`echo $line | awk '{ print $2; }'`
|
| 133 |
STAT_USER[$j]=$[${STAT_USER[$j]}+$temp1]
|
| 134 |
# echo "N_CLASS_U_2="$temp1 |
| 135 |
# echo "N_CLASS_U_2_SUM "$j" ="${STAT_USER[$j]}
|
| 136 |
;; |
| 137 |
esac |
| 138 |
|
| 139 |
j=$[$j+1] |
| 140 |
|
| 141 |
done; |
| 142 |
|
| 143 |
done < $SH_TMP |
| 144 |
|
| 145 |
j=1 |
| 146 |
while [ $j -le $L_USERS ] |
| 147 |
do |
| 148 |
echo ${USERNAMES[${j}]}".value "${STAT_USER[$j]}
|
| 149 |
j=$[$j+1] |
| 150 |
done; |
| 151 |
|
| 152 |
|
| 153 |
## clean temp file |
| 154 |
temp1=`echo "" > $SH_TMP` |
