1 | 1 | simandl | #!/bin/bash |
2 | | | |
3 | | | if [ $# -lt 4 ] |
4 | | | then |
5 | | | echo "Usage: `basename $0` <target name> <time interval> <file suffix> <graph comment> [graph width]" |
6 | | | exit 1; |
7 | | | fi |
8 | | | |
9 | | | name="$1" |
10 | | | timediff="$2" |
11 | | | suffix="$3" |
12 | | | popis="$4" |
13 | | | |
14 | | | if [ $# -ge 5 ] |
15 | | | then |
16 | | | width="$5" |
17 | | | else |
18 | | | width=400 |
19 | | | fi |
20 | | | |
21 | | | #PATH=$PATH:/opt/rrdtool/bin |
22 | | | |
23 | | | datadir="/var/statistiky/ping" |
24 | | | target_img_dir="/var/www/heaven/stat/img" |
25 | | | |
26 | | | cd $datadir |
27 | | | |
28 | | | now=`date +%s` |
29 | | | |
30 | | | if [ $timediff -ge 604800 ] |
31 | | | then |
32 | | | xgridstr="--x-grid HOUR:12:DAY:1:DAY:1:86400:%d.%m." |
33 | | | else |
34 | | | xgridstr="" |
35 | | | fi |
36 | | | |
37 | | | xgridstr="" |
38 | | | if [ $timediff -gt 108000 ]; then xgridstr="--x-grid HOUR:6:DAY:1:DAY:1:86400:%d.%m."; fi |
39 | | | if [ $timediff -gt 777600 ]; then xgridstr="--x-grid DAY:1:WEEK:1:WEEK:1:86400:%d.%m."; fi |
40 | | | |
41 | | | function rtt_avg_peak() |
42 | | | { |
43 | | | rrdtool graph ${target_img_dir}/ping_${name}_rtt_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
44 | | | DEF:rttavg=${name}.rrd:rttavg:MAX \ |
45 | | | DEF:rttmin=${name}.rrd:rttmin:MAX \ |
46 | | | AREA:rttmin#a8a8FF:"min" \ |
47 | | | LINE2:rttavg#202020:"avg" \ |
48 | | | --vertical-label "Round Trip Time Peak [ms]" \ |
49 | | | --height 200 \ |
50 | | | --width ${width} \ |
51 | | | ${xgridstr} \ |
52 | | | --title "Spickove hodnoty: ${name} ${popis}" \ |
53 | | | --lower-limit 0 \ |
54 | | | --upper-limit 1 |
55 | | | } |
56 | | | |
57 | | | function flow_graph() |
58 | | | { |
59 | | | rtt_avg_peak |
60 | | | |
61 | | | rrdtool graph ${target_img_dir}/ping_${name}_pktloss_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
62 | | | DEF:pl_avg=${name}.rrd:pktloss:AVERAGE \ |
63 | | | DEF:pl_min=${name}.rrd:pktloss:MIN \ |
64 | | | DEF:pl_max=${name}.rrd:pktloss:MAX \ |
65 | | | CDEF:avg1=PREV\(pl_avg\) \ |
66 | | | CDEF:avg2=PREV\(avg1\) \ |
67 | | | CDEF:min1=PREV\(pl_min\) \ |
68 | | | CDEF:min2=PREV\(min1\) \ |
69 | | | CDEF:max1=PREV\(pl_max\) \ |
70 | | | CDEF:max2=PREV\(max1\) \ |
71 | | | CDEF:prumer_pktloss=pl_avg,avg1,avg2,+,+,3,/ \ |
72 | | | CDEF:maxmin=pl_max,pl_min,- \ |
73 | | | HRULE:5#000000 \ |
74 | | | AREA:pl_min#FFFFFF \ |
75 | | | STACK:maxmin#e0e0e0 \ |
76 | | | LINE1:pl_max#FFa1a1:"max" \ |
77 | | | LINE1:pl_min#a8a8FF:"min" \ |
78 | | | LINE2:prumer_pktloss#202020:"avg" \ |
79 | | | --vertical-label "Packet loss [%]" \ |
80 | | | --height 200 \ |
81 | | | --width ${width} \ |
82 | | | ${xgridstr} \ |
83 | | | --title "${name} ${popis}" \ |
84 | | | --lower-limit 0 \ |
85 | | | --upper-limit 5 |
86 | | | } |
87 | | | |
88 | | | function rtt_mean_deviation_avgavg() |
89 | | | { |
90 | | | rrdtool graph ${target_img_dir}/ping_${name}_rtt_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
91 | | | DEF:rttmin=${name}.rrd:rttmin:AVERAGE \ |
92 | | | DEF:rttavg=${name}.rrd:rttavg:AVERAGE \ |
93 | | | DEF:rttmdev=${name}.rrd:rttmdev:AVERAGE \ |
94 | | | CDEF:avg1=PREV\(rttavg\) \ |
95 | | | CDEF:avg2=PREV\(avg1\) \ |
96 | | | CDEF:min1=PREV\(rttmin\) \ |
97 | | | CDEF:mdev1=PREV\(rttmdev\) \ |
98 | | | CDEF:prumer_rttavg=rttavg,avg1,avg2,+,+,3,/ \ |
99 | | | LINE2:min1#6750ff:"min" \ |
100 | | | LINE1:mdev1#ff5047:"mdev" \ |
101 | | | LINE2:prumer_rttavg#202020:"avg" \ |
102 | | | --vertical-label "Round Trip Time [ms]" \ |
103 | | | --height 200 \ |
104 | | | --width ${width} \ |
105 | | | ${xgridstr} \ |
106 | | | --title "${name} ${popis}" \ |
107 | | | --lower-limit 0 \ |
108 | | | --upper-limit 1 |
109 | | | } |
110 | | | function rtt_mean_deviation_maxavg() |
111 | | | { |
112 | | | rrdtool graph ${target_img_dir}/ping_${name}_rtt_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
113 | | | DEF:rttmin=${name}.rrd:rttmin:MAX \ |
114 | | | DEF:rttavg=${name}.rrd:rttavg:MAX \ |
115 | | | DEF:rttmdev=${name}.rrd:rttmdev:MAX \ |
116 | | | CDEF:avg1=PREV\(rttavg\) \ |
117 | | | CDEF:avg2=PREV\(avg1\) \ |
118 | | | CDEF:min1=PREV\(rttmin\) \ |
119 | | | CDEF:mdev1=PREV\(rttmdev\) \ |
120 | | | CDEF:prumer_rttavg=rttavg,avg1,avg2,+,+,3,/ \ |
121 | | | LINE2:min1#6750ff:"min" \ |
122 | | | LINE1:mdev1#ff5047:"mdev" \ |
123 | | | LINE2:prumer_rttavg#202020:"avg" \ |
124 | | | --vertical-label "Round Trip Time [ms]" \ |
125 | | | --height 200 \ |
126 | | | --width ${width} \ |
127 | | | ${xgridstr} \ |
128 | | | --title "${name} ${popis}" \ |
129 | | | --lower-limit 0 \ |
130 | | | --upper-limit 1 |
131 | | | } |
132 | | | |
133 | | | function rtt_min_max_avg_7200() |
134 | | | { |
135 | | | rrdtool graph ${target_img_dir}/ping_${name}_rtt_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
136 | | | DEF:rttmin=${name}.rrd:rttmin:AVERAGE \ |
137 | | | DEF:rttmax=${name}.rrd:rttmax:AVERAGE \ |
138 | | | DEF:rttavg=${name}.rrd:rttavg:AVERAGE \ |
139 | | | DEF:rttmdev=${name}.rrd:rttmdev:AVERAGE \ |
140 | | | CDEF:avg1=PREV\(rttavg\) \ |
141 | | | CDEF:avg2=PREV\(avg1\) \ |
142 | | | CDEF:min1=PREV\(rttmin\) \ |
143 | | | CDEF:max1=PREV\(rttmax\) \ |
144 | | | CDEF:mdev1=PREV\(rttmdev\) \ |
145 | | | CDEF:prumer_rttavg=rttavg,avg1,avg2,+,+,3,/ \ |
146 | | | CDEF:maxmin=max1,min1,- \ |
147 | | | AREA:min1#FFFFFF \ |
148 | | | STACK:maxmin#e0e0e0 \ |
149 | | | LINE1:max1#FFa1a1:"max" \ |
150 | | | LINE1:min1#a8a8FF:"min" \ |
151 | | | LINE2:prumer_rttavg#202020:"avg" \ |
152 | | | --vertical-label "Round Trip Time [ms]" \ |
153 | | | --height 200 \ |
154 | | | --width ${width} \ |
155 | | | ${xgridstr} \ |
156 | | | --title "${name} ${popis}" \ |
157 | | | --lower-limit 0 \ |
158 | | | --upper-limit 1 |
159 | | | } |
160 | | | |
161 | | | function flow_graph_7200() |
162 | | | { |
163 | | | |
164 | | | rtt_mean_deviation_7200 |
165 | | | |
166 | | | rrdtool graph ${target_img_dir}/ping_${name}_pktloss_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
167 | | | DEF:pl_avg=${name}.rrd:pktloss:AVERAGE \ |
168 | | | CDEF:avg1=PREV\(pl_avg\) \ |
169 | | | CDEF:avg2=PREV\(avg1\) \ |
170 | | | CDEF:min_agg=pl_avg,avg1,avg2,MIN,MIN \ |
171 | | | CDEF:max_agg=pl_avg,avg1,avg2,MAX,MAX \ |
172 | | | CDEF:prumer_pktloss=pl_avg,avg1,avg2,+,+,3,/ \ |
173 | | | CDEF:maxmin=max_agg,min_agg,- \ |
174 | | | HRULE:5#000000 \ |
175 | | | AREA:min_agg#FFFFFF \ |
176 | | | STACK:maxmin#e0e0e0 \ |
177 | | | LINE1:max_agg#FFa1a1:"max" \ |
178 | | | LINE1:min_agg#a8a8FF:"min" \ |
179 | | | LINE2:prumer_pktloss#202020:"avg" \ |
180 | | | --vertical-label "Packet loss [%]" \ |
181 | | | --height 200 \ |
182 | | | --width ${width} \ |
183 | | | ${xgridstr} \ |
184 | | | --title "${name} ${popis}" \ |
185 | | | --lower-limit 0 \ |
186 | | | --upper-limit 5 |
187 | | | } |
188 | | | |
189 | | | function rtt_prime_nekonsolidovane_hodnoty() |
190 | | | { |
191 | | | rrdtool graph ${target_img_dir}/ping_${name}_rtt_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
192 | | | DEF:rttmin=${name}.rrd:rttmin:AVERAGE \ |
193 | | | DEF:rttavg=${name}.rrd:rttavg:AVERAGE \ |
194 | | | DEF:rttmdev=${name}.rrd:rttmdev:AVERAGE \ |
195 | | | LINE2:rttmin#6750ff:"min" \ |
196 | | | LINE1:rttmdev#ff5047:"mdev" \ |
197 | | | LINE2:rttavg#202020:"avg" \ |
198 | | | --vertical-label "Round Trip Time [ms]" \ |
199 | | | --height 200 \ |
200 | | | --width ${width} \ |
201 | | | ${xgridstr} \ |
202 | | | --title "${name} ${popis}" \ |
203 | | | --lower-limit 0 \ |
204 | | | --upper-limit 1 |
205 | | | } |
206 | | | |
207 | | | function pktloss_prime_nekonsolidovane_hodnoty() |
208 | | | { |
209 | | | rrdtool graph ${target_img_dir}/ping_${name}_pktloss_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
210 | | | DEF:pl_avg=${name}.rrd:pktloss:AVERAGE \ |
211 | | | HRULE:5#000000 \ |
212 | | | LINE2:pl_avg#202020:"avg" \ |
213 | | | --vertical-label "Packet loss [%]" \ |
214 | | | --height 200 \ |
215 | | | --width ${width} \ |
216 | | | ${xgridstr} \ |
217 | | | --title "${name} ${popis}" \ |
218 | | | --lower-limit 0 \ |
219 | | | --upper-limit 5 |
220 | | | } |
221 | | | |
222 | | | function pktloss_avgavg() |
223 | | | { |
224 | | | rrdtool graph ${target_img_dir}/ping_${name}_pktloss_${suffix}.png --imgformat PNG --start $(($now-${timediff})) --end $now \ |
225 | | | DEF:pl_avg=${name}.rrd:pktloss:AVERAGE \ |
226 | | | CDEF:avg1=PREV\(pl_avg\) \ |
227 | | | CDEF:avg2=PREV\(avg1\) \ |
228 | | | CDEF:prumer_pktloss=pl_avg,avg1,avg2,+,+,3,/ \ |
229 | | | HRULE:5#000000 \ |
230 | | | AREA:avg1#FFa1a1:"presne" \ |
231 | | | LINE2:prumer_pktloss#202020:"prumer" \ |
232 | | | --vertical-label "Packet loss [%]" \ |
233 | | | --height 200 \ |
234 | | | --width ${width} \ |
235 | | | ${xgridstr} \ |
236 | | | --title "${name} ${popis}" \ |
237 | | | --lower-limit 0 \ |
238 | | | --upper-limit 5 |
239 | | | } |
240 | | | |
241 | | | if [ $timediff -le 21600 ] |
242 | | | then |
243 | | | rtt_prime_nekonsolidovane_hodnoty |
244 | | | pktloss_prime_nekonsolidovane_hodnoty |
245 | | | else |
246 | | | if [ $timediff -le 108000 ] |
247 | | | then |
248 | | | # rtt_mean_deviation_maxavg |
249 | | | rtt_avg_peak |
250 | | | pktloss_avgavg |
251 | | | else |
252 | | | flow_graph |
253 | | | fi |
254 | | | fi |