![]() ![]() |
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:U \DS:output:COUNTER:10:0:U \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}while [ true ] ; do. ${config_file}for device in $RATES_DEVICES; doif [ ! -f $device.rrd ] ; thencreate $devicesleep 1;filogfile="$stat_dir/traffic.$device"if [ ! -f $logfile ] ; thenecho "UNIX time IN bytes OUT bytes" >$logfileecho "-----------------------------------------" >>$logfilefitimenow=`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 $timenow:$rxbytes:$txbytesfidonesleep 5;done