File: maint.weekly

package info (click to toggle)
bandwidthd 2.0.1%2Bcvs20090917-10
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,204 kB
  • sloc: sh: 3,008; ansic: 2,746; php: 1,263; yacc: 216; makefile: 162; lex: 36; sql: 27
file content (53 lines) | stat: -rwxr-xr-x 2,415 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
echo "SET sort_mem TO 45000;"
echo -e "bd_rx_log \n bd_tx_log \n bd_rx_total_log \n bd_tx_total_log" | while read TABLE; 
do
cat << EOF
BEGIN;
insert into $TABLE (sensor_id, ip, timestamp, sample_duration, packet_count, total, icmp, udp, tcp, ftp, http, p2p) 
select sensor_id, ip, 
date_trunc('day', timestamp) + (case when extract(hour from timestamp) >= 12 then interval '12 hours' 
else interval '0 hours' end) + interval '12 hours',
60*60*12, sum(packet_count), sum(total), sum(icmp), sum(udp), sum(tcp), sum(ftp), sum(http), sum(p2p)

from $TABLE
where sample_duration < 60*60*12
and timestamp < now() - interval '35 days'
group by sensor_id, ip, 
date_trunc('day', timestamp) + (case when extract(hour from timestamp) >= 12 then interval '12 hours'
else interval '0 hours' end);                                                                                                                             

delete from $TABLE where sample_duration < 60*60*12 and timestamp < now() - interval '35 days';
COMMIT;
BEGIN;
insert into $TABLE (sensor_id, ip, timestamp, sample_duration, packet_count, total, icmp, udp, tcp, ftp, http, p2p) 
select sensor_id, ip, 
date_trunc('hour', timestamp)+interval '1 hour', 
60*60, sum(packet_count), sum(total), sum(icmp), sum(udp), sum(tcp), sum(ftp), sum(http), sum(p2p)

from $TABLE
where sample_duration < 60*60
and timestamp < now() - interval '7 days'
group by sensor_id, ip, 
date_trunc('hour', timestamp);

delete from $TABLE where sample_duration < 60*60 and timestamp < now() - interval '7 days';
COMMIT;
BEGIN;
insert into $TABLE (sensor_id, ip, timestamp, sample_duration, packet_count, total, icmp, udp, tcp, ftp, http, p2p)
select sensor_id, ip, 
date_trunc('hour', timestamp) + (interval '1 minute' * trunc(EXTRACT(MINUTE FROM timestamp)::numeric,-1)) 
+ interval '10 minutes',
10*60, sum(packet_count), sum(total), sum(icmp), sum(udp), sum(tcp), sum(ftp), sum(http), sum(p2p)
                                                                                                                             
from $TABLE
where sample_duration < 10*60
and timestamp < now() - interval '2 days'
group by sensor_id, ip, 
date_trunc('hour', timestamp) + (interval '1 minute' * trunc(EXTRACT(MINUTE FROM timestamp)::numeric,-1));

delete from $TABLE where sample_duration < 10*60 and timestamp < now() - interval '2 days';
COMMIT;
CLUSTER $TABLE;
ANALYZE $TABLE;
EOF
done