1 | 1 | simandl | #!/bin/bash |
2 | | | |
3 | | | name=mpstat |
4 | | | timediff=$1 |
5 | | | suffix=$2 |
6 | | | popis=$3 |
7 | | | width=$4 |
8 | | | |
9 | | | PATH=$PATH:/opt/rrdtool/bin |
10 | | | |
11 | | | datadir=/var/statistiky/system |
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 | | | if [ $timediff -gt 7200 ] |
30 | | | then |
31 | | | |
32 | | | for stat in user nice system iowait irq softirq idle intrs |
33 | | | do |
34 | | | rrdtool graph ${target_img_dir}/${name}_${stat}_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \ |
35 | | | DEF:avg_value=${name}.rrd:${stat}:AVERAGE \ |
36 | | | DEF:min_value=${name}.rrd:${stat}:MIN \ |
37 | | | DEF:max_value=${name}.rrd:${stat}:MAX \ |
38 | | | CDEF:avg1=PREV\(avg_value\) \ |
39 | | | CDEF:avg2=PREV\(avg1\) \ |
40 | | | CDEF:min1=PREV\(min_value\) \ |
41 | | | CDEF:max1=PREV\(max_value\) \ |
42 | | | CDEF:prumer_avg=avg_value,avg1,avg2,+,+,3,/ \ |
43 | | | CDEF:maxmin=max1,min1,- \ |
44 | | | AREA:min1#FFFFFF \ |
45 | | | STACK:maxmin#e0e0e0 \ |
46 | | | LINE1:max1#FFa1a1:"max" \ |
47 | | | LINE1:min1#a8a8FF:"min" \ |
48 | | | LINE2:prumer_avg#202020:"avg" \ |
49 | | | --vertical-label "CPU time [%]" \ |
50 | | | --height 200 \ |
51 | | | --width ${width} \ |
52 | | | ${xgridstr} \ |
53 | | | --title "${stat} ${name} ${popis}" |
54 | | | done |
55 | | | |
56 | | | else |
57 | | | |
58 | | | for stat in user nice system iowait irq softirq idle intrs |
59 | | | do |
60 | | | rrdtool graph ${target_img_dir}/${name}_${stat}_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \ |
61 | | | DEF:value=${name}.rrd:${stat}:MAX \ |
62 | | | LINE1:value#000000 \ |
63 | | | --vertical-label "CPU time [%]" \ |
64 | | | --height 200 \ |
65 | | | --width ${width} \ |
66 | | | ${xgridstr} \ |
67 | | | --title "${stat} ${name} ${popis}" |
68 | | | done |
69 | | | |
70 | | | fi |
71 | | | |