crusader |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/bin/bash
PATH=/opt/rrdtool/bin:$PATH:/sbin:/usr/sbin
data_dir="/var/statistiky/arp"
mkdir -p $data_dir
cd ${data_dir}
config_file=/opt/statistiky/collect_arp.conf
function create()
{
local filename=$1
echo " creating new arp2.rrd"
# zakladem je krok 5 sekund
# petiminutove useky se pocitaji z 60 PDP (primary data points) (12 za minutu * 5 minut)
# vsechny RRA se pocitaji primo z PDP, tj. dvouhodinove useky se pocitaji z 240 PDP
# za posledni tyden chceme 5minutove useky udaje => 12*24*9 = 2592 radku
# za posledni mesic chceme 20minutove useky => 3*24*38 = 2736 radku
# za posledni rok chceme dvouhodinove useky => 12*400 = 4800 radku
rrdtool create ${filename}.rrd --step 5 --start `date +%s` \
DS:count:GAUGE:10:0:100 \
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
}
echo "Looking for arp.rrd"
if [ ! -f arp.rrd ] ; then
create arp
fi
sleep 2;
start_time=`date +%s`
interval=$(( $start_time / 5 * 5 + 5 ))
while [ true ]
do
. ${config_file}
echo "Wait to $interval"
wait_to $interval
timenow=`date +%s`
echo "Time now: `date +%s`"
count="0"
for net_dev in $DEVICES
do
count_dev=$(( `arp -n -i $net_dev | grep ether | grep -v "192.168" | wc -l` + 0 ))
echo " items in arp table $net_dev: $count_dev"
let count+=$count_dev
done
echo "All items in arp table : $count"
if [ ! -z "${count}" ]
then
rrdtool update arp.rrd $timenow:$count
fi
interval=$(( $interval + 5 ))
done