![]() ![]() |
crusader |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/bin/bashPATH=/opt/rrdtool/bin:$PATH:/sbinstat_dir="/var/statistiky/rates"mkdir -p $stat_dirconfig_file=/opt/statistiky/collect_rates.confif [ ! -f $cwd/$config_file ]thenecho "Missing config file $config_file"exit 1;ficd $stat_dirfunction create()# $1 ... netdevice{local device=$1echo "Creating device $device"# 20s ~ agregace ze ctyr hodnot (PDP)# za poslednich 16 hodin chceme 20s udaje => 16*3600/20 = 2880 generaci/radku# 5 minut = 12 PDP za minutu * 5 minut = 60 PDP# za posledni tyden chceme 5minutove udaje => 12*24*9 = 2592 radku (rows)# 20min ~ agregace z 240 PDP# za posledni mesic chceme 20minutove useky => 3*24*38 = 2736 radku# dve hodiny ~ 1440 PDP# za posledni rok chceme dvouhodinove useky => 12*400 = 4800 radkurrdtool create ${device}.rrd --step 5 --start `date +%s` \DS:input:COUNTER:10:0:10000000 \DS:output:COUNTER:10:0:10000000 \RRA:AVERAGE:0.7:1:1440 \RRA:MAX:0.7:4:2880 \RRA:MIN:0.7:4:2880 \RRA:AVERAGE:0.7:4:2880 \RRA:MAX:0.7:60:2592 \RRA:MIN:0.7:60:2592 \RRA:AVERAGE:0.7:60:2592 \RRA:MAX:0.7:240:2736 \RRA:MIN:0.7:240:2736 \RRA:AVERAGE:0.7:240:2736 \RRA:MAX:0.7:1440:4800 \RRA:MIN:0.7:1440:4800 \RRA:AVERAGE:0.7:1440:4800}function wait_to()# $1 date for waiting to{local time_now=`date +%s`;while [ $time_now -lt $1 ]dotime_now=`date +%s`sleep 1;done}# first time rrd files initialization. ${config_file}do_sleep="no"for device in $RATES_DEVICES; doif [ ! -f $device.rrd ] ; thencreate $devicedo_sleep="yes"fidoneif [ "$do_sleep" == "yes" ]; thensleep 5fiunset do_sleepstart_time=`date +%s`interval=$(( $start_time / 5 * 5 + 5 ))while [ true ] ; do. ${config_file}wait_to $intervalfor device in $RATES_DEVICES; doif [ ! -f $device.rrd ] ; thencreate $device# first measurement will be in the next roundcontinue;fitimenow=`date +%s`dev=`cat /proc/net/dev | grep $device`values=`echo $dev | cut -d ':' -f 2`rxbytes=`echo $values | awk '{print $1;}'`txbytes=`echo $values | awk '{print $9;}'`if [ ! -z "${rxbytes}" ] && [ ! -z "${txbytes}" ]; thenrrdtool update $device.rrd $interval:$rxbytes:$txbytesfidone# compute aggregated valuesif [ ! -z "$AGG_NAME" ]; thenif [ ! -f $AGG_NAME.rrd ] ; thencreate $AGG_NAME# first measurement will be in the next roundcontinue;fitimenow=`date +%s`rxbytes="0"txbytes="0"for device in $AGG_DEVICES; dodev=`cat /proc/net/dev | grep $device`echo $devvalues=`echo $dev | cut -d ':' -f 2`echo $valueslet rxbytes=$rxbytes+`echo $values | awk '{print $1;}'`let txbytes=$txbytes+`echo $values | awk '{print $9;}'`echo rxbtres $rxbytesecho txbytes $txbytesdoneif [ ! -z "${rxbytes}" ] && [ ! -z "${txbytes}" ]; thenrrdtool update $AGG_NAME.rrd $interval:$rxbytes:$txbytesfifiinterval=$(( $interval + 5 ))done