jablonka.czprosek.czf

crusader

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

 

Line No. Rev Author Line
11simandl#!/bin/bash
2 
3PATH=/opt/rrdtool/bin:$PATH:/sbin
4 
5stat_dir="/var/statistiky/rates"
6mkdir -p $stat_dir
7 
8config_file=/opt/statistiky/collect_rates.conf
9 
10if [ ! -f $cwd/$config_file ]
11then
12 echo "Missing config file $config_file"
13 exit 1;
14fi
15 
16cd $stat_dir
17 
18function create()
19# $1 ... netdevice
20{
21 local device=$1
22 echo "Creating device $device"
23 
24# 20s ~ agregace ze ctyr hodnot (PDP)
25# za poslednich 16 hodin chceme 20s udaje => 16*3600/20 = 2880 generaci/radku
26# 5 minut = 12 PDP za minutu * 5 minut = 60 PDP
27# za posledni tyden chceme 5minutove udaje => 12*24*9 = 2592 radku (rows)
28# 20min ~ agregace z 240 PDP
29# za posledni mesic chceme 20minutove useky => 3*24*38 = 2736 radku
30# dve hodiny ~ 1440 PDP
31# za posledni rok chceme dvouhodinove useky => 12*400 = 4800 radku
32 
33rrdtool create ${device}.rrd --step 5 --start `date +%s` \
34 DS:input:COUNTER:10:0:U \
35 DS:output:COUNTER:10:0:U \
36 RRA:AVERAGE:0.7:1:1440 \
37 RRA:MAX:0.7:4:2880 \
38 RRA:MIN:0.7:4:2880 \
39 RRA:AVERAGE:0.7:4:2880 \
40 RRA:MAX:0.7:60:2592 \
41 RRA:MIN:0.7:60:2592 \
42 RRA:AVERAGE:0.7:60:2592 \
43 RRA:MAX:0.7:240:2736 \
44 RRA:MIN:0.7:240:2736 \
45 RRA:AVERAGE:0.7:240:2736 \
46 RRA:MAX:0.7:1440:4800 \
47 RRA:MIN:0.7:1440:4800 \
48 RRA:AVERAGE:0.7:1440:4800
49 
50}
51 
52while [ true ] ; do
53 
54 . ${config_file}
55 
56 for device in $RATES_DEVICES; do
57 
58 if [ ! -f $device.rrd ] ; then
59 create $device
60 sleep 1;
61 fi
62 logfile="$stat_dir/traffic.$device"
63 if [ ! -f $logfile ] ; then
64 echo "UNIX time IN bytes OUT bytes" >$logfile
65 echo "-----------------------------------------" >>$logfile
66 fi
67 timenow=`date +%s`
68 dev=`cat /proc/net/dev | grep $device`
69 values=`echo $dev | cut -d ':' -f 2`
70 rxbytes=`echo $values | awk '{print $1;}'`
71 txbytes=`echo $values | awk '{print $9;}'`
72 
73 if [ ! -z "${rxbytes}" ] && [ ! -z "${txbytes}" ]; then
74 rrdtool update $device.rrd $timenow:$rxbytes:$txbytes
75 fi
76 done
77 sleep 5;
78done

Powered by WebSVN 2.2.1