1 | 1 | simandl | #!/bin/bash |
2 | | | |
3 | | | stat_dir="/var/statistiky/crusader" |
4 | | | mkdir -p $stat_dir |
5 | | | |
6 | | | config_file=/opt/statistiky/collect_crusader.conf |
7 | | | |
8 | | | if [ ! -f $config_file ] |
9 | | | then |
10 | | | echo "Missing config file $config_file" |
11 | | | exit 1; |
12 | | | fi |
13 | | | |
14 | | | cd $stat_dir |
15 | | | |
16 | | | function create() |
17 | | | # $1 ... netdevice |
18 | | | { |
19 | | | local file=$1 |
20 | | | echo "Creating RRD archive $file" |
21 | | | |
22 | | | # step = 5s |
23 | | | # za posledni 2,5 hodiny chceme vsechny PDP => 2,5 * 3600 / 5 = 1800 hodnot/radku |
24 | | | # 20s ~ agregace ze ctyr hodnot (PDP) |
25 | | | # za poslednich 10 hodin chceme 20s udaje => 10*3600/20 = 1800 generaci/radku |
26 | | | # za poslednich 30 hodin chceme 60s udaje => 30*3600/60 = 1800 generaci/radku |
27 | | | # 5 minut = 12 PDP za minutu * 5 minut = 60 PDP |
28 | | | # za posledni tyden (9dni) chceme 5minutove udaje => 12*24*9 = 2592 radku (rows) |
29 | | | # 20min ~ agregace z 240 PDP |
30 | | | # za posledni mesic (38dni) chceme 20minutove useky => 3*24*38 = 2736 radku |
31 | | | # dve hodiny ~ 1440 PDP |
32 | | | # za posledni rok chceme dvouhodinove useky => 12*400 = 4800 radku |
33 | | | |
34 | | | rrdtool create ${file}.rrd --step 5 --start `date +%s` \ |
35 | | | DS:rss_avg:GAUGE:10:0:999 \ |
36 | | | DS:rss_min:GAUGE:10:0:999 \ |
37 | | | DS:rss_max:GAUGE:10:0:999 \ |
38 | | | RRA:AVERAGE:0.7:1:1800 \ |
39 | | | RRA:MAX:0.7:1:1800 \ |
40 | | | RRA:MIN:0.7:1:1800 \ |
41 | | | RRA:AVERAGE:0.7:4:2880 \ |
42 | | | RRA:MAX:0.7:4:2880 \ |
43 | | | RRA:MIN:0.7:4:2880 \ |
44 | | | RRA:AVERAGE:0.7:12:1800 \ |
45 | | | RRA:MAX:0.7:12:1800 \ |
46 | | | RRA:MIN:0.7:12:1800 \ |
47 | | | RRA:AVERAGE:0.7:60:2592 \ |
48 | | | RRA:MAX:0.7:60:2592 \ |
49 | | | RRA:MIN:0.7:60:2592 \ |
50 | | | RRA:AVERAGE:0.7:240:2736 \ |
51 | | | RRA:MAX:0.7:240:2736 \ |
52 | | | RRA:MIN:0.7:240:2736 \ |
53 | | | RRA:AVERAGE:0.7:1440:4800 \ |
54 | | | RRA:MAX:0.7:1440:4800 \ |
55 | | | RRA:MIN:0.7:1440:4800 |
56 | | | |
57 | | | } |
58 | | | |
59 | | | function wait_to() |
60 | | | # $1 date for waiting to |
61 | | | { |
62 | | | local time_now=`date +%s`; |
63 | | | while [ $time_now -lt $1 ] |
64 | | | do |
65 | | | time_now=`date +%s` |
66 | | | sleep 1; |
67 | | | done |
68 | | | } |
69 | | | |
70 | | | start_time=`date +%s` |
71 | | | interval=$(( $start_time / 5 * 5 + 5 )) |
72 | | | |
73 | | | while [ true ] ; do |
74 | | | |
75 | | | . ${config_file} |
76 | | | |
77 | | | device=${DEVICE[0]} |
78 | | | rrdfile=${NAME[0]}0 |
79 | | | |
80 | | | if [ ! -f $rrdfile.rrd ] ; then |
81 | | | create $rrdfile |
82 | | | fi |
83 | | | |
84 | | | soucet_rss="0" |
85 | | | rss_min="1000" # ma to jen tri cifry, tj. max 999 => 1000 je vic nez maximum |
86 | | | rss_max="0" |
87 | | | pocet="0" |
88 | | | read rss <${device} # pouze synchronizace, holt o jeden radek prijdeme |
89 | | | time_now=`date +%s` |
90 | | | while [ $time_now -lt $interval ]; do # cekame na zacatek dalsiho intervalu |
91 | | | time_now=`date +%s` |
92 | | | |
93 | | | read -t 1 rss rest <${device} # tady cteme |
94 | | | # echo "rss: '$rss' and the rest of line: '$rest'" |
95 | | | test $rss -ge 0 2>/dev/null # slouzi k otestovani, ze rss obsahuje numerickou hodnoru |
96 | | | if [ $? -lt 2 ] # pokud vyjde 2, pak to neni cislo a test selhal |
97 | | | then |
98 | | | soucet_rss=$(( $soucet_rss + $rss )) |
99 | | | pocet=$(( $pocet + 1 )) |
100 | | | if [ $rss -lt $rss_min ]; then |
101 | | | rss_min=$rss |
102 | | | fi |
103 | | | if [ $rss -gt $rss_max ]; then |
104 | | | rss_max=$rss |
105 | | | fi |
106 | | | fi |
107 | | | done |
108 | | | |
109 | | | if [ $pocet -gt 0 ] |
110 | | | then |
111 | | | prumer=`echo "${soucet_rss}/${pocet}" | bc -l` |
112 | | | echo "prumer: $prumer min: $rss_min max: $rss_max" |
113 | | | rrdtool update $rrdfile.rrd -t rss_avg:rss_min:rss_max $interval:$prumer:$rss_min:$rss_max |
114 | | | else |
115 | | | echo "NaN" |
116 | | | rrdtool update $rrdfile.rrd -t rss_avg:rss_min:rss_max $interval:U:U:U |
117 | | | fi |
118 | | | |
119 | | | interval=$(( $interval + 5 )) |
120 | | | |
121 | | | done |