jablonka.czprosek.czf

crusader

Subversion Repositories:
[/] [trunk/] [statistiky/] [opt/] [statistiky/] [archiv/] [collect_rates.sh.20051013] - Rev 1

Compare with Previous - Blame - Download


#!/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: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; do

        if [ ! -f $device.rrd ] ; then
            create $device
            sleep 1;
        fi
        logfile="$stat_dir/traffic.$device"
        if [ ! -f $logfile ] ; then
            echo "UNIX time     IN bytes       OUT bytes" >$logfile
            echo "-----------------------------------------" >>$logfile
        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 $timenow:$rxbytes:$txbytes
        fi
    done
    sleep 5;
done

Powered by WebSVN 2.2.1