1 | 1 | simandl | #!/bin/bash |
2 | | | |
3 | | | name=crusader$1 |
4 | | | timediff=$2 |
5 | | | suffix=$3 |
6 | | | popis=$4 |
7 | | | width=$5 |
8 | | | |
9 | | | PATH=$PATH:/opt/rrdtool/bin |
10 | | | |
11 | | | datadir=/var/statistiky/crusader |
12 | | | target_img_dir="/var/www/heaven/stat/img" |
13 | | | |
14 | | | cd $datadir |
15 | | | |
16 | | | xgridstr="" |
17 | | | |
18 | | | if [ $timediff -ge 604800 ] |
19 | | | then |
20 | | | xgridstr="--x-grid HOUR:12:DAY:1:DAY:1:86400:%d.%m." |
21 | | | fi |
22 | | | if [ $timediff -ge 2678400 ] |
23 | | | then |
24 | | | xgridstr="--x-grid DAY:1:DAY:7:DAY:2:86400:%d.%m." |
25 | | | fi |
26 | | | |
27 | | | now=`date +%s` |
28 | | | |
29 | | | function simple_graph() |
30 | | | { |
31 | | | rrdtool graph ${target_img_dir}/${name}_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \ |
32 | | | DEF:rss_min=${name}.rrd:rss:MIN \ |
33 | | | DEF:rss_max=${name}.rrd:rss:MAX \ |
34 | | | DEF:rss_avg=${name}.rrd:rss:AVERAGE \ |
35 | | | LINE1:rss_max#FF0000:"max" \ |
36 | | | AREA:rss_avg#a0a0a0:"avg" \ |
37 | | | LINE1:rss_min#0000FF:"min" \ |
38 | | | --vertical-label "RSS" \ |
39 | | | --height 200 \ |
40 | | | --width ${width} \ |
41 | | | --title "${name} ${popis}" |
42 | | | } |
43 | | | |
44 | | | # detekce UNKNOWN |
45 | | | # CDEF:offline=prumer_avg,UN,INF,0,IF \ |
46 | | | # AREA:offline#f3ff73 \ |
47 | | | |
48 | | | |
49 | | | function flow_graph() |
50 | | | { |
51 | | | rrdtool graph ${target_img_dir}/${name}_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \ |
52 | | | DEF:rss_avg=${name}.rrd:rss_avg:AVERAGE \ |
53 | | | DEF:rss_min=${name}.rrd:rss_min:MIN \ |
54 | | | DEF:rss_max=${name}.rrd:rss_max:MAX \ |
55 | | | CDEF:avg1=PREV\(rss_avg\) \ |
56 | | | CDEF:avg2=PREV\(avg1\) \ |
57 | | | CDEF:min1=PREV\(rss_min\) \ |
58 | | | CDEF:max1=PREV\(rss_max\) \ |
59 | | | CDEF:prumer_avg=rss_avg,avg1,avg2,+,+,3,/ \ |
60 | | | CDEF:maxmin=max1,min1,- \ |
61 | | | HRULE:400#FF0000 \ |
62 | | | HRULE:450#00BB00 \ |
63 | | | AREA:min1#FFFFFF \ |
64 | | | STACK:maxmin#e0e0e0 \ |
65 | | | LINE1:max1#FFa1a1:"max" \ |
66 | | | LINE1:min1#a8a8FF:"min" \ |
67 | | | LINE2:prumer_avg#202020:"avg" \ |
68 | | | --vertical-label "RSS" \ |
69 | | | --height 200 \ |
70 | | | --width ${width} \ |
71 | | | ${xgridstr} \ |
72 | | | --title "Sila signalu ${name} ${popis}" |
73 | | | } |
74 | | | |
75 | | | #if [ $timediff -lt 86400 ] |
76 | | | if [ $timediff -eq 9000 ] |
77 | | | then |
78 | | | rrdtool graph ${target_img_dir}/${name}_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \ |
79 | | | DEF:rss_avg=${name}.rrd:rss_avg:AVERAGE \ |
80 | | | DEF:rss_min=${name}.rrd:rss_min:MIN \ |
81 | | | DEF:rss_max=${name}.rrd:rss_max:MAX \ |
82 | | | CDEF:maxmin=rss_max,rss_min,- \ |
83 | | | HRULE:0#000000 \ |
84 | | | AREA:rss_min#FFFFFF \ |
85 | | | STACK:maxmin#e0e0e0 \ |
86 | | | LINE1:rss_min#a8a8FF:"min" \ |
87 | | | LINE1:rss_max#FFa1a1:"max" \ |
88 | | | LINE1:rss_avg#202020:"avg" \ |
89 | | | --vertical-label "RSS" \ |
90 | | | --height 800 \ |
91 | | | --width ${width} \ |
92 | | | ${xgridstr} \ |
93 | | | --title "Sila signalu ${name} ${popis}" |
94 | | | else |
95 | | | flow_graph |
96 | | | fi |