jablonka.czprosek.czf

crusader

Subversion Repositories:
[/] [trunk/] [statistiky/] [opt/] [statistiky/] [archiv/] [collect_crusader.sh.20051030] - Blame information for rev 2

 

Line No. Rev Author Line
11simandl#!/bin/bash3
2#
3#
4# 2005-10-27/Libor pridano prehazovani na WiFi zalohu pri signalu < 300
5#
6#
7 
8stat_dir="/var/statistiky/crusader"
9mkdir -p $stat_dir
10 
11config_file=/opt/statistiky/collect_crusader.conf
12 
13if [ ! -f $config_file ]
14then
15 echo "Missing config file $config_file"
16 exit 1;
17fi
18 
19cd $stat_dir
20 
21function create()
22# $1 ... netdevice
23{
24 local file=$1
25 echo "Creating RRD archive $file"
26 
27# step = 5s
28# za posledni 2,5 hodiny chceme vsechny PDP => 2,5 * 3600 / 5 = 1800 hodnot/radku
29# 20s ~ agregace ze ctyr hodnot (PDP)
30# za poslednich 10 hodin chceme 20s udaje => 10*3600/20 = 1800 generaci/radku
31# za poslednich 30 hodin chceme 60s udaje => 30*3600/60 = 1800 generaci/radku
32# 5 minut = 12 PDP za minutu * 5 minut = 60 PDP
33# za posledni tyden (9dni) chceme 5minutove udaje => 12*24*9 = 2592 radku (rows)
34# 20min ~ agregace z 240 PDP
35# za posledni mesic (38dni) chceme 20minutove useky => 3*24*38 = 2736 radku
36# dve hodiny ~ 1440 PDP
37# za posledni rok chceme dvouhodinove useky => 12*400 = 4800 radku
38 
39rrdtool create ${file}.rrd --step 5 --start `date +%s` \
40 DS:rss_avg:GAUGE:10:0:999 \
41 DS:rss_min:GAUGE:10:0:999 \
42 DS:rss_max:GAUGE:10:0:999 \
43 RRA:AVERAGE:0.7:1:1800 \
44 RRA:MAX:0.7:1:1800 \
45 RRA:MIN:0.7:1:1800 \
46 RRA:AVERAGE:0.7:4:2880 \
47 RRA:MAX:0.7:4:2880 \
48 RRA:MIN:0.7:4:2880 \
49 RRA:AVERAGE:0.7:12:1800 \
50 RRA:MAX:0.7:12:1800 \
51 RRA:MIN:0.7:12:1800 \
52 RRA:AVERAGE:0.7:60:2592 \
53 RRA:MAX:0.7:60:2592 \
54 RRA:MIN:0.7:60:2592 \
55 RRA:AVERAGE:0.7:240:2736 \
56 RRA:MAX:0.7:240:2736 \
57 RRA:MIN:0.7:240:2736 \
58 RRA:AVERAGE:0.7:1440:4800 \
59 RRA:MAX:0.7:1440:4800 \
60 RRA:MIN:0.7:1440:4800
61 
62}
63 
64function wait_to()
65# $1 date for waiting to
66{
67 local time_now=`date +%s`;
68 while [ $time_now -lt $1 ]
69 do
70 time_now=`date +%s`
71 sleep 1;
72 done
73}
74 
75function activate_wifi()
76{
77 ip route del 10.23.13.128/25
78 ip route add 10.23.13.128/25 via 10.23.13.42
79 ip route del 10.23.0.42/32
80 ip route add 10.23.0.42/32 via 10.23.13.42
81 echo "Activated WiFi backup"
82}
83function activate_fso()
84{
85 ip route del 10.23.13.128/25
86 ip route add 10.23.13.128/25 via 10.23.192.54
87 ip route del 10.23.0.42/32
88 ip route add 10.23.0.42/32 via 10.23.192.54
89 echo "Activated FSO primary link"
90}
91 
92rss_offset=75
93# kolikrat byl signal nizsi nez rss_low_threshold opakovane v rade po sobe
94rss_low_count=0
95# pocet detekovanych slabych signalu v rade, kdy se prepoji inet na zalohu
96rss_low_count_down=3
97# pokud sila signalu klesne pod threshold je indikovana jako slaby signal
98let rss_low_threshold=300-$rss_offset
99# kolikrat byl signal vyssi nez rss_good_threshold opakovane v rade po sobe
100rss_good_count=0
101# pocet detekovanych dobrych signalu v rade, kdy se prepoji inet zpet na Crusader
102rss_good_count_up=12
103# pokud sila signalu stoupne nad threshold je indikovana jako dobry signal
104let rss_good_threshold=350+rss_offset
105# stav sily signalu, muze byt 'low' nebo 'good'
106# zaciname s 'good' protoze prepnuti good->low je rychlejsi a taky startup skripty
107# pocitaji s optickou linkou, WiFi je zaloha
108rss_status="good"
109rss_status_last="good"
110 
111function rss_check_status()
112# $1 je sila signalu RSS
113{
114 local rss=$1
115 if [ $rss -ge $rss_low_threshold ]; then
116 echo "RSS($rss) >= low_threshold ($rss_low_threshold), erasing rss_low_count"
117 rss_low_count="0"
118 fi
119 if [ $rss -le $rss_good_threshold ]; then
120 echo "RSS($rss) <= good_threshold ($rss_good_threshold), erasing rss_good_count"
121 rss_good_count="0"
122 fi
123 if [ "$rss_status" == "good" ] && [ $rss -lt $rss_low_threshold ]; then
124 let rss_low_count+=1
125 echo "RSS($rss) < low_threshold ($rss_low_threshold), increasing rss_low_count to $rss_low_count"
126 fi
127 if [ "$rss_status" == "low" ] && [ $rss -gt $rss_good_threshold ]; then
128 let rss_good_count+=1
129 echo "RSS($rss) > good_threshold ($rss_good_threshold), increasing rss_good_count to $rss_good_count"
130 fi
131 if [ "$rss_status" == "good" ] && [ $rss_low_count -ge $rss_low_count_down ]; then
132 echo "FSO link goes down"
133 rss_status="low"
134 activate_wifi
135 fi
136 if [ "$rss_status" == "low" ] && [ $rss_good_count -ge $rss_good_count_up ]; then
137 echo "FSO link goes up"
138 rss_status="good"
139 activate_fso
140 fi
141}
142 
143start_time=`date +%s`
144interval=$(( $start_time / 5 * 5 + 5 ))
145 
146while [ true ] ; do
147 
148 . ${config_file}
149 
150 device=${DEVICE[0]}
151 rrdfile=${NAME[0]}0
152 
153 if [ ! -f $rrdfile.rrd ] ; then
154 create $rrdfile
155 fi
156 
157 soucet_rss="0"
158 rss_min="1000" # ma to jen tri cifry, tj. max 999 => 1000 je vic nez maximum
159 rss_max="0"
160 pocet="0"
161 read rss <${device} # pouze synchronizace, holt o jeden radek prijdeme
162 time_now=`date +%s`
163 while [ $time_now -lt $interval ]; do # cekame na zacatek dalsiho intervalu
164 time_now=`date +%s`
165 
166 read -t 1 rss rest <${device} # tady cteme
167# echo "rss: '$rss' and the rest of line: '$rest'"
168 test $rss -ge 0 2>/dev/null # slouzi k otestovani, ze rss obsahuje numerickou hodnoru
169 if [ $? -lt 2 ] # pokud vyjde 2, pak to neni cislo a test selhal
170 then
171 soucet_rss=$(( $soucet_rss + $rss ))
172 pocet=$(( $pocet + 1 ))
173 if [ $rss -lt $rss_min ]; then
174 rss_min=$rss
175 fi
176 if [ $rss -gt $rss_max ]; then
177 rss_max=$rss
178 fi
179 fi
180 done
181 
182 if [ $pocet -gt 0 ]
183 then
184 prumer=`echo "${soucet_rss}/${pocet}" | bc -l`
185 echo "prumer: $prumer min: $rss_min max: $rss_max"
186 rrdtool update $rrdfile.rrd -t rss_avg:rss_min:rss_max $interval:$prumer:$rss_min:$rss_max
187 prumer=`echo $prumer | cut -d '.' -f 1`
188 rss_check_status $prumer
189 else
190 echo "NaN"
191 rrdtool update $rrdfile.rrd -t rss_avg:rss_min:rss_max $interval:U:U:U
192 rss_check_status 0
193 fi
194 
195 interval=$(( $interval + 5 ))
196 
197done

Powered by WebSVN 2.2.1