#!/bin/bash PATH=/opt/rrdtool/bin:$PATH:/sbin stat_dir="/var/statistiky/rates" mkdir -p $stat_dir config_file=/opt/statistiky/collect_rates.conf if [ ! -f $cwd/$config_file ] then echo "Missing config file $config_file" exit 1; fi cd $stat_dir function create() # $1 ... netdevice { local device=$1 echo "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 radku rrdtool 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 ] do time_now=`date +%s` sleep 1; done } # first time rrd files initialization . ${config_file} do_sleep="no" for device in $RATES_DEVICES; do if [ ! -f $device.rrd ] ; then create $device do_sleep="yes" fi done if [ "$do_sleep" == "yes" ]; then sleep 5 fi unset do_sleep start_time=`date +%s` interval=$(( $start_time / 5 * 5 + 5 )) while [ true ] ; do . ${config_file} wait_to $interval for device in $RATES_DEVICES; do if [ ! -f $device.rrd ] ; then create $device # first measurement will be in the next round continue; fi timenow=`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}" ]; then rrdtool update $device.rrd $interval:$rxbytes:$txbytes fi done # compute aggregated values if [ ! -z "$AGG_NAME" ]; then if [ ! -f $AGG_NAME.rrd ] ; then create $AGG_NAME # first measurement will be in the next round continue; fi timenow=`date +%s` rxbytes="0" txbytes="0" for device in $AGG_DEVICES; do dev=`cat /proc/net/dev | grep $device` echo $dev values=`echo $dev | cut -d ':' -f 2` echo $values let rxbytes=$rxbytes+`echo $values | awk '{print $1;}'` let txbytes=$txbytes+`echo $values | awk '{print $9;}'` echo rxbtres $rxbytes echo txbytes $txbytes done if [ ! -z "${rxbytes}" ] && [ ! -z "${txbytes}" ]; then rrdtool update $AGG_NAME.rrd $interval:$rxbytes:$txbytes fi fi interval=$(( $interval + 5 )) done WebSVN - crusader - Blame - Rev 1 - /trunk/statistiky/opt/statistiky/collect_rates.sh
  jablonka.czprosek.czf

crusader

Subversion Repositories:
[/] [trunk/] [statistiky/] [opt/] [statistiky/] [collect_rates.sh] - Blame information for rev 1

 

Line No. Rev Author Line

Powered by WebSVN 2.2.1