-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sql
231 lines (224 loc) · 8.21 KB
/
setup.sql
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
CREATE TABLE flows
(
`begin_at` DateTime64(3) CODEC(DoubleDelta),
`end_at` DateTime64(3) CODEC(DoubleDelta),
`vlan` UInt16 CODEC(Gorilla),
`ipv` UInt8 CODEC(NONE),
`ipproto` UInt8 CODEC(NONE),
`saddr` IPv6 CODEC(ZSTD(3)),
`daddr` IPv6 CODEC(ZSTD(3)),
`sport` UInt16 CODEC(NONE),
`dport` UInt16 CODEC(NONE),
`gre_key` UInt32 CODEC(Gorilla),
`packets` UInt64 CODEC(Gorilla),
`bytes` UInt64 CODEC(Gorilla),
`frags` UInt64 CODEC(Gorilla),
`syns` UInt32 CODEC(Gorilla),
`fins` UInt32 CODEC(Gorilla),
`rsts` UInt32 CODEC(Gorilla),
`mintcpwin` UInt16 CODEC(DoubleDelta),
`maxtcpwin` UInt16 CODEC(DoubleDelta),
`minpktlen` UInt32 CODEC(DoubleDelta),
`maxpktlen` UInt32 CODEC(DoubleDelta),
`min_ttl` UInt8 CODEC(Gorilla),
`max_ttl` UInt8 CODEC(Gorilla),
`pkt_lens` Map(UInt16, UInt64) CODEC(DoubleDelta),
INDEX begin_at_idx begin_at TYPE minmax GRANULARITY 2048,
INDEX end_at_idx end_at TYPE minmax GRANULARITY 2048
)
ENGINE = SummingMergeTree()
PARTITION BY toStartOfDay(begin_at)
ORDER BY (vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key, begin_at, end_at)
TTL toDateTime(end_at) + toIntervalHour(4);
CREATE TABLE flowstats
(
`begin_at` DateTime64(3) CODEC(DoubleDelta),
`end_at` DateTime64(3) CODEC(DoubleDelta),
`user_ms` UInt32 CODEC(Gorilla),
`kern_ms` UInt32 CODEC(Gorilla),
`reads` UInt64 CODEC(Gorilla),
`packets` UInt64 CODEC(Gorilla),
`bytes` UInt64 CODEC(Gorilla),
`flows` UInt32 CODEC(Gorilla),
`pcap_recv` UInt32 CODEC(Gorilla),
`pcap_drop` UInt32 CODEC(Gorilla),
`pcap_ifdrop` UInt32 CODEC(Gorilla),
`mdrop` UInt64 CODEC(Gorilla),
INDEX begin_at_idx begin_at TYPE minmax GRANULARITY 2048,
INDEX end_at_idx end_at TYPE minmax GRANULARITY 2048
)
ENGINE = SummingMergeTree()
PARTITION BY toStartOfDay(begin_at)
ORDER BY (begin_at, end_at)
TTL toDateTime(end_at) + toIntervalHour(4);
CREATE TABLE dns_lookups
(
`begin_at` DateTime64(3) CODEC(DoubleDelta),
`end_at` DateTime64(3) CODEC(DoubleDelta),
`saddr` FixedString(16) CODEC(ZSTD(1)),
`daddr` FixedString(16) CODEC(ZSTD(1)),
`sport` UInt16 CODEC(Gorilla),
`dport` UInt16 CODEC(Gorilla),
`qid` UInt16 CODEC(Gorilla),
`name` String CODEC(ZSTD(1)),
INDEX begin_at_idx begin_at TYPE minmax GRANULARITY 1024,
INDEX end_at_idx end_at TYPE minmax GRANULARITY 1024
)
ENGINE = MergeTree()
PARTITION BY toStartOfDay(begin_at)
ORDER BY (saddr, daddr, sport, dport, qid, begin_at, end_at);
CREATE TABLE rdns
(
`begin_at` DateTime64(3) CODEC(DoubleDelta),
`end_at` DateTime64(3) CODEC(DoubleDelta),
`addr` FixedString(16) CODEC(ZSTD(1)),
`name` String CODEC(ZSTD(1)),
INDEX end_at_idx end_at TYPE minmax GRANULARITY 1024,
INDEX begin_at_idx begin_at TYPE minmax GRANULARITY 1024
)
ENGINE = MergeTree()
PARTITION BY toStartOfDay(end_at)
ORDER BY (addr, end_at, begin_at);
CREATE MATERIALIZED VIEW flows_5sec
(
`interval` DateTime CODEC(DoubleDelta),
`vlan` UInt16 CODEC(Gorilla),
`ipv` UInt8 CODEC(NONE),
`ipproto` UInt8 CODEC(NONE),
`saddr` FixedString(16) CODEC(ZSTD(3)),
`daddr` FixedString(16) CODEC(ZSTD(3)),
`sport` UInt16 CODEC(Gorilla),
`dport` UInt16 CODEC(Gorilla),
`gre_key` UInt32 CODEC(Gorilla),
`packets` UInt64 CODEC(Gorilla),
`bytes` UInt64 CODEC(Gorilla),
`syns` UInt64 CODEC(Gorilla),
`fins` UInt64 CODEC(Gorilla),
`rsts` UInt64 CODEC(Gorilla),
INDEX interval_idx interval TYPE minmax GRANULARITY 2048,
INDEX daddr_idx daddr TYPE bloom_filter(0.025) GRANULARITY 8192,
INDEX daddrport_idx (ipproto, daddr, dport) TYPE bloom_filter(0.025) GRANULARITY 8192,
INDEX dport_idx (ipproto, dport) TYPE bloom_filter(0.025) GRANULARITY 8192
)
ENGINE = SummingMergeTree
PARTITION BY toStartOfDay(interval)
ORDER BY (vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key, interval)
TTL interval + toIntervalDay(14)
AS SELECT
toStartOfInterval(begin_at, toIntervalSecond(5)) AS interval,
vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key,
sum(packets) AS packets,
sum(bytes) AS bytes,
sum(syns) AS syns,
sum(fins) AS fins,
sum(rsts) AS rsts
FROM flows
GROUP BY
interval, vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key;
CREATE MATERIALIZED VIEW flows_1min
(
`interval` DateTime CODEC(DoubleDelta),
`vlan` UInt16 CODEC(Gorilla),
`ipv` UInt8 CODEC(NONE),
`ipproto` UInt8 CODEC(NONE),
`saddr` FixedString(16) CODEC(ZSTD(3)),
`daddr` FixedString(16) CODEC(ZSTD(3)),
`sport` UInt16 CODEC(Gorilla),
`dport` UInt16 CODEC(Gorilla),
`gre_key` UInt32 CODEC(Gorilla),
`packets` UInt64 CODEC(Gorilla),
`bytes` UInt64 CODEC(Gorilla),
`syns` UInt64 CODEC(Gorilla),
`fins` UInt64 CODEC(Gorilla),
`rsts` UInt64 CODEC(Gorilla),
INDEX interval_idx interval TYPE minmax GRANULARITY 2048,
INDEX daddr_idx daddr TYPE bloom_filter(0.025) GRANULARITY 8192,
INDEX daddrport_idx (ipproto, daddr, dport) TYPE bloom_filter(0.025) GRANULARITY 8192,
INDEX dport_idx (ipproto, dport) TYPE bloom_filter(0.025) GRANULARITY 8192
)
ENGINE = SummingMergeTree
PARTITION BY toStartOfDay(interval)
ORDER BY (vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key, interval)
TTL interval + toIntervalDay(180)
AS SELECT
toStartOfInterval(begin_at, toIntervalSecond(60)) AS interval,
vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key,
sum(packets) AS packets,
sum(bytes) AS bytes,
sum(syns) AS syns,
sum(fins) AS fins,
sum(rsts) AS rsts
FROM flows
GROUP BY
interval, vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key;
CREATE MATERIALIZED VIEW flows_5min
(
`interval` DateTime CODEC(DoubleDelta),
`vlan` UInt16 CODEC(Gorilla),
`ipv` UInt8 CODEC(NONE),
`ipproto` UInt8 CODEC(NONE),
`saddr` FixedString(16) CODEC(ZSTD(3)),
`daddr` FixedString(16) CODEC(ZSTD(3)),
`sport` UInt16 CODEC(Gorilla),
`dport` UInt16 CODEC(Gorilla),
`gre_key` UInt32 CODEC(Gorilla),
`packets` UInt64 CODEC(Gorilla),
`bytes` UInt64 CODEC(Gorilla),
`syns` UInt64 CODEC(Gorilla),
`fins` UInt64 CODEC(Gorilla),
`rsts` UInt64 CODEC(Gorilla),
INDEX interval_idx interval TYPE minmax GRANULARITY 2048,
INDEX daddr_idx daddr TYPE bloom_filter(0.025) GRANULARITY 8192,
INDEX daddrport_idx (ipproto, daddr, dport) TYPE bloom_filter(0.025) GRANULARITY 8192,
INDEX dport_idx (ipproto, dport) TYPE bloom_filter(0.025) GRANULARITY 8192
)
ENGINE = SummingMergeTree
PARTITION BY toStartOfDay(interval)
ORDER BY (vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key, interval)
TTL interval + toIntervalDay(540)
AS SELECT
toStartOfInterval(begin_at, toIntervalSecond(300)) AS interval,
vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key,
sum(packets) AS packets,
sum(bytes) AS bytes,
sum(syns) AS syns,
sum(fins) AS fins,
sum(rsts) AS rsts
FROM flows
GROUP BY
interval, vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key;
CREATE MATERIALIZED VIEW flows_1hr
(
`interval` DateTime CODEC(DoubleDelta),
`vlan` UInt16 CODEC(Gorilla),
`ipv` UInt8 CODEC(NONE),
`ipproto` UInt8 CODEC(NONE),
`saddr` FixedString(16) CODEC(ZSTD(3)),
`daddr` FixedString(16) CODEC(ZSTD(3)),
`sport` UInt16 CODEC(Gorilla),
`dport` UInt16 CODEC(Gorilla),
`gre_key` UInt32 CODEC(Gorilla),
`packets` UInt64 CODEC(Gorilla),
`bytes` UInt64 CODEC(Gorilla),
`syns` UInt64 CODEC(Gorilla),
`fins` UInt64 CODEC(Gorilla),
`rsts` UInt64 CODEC(Gorilla),
INDEX interval_idx interval TYPE minmax GRANULARITY 2048,
INDEX daddr_idx daddr TYPE bloom_filter(0.025) GRANULARITY 8192,
INDEX daddrport_idx (ipproto, daddr, dport) TYPE bloom_filter(0.025) GRANULARITY 8192,
INDEX dport_idx (ipproto, dport) TYPE bloom_filter(0.025) GRANULARITY 8192
)
ENGINE = SummingMergeTree
PARTITION BY toStartOfDay(interval)
ORDER BY (vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key, interval)
AS SELECT
toStartOfInterval(begin_at, toIntervalSecond(3600)) AS interval,
vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key,
sum(packets) AS packets,
sum(bytes) AS bytes,
sum(syns) AS syns,
sum(fins) AS fins,
sum(rsts) AS rsts
FROM flows
GROUP BY
interval, vlan, ipv, ipproto, saddr, daddr, sport, dport, gre_key;