1 | 1 | simandl | #!/bin/bash |
2 | | | |
3 | | | PATH=/opt/rrdtool/bin:$PATH:/sbin:/usr/sbin |
4 | | | |
5 | | | data_dir="/var/statistiky/arp" |
6 | | | mkdir -p $data_dir |
7 | | | |
8 | | | cd ${data_dir} |
9 | | | |
10 | | | config_file=/opt/statistiky/collect_arp.conf |
11 | | | |
12 | | | function create() |
13 | | | { |
14 | | | local filename=$1 |
15 | | | echo " creating new arp2.rrd" |
16 | | | |
17 | | | # zakladem je krok 5 sekund |
18 | | | # petiminutove useky se pocitaji z 60 PDP (primary data points) (12 za minutu * 5 minut) |
19 | | | # vsechny RRA se pocitaji primo z PDP, tj. dvouhodinove useky se pocitaji z 240 PDP |
20 | | | # za posledni tyden chceme 5minutove useky udaje => 12*24*9 = 2592 radku |
21 | | | # za posledni mesic chceme 20minutove useky => 3*24*38 = 2736 radku |
22 | | | # za posledni rok chceme dvouhodinove useky => 12*400 = 4800 radku |
23 | | | rrdtool create ${filename}.rrd --step 5 --start `date +%s` \ |
24 | | | DS:count:GAUGE:10:0:100 \ |
25 | | | RRA:AVERAGE:0.7:1:1440 \ |
26 | | | RRA:MAX:0.7:4:2880 \ |
27 | | | RRA:MIN:0.7:4:2880 \ |
28 | | | RRA:AVERAGE:0.7:4:2880 \ |
29 | | | RRA:MAX:0.7:60:2592 \ |
30 | | | RRA:MIN:0.7:60:2592 \ |
31 | | | RRA:AVERAGE:0.7:60:2592 \ |
32 | | | RRA:MAX:0.7:240:2736 \ |
33 | | | RRA:MIN:0.7:240:2736 \ |
34 | | | RRA:AVERAGE:0.7:240:2736 \ |
35 | | | RRA:MAX:0.7:1440:4800 \ |
36 | | | RRA:MIN:0.7:1440:4800 \ |
37 | | | RRA:AVERAGE:0.7:1440:4800 |
38 | | | |
39 | | | } |
40 | | | |
41 | | | function wait_to() |
42 | | | # $1 date for waiting to |
43 | | | { |
44 | | | local time_now=`date +%s`; |
45 | | | while [ $time_now -lt $1 ] |
46 | | | do |
47 | | | time_now=`date +%s` |
48 | | | sleep 1; |
49 | | | done |
50 | | | } |
51 | | | |
52 | | | echo "Looking for arp.rrd" |
53 | | | if [ ! -f arp.rrd ] ; then |
54 | | | create arp |
55 | | | fi |
56 | | | sleep 2; |
57 | | | |
58 | | | |
59 | | | start_time=`date +%s` |
60 | | | interval=$(( $start_time / 5 * 5 + 5 )) |
61 | | | |
62 | | | while [ true ] |
63 | | | do |
64 | | | . ${config_file} |
65 | | | |
66 | | | echo "Wait to $interval" |
67 | | | wait_to $interval |
68 | | | timenow=`date +%s` |
69 | | | echo "Time now: `date +%s`" |
70 | | | |
71 | | | count="0" |
72 | | | for net_dev in $DEVICES |
73 | | | do |
74 | | | count_dev=$(( `arp -n -i $net_dev | grep ether | grep -v "192.168" | wc -l` + 0 )) |
75 | | | echo " items in arp table $net_dev: $count_dev" |
76 | | | let count+=$count_dev |
77 | | | done |
78 | | | echo "All items in arp table : $count" |
79 | | | |
80 | | | |
81 | | | if [ ! -z "${count}" ] |
82 | | | then |
83 | | | rrdtool update arp.rrd $timenow:$count |
84 | | | fi |
85 | | | |
86 | | | interval=$(( $interval + 5 )) |
87 | | | |
88 | | | done |
89 | | | |