crusader |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/bin/bash
if [ $# -lt 4 ]
then
echo "Usage: `basename $0` <target name> <time interval> <file suffix> <graph comment> [graph width]"
exit 1;
fi
name=$1
timediff=$2
suffix=$3
popis=$4
if [ $# -ge 5 ]
then
width=$5
else
width=400
fi
PATH=$PATH:/opt/rrdtool/bin
datadir="/var/statistiky/ping"
target_img_dir="/var/www/heaven/stat/img"
cd $datadir
now=`date +%s`
if [ $timediff -ge 604800 ]
then
xgridstr="--x-grid HOUR:12:DAY:1:DAY:1:86400:%d.%m."
else
xgridstr=""
fi
function flow_graph()
{
rrdtool graph ${target_img_dir}/ping_${name}_rtt_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \
DEF:rttmin=${name}.rrd:rttmin:MIN \
DEF:rttmax=${name}.rrd:rttmax:MAX \
DEF:rttavg=${name}.rrd:rttavg:AVERAGE \
DEF:rttmdev=${name}.rrd:rttmdev:AVERAGE \
CDEF:avg1=PREV\(rttavg\) \
CDEF:avg2=PREV\(avg1\) \
CDEF:min1=PREV\(rttmin\) \
CDEF:min2=PREV\(min1\) \
CDEF:max1=PREV\(rttmax\) \
CDEF:max2=PREV\(max1\) \
CDEF:mdev1=PREV\(rttmdev\) \
CDEF:mdev2=PREV\(mdev1\) \
CDEF:prumer_rttavg=rttavg,avg1,avg2,+,+,3,/ \
CDEF:prumer_rttmdev=rttmdev,mdev1,mdev2,+,+,3,/ \
CDEF:maxmin=rttmax,rttmin,- \
AREA:rttmin#FFFFFF \
STACK:maxmin#e0e0e0 \
LINE1:rttmax#FFa1a1:"max" \
LINE1:rttmin#a8a8FF:"min" \
LINE2:prumer_rttavg#202020:"avg" \
--vertical-label "Round Trip Time [ms]" \
--height 200 \
--width ${width} \
${xgridstr} \
--title "${name} ${popis}" \
--lower-limit 0 \
--upper-limit 1
rrdtool graph ${target_img_dir}/ping_${name}_pktloss_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \
DEF:pl_avg=${name}.rrd:pktloss:AVERAGE \
DEF:pl_min=${name}.rrd:pktloss:MIN \
DEF:pl_max=${name}.rrd:pktloss:MAX \
CDEF:avg1=PREV\(pl_avg\) \
CDEF:avg2=PREV\(avg1\) \
CDEF:min1=PREV\(pl_min\) \
CDEF:min2=PREV\(min1\) \
CDEF:max1=PREV\(pl_max\) \
CDEF:max2=PREV\(max1\) \
CDEF:prumer_pktloss=pl_avg,avg1,avg2,+,+,3,/ \
CDEF:maxmin=pl_max,pl_min,- \
HRULE:5#000000 \
AREA:pl_min#FFFFFF \
STACK:maxmin#e0e0e0 \
LINE1:pl_max#FFa1a1:"max" \
LINE1:pl_min#a8a8FF:"min" \
LINE2:prumer_pktloss#202020:"avg" \
--vertical-label "Packet loss [%]" \
--height 200 \
--width ${width} \
${xgridstr} \
--title "${name} ${popis}" \
--lower-limit 0 \
--upper-limit 5
}
function flow_graph_7200()
{
rrdtool graph ${target_img_dir}/ping_${name}_rtt_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \
DEF:rttavg=${name}.rrd:rttavg:AVERAGE \
DEF:rttmdev=${name}.rrd:rttmdev:AVERAGE \
CDEF:avg1=PREV\(rttavg\) \
CDEF:avg2=PREV\(avg1\) \
CDEF:min_agg=rttavg,avg1,avg2,MIN,MIN \
CDEF:max_agg=rttavg,avg1,avg2,MAX,MAX \
CDEF:mdev1=PREV\(rttmdev\) \
CDEF:mdev2=PREV\(mdev1\) \
CDEF:prumer_rttavg=rttavg,avg1,avg2,+,+,3,/ \
CDEF:prumer_rttmdev=rttmdev,mdev1,mdev2,+,+,3,/ \
CDEF:maxmin=max_agg,min_agg,- \
AREA:min_agg#FFFFFF \
STACK:maxmin#e0e0e0 \
LINE1:max_agg#FFa1a1:"max" \
LINE1:min_agg#a8a8FF:"min" \
LINE2:prumer_rttavg#202020:"avg" \
--vertical-label "Round Trip Time [ms]" \
--height 200 \
--width ${width} \
${xgridstr} \
--title "${name} ${popis}" \
--lower-limit 0 \
--upper-limit 1
rrdtool graph ${target_img_dir}/ping_${name}_pktloss_${suffix}.png --imgformat PNG --start `expr $now - ${timediff}` --end $now \
DEF:pl_avg=${name}.rrd:pktloss:AVERAGE \
CDEF:avg1=PREV\(pl_avg\) \
CDEF:avg2=PREV\(avg1\) \
CDEF:min_agg=pl_avg,avg1,avg2,MIN,MIN \
CDEF:max_agg=pl_avg,avg1,avg2,MAX,MAX \
CDEF:prumer_pktloss=pl_avg,avg1,avg2,+,+,3,/ \
CDEF:maxmin=max_agg,min_agg,- \
HRULE:5#000000 \
AREA:min_agg#FFFFFF \
STACK:maxmin#e0e0e0 \
LINE1:max_agg#FFa1a1:"max" \
LINE1:min_agg#a8a8FF:"min" \
LINE2:prumer_pktloss#202020:"avg" \
--vertical-label "Packet loss [%]" \
--height 200 \
--width ${width} \
${xgridstr} \
--title "${name} ${popis}" \
--lower-limit 0 \
--upper-limit 5
}
if [ $timediff -lt 86400 ]
then
flow_graph_7200
else
flow_graph
fi