#!/bin/sh rrdtool=/usr/bin RRD_DB_DIR=/opt/rrd_db/ RRD_DB_FILE=/opt/rrd_db/eth0-stream.rrd RRD_DB_PIC=/opt/rrd_pic/ NOW=`date +%s` MONTH_IN_SEC=2629743 MONTH_AGO=$(($NOW-$MONTH_IN_SEC)) ONE_QUARTER_AGO=$(($NOW-900)) ONE_HOUR_AGO=$(($NOW-3600)) ONE_DAY_AGO=$(($NOW-86400)) ONE_WEEK_AGO=$(($NOW-604800)) ONE_MONTH_AGO=$(($NOW-2629743)) ONE_YEAR_AGO=$(($NOW-31556926)) do_rrdgraph(){ if [ $2 = "quarter" ] then echo quarter flag=MINUTE:1:MINUTE:3:MINUTE:3:0:"%H:%M" elif [ $2 = "hour" ] then echo hour flag=MINUTE:3:MINUTE:6:MINUTE:6:0:"%H:%M" elif [ $2 = "day" ] then echo day flag=MINUTE:30:HOUR:1:HOUR:2:0:"%H:%M" elif [ $2 = "week" ] then echo week flag=DAY:1:DAY:2:DAY:1:0:"%m/%d" elif [ $2 = "month" ] then echo month flag=DAY:1:DAY:3:DAY:3:0:"%m/%d" elif [ $2 = "year" ] then echo year flag=MONTH:1:MONTH:2:MONTH:2:0:"%Y/%m" fi if [[ $3 != "" ]] then echo "resolution=$3" resolution="-S $3" else echo "resolution=300" resolution="-S 300" fi $rrdtool/rrdtool graph "${RRD_DB_PIC}eth0-stream_$2.png" -s $1 -h 120 -w 500 -a PNG ${resolution} -t "Stream of eth0 (last $2)" \ -v bytes \ --lower-limit=0 \ --units-exponent 0 \ --rigid \ --x-grid ${flag} \ DEF:a="$RRD_DB_FILE":eth0_in:AVERAGE \ DEF:b="$RRD_DB_FILE":eth0_out:AVERAGE \ LINE1:a#003300:"eth0_in. \: " \ GPRINT:a:AVERAGE:"%.2lf" \ LINE1:b#9900FF:"eth0_out. \:" \ GPRINT:b:AVERAGE:"%.2lf" } if [ -e "$RRD_DB_FILE" ] then echo "file exits: $RRD_DB_FILE" VALUE=$(cat /proc/net/dev|grep eth0|sed 's/^.*://'|awk '{print $1":"$9}') $rrdtool/rrdtool updatev $RRD_DB_FILE N:${VALUE} do_rrdgraph $ONE_QUARTER_AGO quarter do_rrdgraph $ONE_HOUR_AGO hour do_rrdgraph $ONE_DAY_AGO day 600 do_rrdgraph $ONE_WEEK_AGO week 600 do_rrdgraph $ONE_MONTH_AGO month 600 do_rrdgraph $ONE_YEAR_AGO year 1800 else $rrdtool/rrdtool create $RRD_DB_FILE --step 300 \ DS:eth0_in:COUNTER:600:0:12500000 \ DS:eth0_out:COUNTER:600:0:12500000 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:4:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 echo "file created:$RRD_DB_FILE" fi