jablonka.czprosek.czf

crusader

Subversion Repositories:
[/] [trunk/] [statistiky/] [opt/] [statistiky/] [collect_crusader.sh.20080607] - Blame information for rev 1

 

Line No. Rev Author Line
11simandl#!/bin/bash3
2#
3#
4# 2006-11-22/Libor Predelano cteni RSS pomoci nove aplikace napsane v C pro snizeni
5# zateze CPU, ktera na VIA C3 800MHz ve stavajici podobe dosahovala
6# az 100%.
7#
8# 2005-11-27/Libor Predelano cteni seriaku. Ted si ho otevre jako filedescriptor
9# a cte z nej jako ze souboru. Na Marvinovi se tim (snad) uplne
10# odstranily chly do nuly, ktere byly nejspis zpusobeny
11# rychlosti (pomalosti) Marvina. (800MHz VIA C3)
12# 2005-11-02/Libor konfiguracni skripty na prehazovani primarni FSO <-> backup WiFi
13# logovani do /var/statistiky/crusader/crusader.log
14# bash3, nevim proc, ale na Marvinovi mi to s dvojkou nechodilo kvuliva
15# porovnavani desetinnych cisel pomoci if [ $neco -le $rss ]...
16# 2005-10-27/Libor pridano prehazovani na WiFi zalohu pri signalu < 300
17#
18#
19 
20PATH=$PATH:/opt/statistiky/bin
21 
22if [ $# -eq 1 ]; then
23 crusader_number=$1
24fi
25if [ $# -gt 1 ]; then
26 echo "ERROR: more than 1 option" >&2
27fi
28if [ $# -lt 1 ]; then
29 crusader_number=0
30fi
31 
32stat_dir="/var/statistiky/crusader"
33logfile="$stat_dir/crusader.log"
34mkdir -p $stat_dir
35 
36config_file=/opt/statistiky/collect_crusader.conf
37script_set_main=/opt/statistiky/crusader_set_main.sh
38script_set_backup=/opt/statistiky/crusader_set_backup.sh
39 
40function Log()
41# $1 ... message
42{
43 timenow=`date +"%Y-%m-%d %T"`
44 echo "LOG: $timenow $1"
45 echo "$timenow $1" >>$logfile
46}
47 
48Log "Crusader start ====="
49Log "Using config file: $config_file"
50 
51if [ ! -f $config_file ]
52then
53 Log "Missing config file $config_file, exiting."
54 exit 1;
55fi
56 
57if [ ! -x $script_set_main ]; then
58 Log "Script set up main is not executable: $script_set_main"
59 exit 1;
60fi
61if [ ! -x $script_set_backup ]; then
62 Log "Script set up main is not executable: $script_set_backup"
63 exit 1;
64fi
65 
66cd $stat_dir
67 
68function create()
69# $1 ... netdevice
70{
71 local file=$1
72 Log "Creating RRD archive $file"
73 
74# step = 5s
75# za posledni 2,5 hodiny chceme vsechny PDP => 2,5 * 3600 / 5 = 1800 hodnot/radku
76# 20s ~ agregace ze ctyr hodnot (PDP)
77# za poslednich 10 hodin chceme 20s udaje => 10*3600/20 = 1800 generaci/radku
78# za poslednich 30 hodin chceme 60s udaje => 30*3600/60 = 1800 generaci/radku
79# 5 minut = 12 PDP za minutu * 5 minut = 60 PDP
80# za posledni tyden (9dni) chceme 5minutove udaje => 12*24*9 = 2592 radku (rows)
81# 20min ~ agregace z 240 PDP
82# za posledni mesic (38dni) chceme 20minutove useky => 3*24*38 = 2736 radku
83# dve hodiny ~ 1440 PDP
84# za posledni rok chceme dvouhodinove useky => 12*400 = 4800 radku
85 
86rrdtool create ${file}.rrd --step 5 --start `date +%s` \
87 DS:rss_avg:GAUGE:10:0:999 \
88 DS:rss_min:GAUGE:10:0:999 \
89 DS:rss_max:GAUGE:10:0:999 \
90 RRA:AVERAGE:0.7:1:1800 \
91 RRA:MAX:0.7:1:1800 \
92 RRA:MIN:0.7:1:1800 \
93 RRA:AVERAGE:0.7:4:2880 \
94 RRA:MAX:0.7:4:2880 \
95 RRA:MIN:0.7:4:2880 \
96 RRA:AVERAGE:0.7:12:1800 \
97 RRA:MAX:0.7:12:1800 \
98 RRA:MIN:0.7:12:1800 \
99 RRA:AVERAGE:0.7:60:2592 \
100 RRA:MAX:0.7:60:2592 \
101 RRA:MIN:0.7:60:2592 \
102 RRA:AVERAGE:0.7:240:2736 \
103 RRA:MAX:0.7:240:2736 \
104 RRA:MIN:0.7:240:2736 \
105 RRA:AVERAGE:0.7:1440:4800 \
106 RRA:MAX:0.7:1440:4800 \
107 RRA:MIN:0.7:1440:4800
108 
109}
110 
111# zastarala: ted cekame pomoci crusader_read_rss
112function wait_to()
113# $1 date for waiting to
114{
115 local time_now=`date +%s`;
116 while [ $time_now -lt $1 ]
117 do
118 time_now=`date +%s`
119 sleep 1;
120 done
121}
122 
123 
124function activate_backup()
125{
126 $script_set_backup
127 echo "Activated WiFi backup"
128}
129function activate_fso()
130{
131 $script_set_main
132 echo "Activated FSO primary link"
133}
134 
135function read_remote_status()
136{
137 remote_rss_status=`grep ^RSS: /var/statistiky/crusader/remote_site_status | awk '{ print $2;}'`
138 echo "Remote RSS status: $remote_rss_status"
139}
140 
141function write_status_to_remote()
142{
143 Log " Writing status (RSS: $rss_status) to remote side"
144 ssh libor@10.23.64.169 "echo \"RSS: $rss_status\" >/var/statistiky/crusader/remote_site_status"
145}
146 
147function rss_check_status()
148# $1 ... jmeno rusaderu (napr. crusader0)
149# $2 je sila signalu RSS
150{
151 local name=$1
152 local rss=$2
153 if [ $rss -ge $rss_low_threshold ]; then
154 echo "RSS($rss) >= low_threshold ($rss_low_threshold), erasing rss_low_count"
155 rss_low_count="0"
156 fi
157 if [ $rss -le $rss_good_threshold ]; then
158 echo "RSS($rss) <= good_threshold ($rss_good_threshold), erasing rss_good_count"
159 rss_good_count="0"
160 fi
161 if [ "$rss_status" == "good" ] && [ $rss -lt $rss_low_threshold ]; then
162 let rss_low_count+=1
163 echo "RSS($rss) < low_threshold ($rss_low_threshold), increasing rss_low_count to $rss_low_count"
164 fi
165 if [ "$rss_status" == "low" ] && [ $rss -gt $rss_good_threshold ]; then
166 let rss_good_count+=1
167 echo "RSS($rss) > good_threshold ($rss_good_threshold), increasing rss_good_count to $rss_good_count"
168 fi
169 if [ "$rss_status" == "good" ] && [ $rss_low_count -ge $rss_low_counter_go_backup ]; then
170 echo "RSS goes down"
171 rss_status="low"
172 Log "Crusader $crusader_number: goes down, RSS: low ($rss)"
173 write_status_to_remote
174 fi
175 if [ "$rss_status" == "low" ] && [ $rss_good_count -ge $rss_good_counter_go_main ]; then
176 echo "RSS goes up"
177 rss_status="good"
178 Log "Crusader $crusader_number: goes up, RSS: good ($rss)"
179 write_status_to_remote
180 fi
181 
182 if [ "$link_status" == "FSO" ] && [ "$rss_status" == "low" ]
183 then
184 Log "Link to backup"
185 activate_backup
186 link_status="backup"
187 fi
188 if [ "$link_status" == "backup" ] && [ "$rss_status" == "good" ] && [ "$remote_rss_status" == "good" ]
189 then
190 Log "Link to FSO"
191 activate_fso
192 link_status="FSO"
193 fi
194 
195 read_remote_status
196 
197 if [ "$link_status" == "FSO" ] && [ "$remote_rss_status" == "low" ]
198 then
199 Log "Link to backup"
200 activate_backup
201 link_status="backup"
202 write_status_to_remote
203 fi
204}
205 
206# Pocatecni nastaveni linky FSO/backup
207function setup_initial_link_status()
208{
209 if [ $rss_avg -gt $rss_good_threshold ]; then
210 rss_status="good"
211 rss_status_last="good"
212 link_status="unknown"
213 else
214 rss_status="low"
215 rss_status_last="low"
216 link_status="unknown"
217 fi
218 write_status_to_remote
219 read_remote_status
220 
221 if [ "$rss_status" == "good" ] && [ "$remote_rss_status" == "good" ]
222 then
223 Log "Link to FSO"
224 activate_fso
225 link_status="FSO"
226 else
227 Log "Link to backup"
228 activate_backup
229 link_status="backup"
230 fi
231}
232 
233function load_config()
234{
235 . ${config_file}
236 rss_low_threshold=${RSS_LOW_THRESHOLD[$crusader_number]}
237 rss_good_threshold=${RSS_GOOD_THRESHOLD[$crusader_number]}
238 rss_low_counter_go_backup=${RSS_LOW_COUNTER_TO_GO_BACKUP[$crusader_number]}
239 rss_good_counter_go_main=${RSS_GOOD_COUNTER_TO_GO_MAIN[$crusader_number]}
240 device=${DEVICE[$crusader_number]}
241 name=${NAME[$crusader_number]}${crusader_number}
242}
243 
244print_config()
245{
246 Log "Crusader $crusader_number"
247 Log " RSS low threshold = $rss_low_threshold"
248 Log " RSS good threshold = $rss_good_threshold"
249 Log " RSS low counter go backup = $rss_low_counter_go_backup"
250 Log " RSS good counter go main = $rss_good_counter_go_main"
251 Log " Seriak: $device"
252}
253 
254# Inicializace
255load_config
256print_config
257j=0
258rv=2
259 
260rss_line=`crusader_read_rss ${device} +2 2>/dev/null`
261rss_avg=`echo $rss_line | awk '{ print $2; }'`
262if [ -z "$rss_avg" ]; then
263 rss_avg="0"
264fi
265Log " Sila signalu pri startu (RSS): $rss_avg"
266 
267# Prvotni nastaveni linky pred hlavni smyckou
268setup_initial_link_status
269 
270# kolikrat byl signal nizsi nez rss_low_threshold opakovane v rade po sobe
271rss_low_counter=0
272# kolikrat byl signal vyssi nez rss_good_threshold opakovane v rade po sobe
273rss_good_counter=0
274 
275start_time=`date +%s`
276interval=$(( $start_time / 5 * 5 + 5 ))
277 
278# Hlavni smycka
279while [ true ] ; do
280 
281 load_config
282 
283 rrdfile=${name}
284 if [ ! -f $rrdfile.rrd ] ; then
285 create $rrdfile
286 fi
287 
288 rss_line=`crusader_read_rss ${device} ${interval} 2>/dev/null`
289 echo "RSS LINE: $rss_line"
290 pocet=`echo $rss_line | awk '{ print $1; }'`
291 if [ -z "$pocet" ]; then
292 pocet="0"
293 fi
294 rss_avg=`echo $rss_line | awk '{ print $2; }'`
295 rss_max=`echo $rss_line | awk '{ print $3; }'`
296 rss_min=`echo $rss_line | awk '{ print $4; }'`
297 if [ -z "$rss_avg" ]; then
298 rss_avg="0"
299 fi
300 if [ -z "$rss_max" ]; then
301 rss_max="0"
302 fi
303 if [ -z "$rss_min" ]; then
304 rss_min="0"
305 fi
306 
307 if [ $pocet -gt 0 ]
308 then
309 echo "Pocet vzorku: $pocet RSS avg: $rss_avg min: $rss_min max: $rss_max"
310 rrdtool update $rrdfile.rrd -t rss_avg:rss_min:rss_max $interval:$rss_avg:$rss_min:$rss_max
311 rss_check_status ${name} $rss_avg
312 else
313 echo "NaN"
314 rrdtool update $rrdfile.rrd -t rss_avg:rss_min:rss_max $interval:U:U:U
315 rss_check_status ${name} 0
316 fi
317 
318 interval=$(( $interval + 5 ))
319 
320 echo ""
321done

Powered by WebSVN 2.2.1