| 1 | 1 | simandl | #!/bin/bash |
| 2 | | | |
| 3 | | | device=$1 |
| 4 | | | timediff=$2 |
| 5 | | | suffix=$3 |
| 6 | | | popis=$4 |
| 7 | | | |
| 8 | | | if [ $# -ge 5 ] |
| 9 | | | then |
| 10 | | | width=$5 |
| 11 | | | else |
| 12 | | | width=400 |
| 13 | | | fi |
| 14 | | | |
| 15 | | | hrule_in="" |
| 16 | | | hrule_out="" |
| 17 | | | if [ $# -ge 6 ] && [ $6 -gt 0 ] |
| 18 | | | then |
| 19 | | | hrule_in="HRULE:$6#00a000" |
| 20 | | | hrule_out="HRULE:-$6#00a000" |
| 21 | | | fi |
| 22 | | | |
| 23 | | | PATH=$PATH:/opt/rrdtool/bin |
| 24 | | | |
| 25 | | | datadir=/var/statistiky/rates |
| 26 | | | target_img_dir="/var/www/heaven/stat/img" |
| 27 | | | |
| 28 | | | cd $datadir |
| 29 | | | |
| 30 | | | now=`date +%s` |
| 31 | | | |
| 32 | | | if [ $timediff -ge 604800 ] |
| 33 | | | then |
| 34 | | | xgridstr="--x-grid HOUR:12:DAY:1:DAY:1:86400:%d.%m." |
| 35 | | | else |
| 36 | | | xgridstr="" |
| 37 | | | fi |
| 38 | | | |
| 39 | | | |
| 40 | | | rrdtool graph ${target_img_dir}/${device}_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \ |
| 41 | | | DEF:inbps=${device}.rrd:input:AVERAGE \ |
| 42 | | | DEF:inbps_max=${device}.rrd:input:MAX \ |
| 43 | | | DEF:outbps=${device}.rrd:output:AVERAGE \ |
| 44 | | | DEF:outbps_max=${device}.rrd:output:MAX \ |
| 45 | | | CDEF:in1=PREV\(inbps\) \ |
| 46 | | | CDEF:in2=PREV\(in1\) \ |
| 47 | | | CDEF:out1=PREV\(outbps\) \ |
| 48 | | | CDEF:out2=PREV\(out1\) \ |
| 49 | | | CDEF:inbps_max1=PREV\(inbps_max\),8,* \ |
| 50 | | | CDEF:inbps_max2=PREV\(inbps_max1\) \ |
| 51 | | | CDEF:outbps_max1=PREV\(outbps_max\),8,* \ |
| 52 | | | CDEF:outbps_max2=PREV\(outbps_max1\) \ |
| 53 | | | CDEF:inbps_out=inbps,in1,in2,+,+,3,/,8,* \ |
| 54 | | | CDEF:inbps_max_out=inbps_max,inbps_max1,inbps_max2,MAX,MAX,inbps_out,- \ |
| 55 | | | CDEF:in_max_diff=inbps_max1,inbps_out,- \ |
| 56 | | | CDEF:outbps_out=outbps,out1,out2,+,+,3,/,-1,*,8,* \ |
| 57 | | | CDEF:out_max_diff=outbps_max1,-1,*,outbps_out,- \ |
| 58 | | | $hrule_in $hrule_out \ |
| 59 | | | CDEF:outbps_max_out=outbps_max,outbps_max1,outbps_max2,MAX,MAX,-1,*,outbps_out,- \ |
| 60 | | | AREA:inbps_out#ffa1a1 \ |
| 61 | | | STACK:in_max_diff#ffd8d8 \ |
| 62 | | | LINE2:inbps_out#FF0000:"In traffic" \ |
| 63 | | | AREA:outbps_out#a8a8ff \ |
| 64 | | | STACK:out_max_diff#d8d8ff \ |
| 65 | | | LINE2:outbps_out#0000FF:"Out traffic" \ |
| 66 | | | --vertical-label bit/s \ |
| 67 | | | --height 250 \ |
| 68 | | | --width $width \ |
| 69 | | | ${xgridstr} \ |
| 70 | | | --title "${device} ${popis}" |