-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrc.status
executable file
·133 lines (113 loc) · 3.81 KB
/
rc.status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# ------------------ rc.status "rc.status" ----------------
# All rights reserved for B@roo 2000-2011
# ---------------------------------------------------------
#set -x
VERSION="2.9.9v"
# Configuration loading
if [ ! -e ${0%rc.status}rc.fire_conf ]; then
exit 1
fi
START_FILE="rc.status"
source ${0%rc.status}rc.fire_conf
# --------------------- Show counters -----------------------
counters()
{
echo " === Traffic counters === "
LIST_NAME=""
for i in `cat ${0%$START_FILE}rc.fire_count | cut -d '#' -f1`
do
# Check for 'table' name
if [ ! `echo $i | grep table` == "" ]; then
TABLE_NAME=`echo $i | cut -d';' -f2`
echo " "
echo " === Table: $TABLE_NAME "
printf " %-20s %-25s %14s %14s \n" 'IP' 'HOST' 'DOWNLOAD' 'UPLOAD'
else
# Parse table
IP_RECORD=`iptaccount -l $TABLE_NAME | grep " $i "`
# Resolve name
NAME=`cat /etc/hosts | grep "$i\s" | awk '{ print $2}'`
if [ ! $NAME == "" ]; then
NAME_STRING="$NAME"
else
NAME_STRING="---"
fi
if [ -n "$IP_RECORD" ]; then
DOWNLOAD=`echo $IP_RECORD | cut -d ' ' -f7`
if [ $DOWNLOAD -gt $[1024*1024*1024] ]; then
DOWNLOAD_RESULT=`echo "scale=2;$DOWNLOAD/1024/1024/1024" | bc`
DOWNLOAD_STRING=`echo ${DOWNLOAD_RESULT}GB`
elif [ $DOWNLOAD -gt $[1024*1024] ]; then
DOWNLOAD_RESULT=`echo "scale=2;$DOWNLOAD/1024/1024" | bc`
DOWNLOAD_STRING=`echo ${DOWNLOAD_RESULT}MB`
elif [ $DOWNLOAD -gt 1024 ]; then
DOWNLOAD_RESULT=`echo "scale=2;$DOWNLOAD/1024" | bc`
DOWNLOAD_STRING=`echo ${DOWNLOAD_RESULT}KB`
elif [ $DOWNLOAD -gt 1 ]; then
DOWNLOAD_RESULT=`echo "scale=2;$DOWNLOAD/1" | bc`
DOWNLOAD_STRING=`echo ${DOWNLOAD_RESULT}B`
else
DOWNLOAD_STRING="0.00B"
fi
UPLOAD=`echo $IP_RECORD | cut -d ' ' -f12`
if [ $UPLOAD -gt $[1024*1024*1024] ]; then
UPLOAD_RESULT=`echo "scale=2;$UPLOAD/1024/1024/1024" | bc`
UPLOAD_STRING=`echo ${UPLOAD_RESULT}GB`
elif [ $UPLOAD -gt $[1024*1024] ]; then
UPLOAD_RESULT=`echo "scale=2;$UPLOAD/1024/1024" | bc`
UPLOAD_STRING=`echo ${UPLOAD_RESULT}MB`
elif [ $UPLOAD -gt 1024 ]; then
UPLOAD_RESULT=`echo "scale=2;$UPLOAD/1024" | bc`
UPLOAD_STRING=`echo ${UPLOAD_RESULT}KB`
elif [ $UPLOAD -gt 1 ]; then
UPLOAD_RESULT=`echo "scale=2;$UPLOAD/1" | bc`
UPLOAD_STRING=`echo ${UPLOAD_RESULT}B`
else
UPLOAD_STRING="0.00B"
fi
printf " %-20s %-25s %14s %14s \n" $i $NAME_STRING $DOWNLOAD_STRING $UPLOAD_STRING
else
printf " %-20s %-25s %14s %14s \n" $i $NAME_STRING 0.00B 0.00B
fi
fi
done
echo " "
}
# -------------------- Show qos-status -----------------------
status()
{
echo "imq0 interface classes"
echo "================================"
tc class show dev imq0 | grep root
tc class show dev imq0 | grep -v root | sort | nl
echo "imq1 interface classes"
echo "==================================="
tc class show dev imq1 | grep root
tc class show dev imq1 | grep -v root | sort | nl
}
# -------------------- Show qos-state ------------------------
state()
{
echo "imq0 interface classes counters"
echo "================================"
tc -s -d class show dev imq0
echo "imq1 interface classes counters"
echo "================================"
tc -s -d class show dev imq1
}
# -------- { counters | qos-status | qos-state } ------------
case "$1" in
'counters')
counters
;;
'qos-state')
state
;;
'qos-status')
status
;;
*)
counters
;;
esac