-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvalues.yaml
527 lines (468 loc) · 27.3 KB
/
values.yaml
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
metrics-server:
enabled: true
vector:
role: Agent
service:
enabled: false
env:
- name: SERVICE_ACCOUNT_TOKEN
valueFrom:
secretKeyRef:
name: vector-service-account
key: token
customConfig:
# Prevent data dir read-only volume mount issue: https://github.com/vectordotdev/helm-charts/issues/226
data_dir: /vector-data-dir
sources:
better_stack_kubernetes_logs:
type: kubernetes_logs
better_stack_kubernetes_metrics_nodes:
type: http_client
endpoint: 'https://{{ .Release.Name }}-metrics-server/apis/metrics.k8s.io/v1beta1/nodes'
auth:
strategy: bearer
token: $SERVICE_ACCOUNT_TOKEN
decoding:
codec: json
headers:
accept:
- application/json
better_stack_kubernetes_metrics_pods:
type: http_client
endpoint: 'https://{{ .Release.Name }}-metrics-server/apis/metrics.k8s.io/v1beta1/pods'
auth:
strategy: bearer
token: $SERVICE_ACCOUNT_TOKEN
decoding:
codec: json
headers:
accept:
- application/json
sinks:
better_stack_http_sink:
type: http
method: post
uri: https://in.logs.betterstack.com/
encoding:
codec: json
compression: gzip
auth:
strategy: bearer
token: ~
inputs:
- better_stack_kubernetes_parser
better_stack_http_metrics_sink:
type: http
method: post
uri: https://in.logs.betterstack.com/metrics
encoding:
codec: json
compression: gzip
auth:
strategy: bearer
token: ~
inputs:
- better_stack_kubernetes_metrics_nodes_parser
- better_stack_kubernetes_metrics_pods_parser
transforms:
better_stack_kubernetes_parser:
type: remap
inputs:
- better_stack_kubernetes_logs
source: |
del(.source_type)
.dt = del(.timestamp)
.kubernetes.stream = del(.stream)
.platform = "Kubernetes"
.apache2 = parse_apache_log(.message, format: "combined") ??
parse_apache_log(.message, format: "common") ??
parse_apache_log(.message, format: "error") ??
{}
if .apache2 != {} {
.platform = "Apache"
.dt = format_timestamp!(parse_timestamp(del(.apache2.timestamp), "%d/%b/%Y:%T %z") ?? .dt, "%+")
.level = del(.apache2.severity)
.message = del(.apache2.message)
request_msg = (string(.apache2.method) ?? "") + " " + (string(.apache2.path) ?? "") + " " + (string(.apache2.protocol) ?? "")
if .message == request_msg { del(.message) }
} else {
del(.apache2)
}
.nginx = parse_regex(.message, r'^\s*(-|(?P<client>\S+))\s+\-\s+(-|(?P<user>\S+))\s+\[(?P<timestamp>.+)\]\s+"(?P<request>(?P<method>\w+)\s+(?P<path>\S+)\s+(?P<protocol>\S+))"\s+(?P<status>\d+)\s+(?P<size>\d+)\s+"(-|(?P<referrer>.+))"\s+"(-|(?P<agent>.+))"\s*') ??
parse_regex(.message, r'^\s*(?P<timestamp>.+)\s+\[(?P<severity>\w+)\]\s+(?P<pid>\d+)\#(?P<tid>\d+):\s+\*(?P<cid>\d+)\s+(?P<message>.*)(?:,\s+client:\s+(?P<client>[^,z]+))(?:,\s+server:\s+(?P<server>[^,z]+))(?:,\s+request:\s+"(?P<request>[^"]+)")(?:,\s+subrequest:\s+"(?P<subrequest>[^"]+)")?(?:,\s+upstream:\s+"(?P<upstream>[^"]+)")?(?:,\s+host:\s+"(?P<host>[^"]+)")(?:,\s+referrer:\s+"(?P<referrer>[^"]+)")?\s*') ??
parse_nginx_log(.message, format: "combined") ??
parse_nginx_log(.message, format: "error") ??
{}
if .nginx != {} {
.platform = "Nginx"
.level = del(.nginx.severity)
.message = del(.nginx.message)
if is_null(.message) { del(.message) }
if exists(.nginx.timestamp) {
.dt = format_timestamp!(
parse_timestamp(.nginx.timestamp, "%d/%b/%Y:%T %z") ??
parse_timestamp(.nginx.timestamp, "%Y/%m/%d %T") ??
.dt,
"%+"
)
del(.nginx.timestamp)
}
if is_string(.nginx.status) { .nginx.status = to_int(.nginx.status) ?? .nginx.status }
if is_string(.nginx.size) { .nginx.size = to_int(.nginx.size) ?? .nginx.size }
if is_string(.nginx.cid) { .nginx.cid = to_int(.nginx.cid) ?? .nginx.cid }
if is_string(.nginx.pid) { .nginx.pid = to_int(.nginx.pid) ?? .nginx.pid }
if is_string(.nginx.tid) { .nginx.tid = to_int(.nginx.tid) ?? .nginx.tid }
if is_null(.nginx.subrequest) { del(.nginx.subrequest) }
if is_null(.nginx.upstream) { del(.nginx.upstream) }
if is_null(.nginx.referrer) { del(.nginx.referrer) }
} else {
del(.nginx)
}
# we can't distinguish apache and nginx logs (they have the same format)
# so we merge them under the generalized "HTTP" platform
if .platform == "Apache" || .platform == "Nginx" {
apache2 = del(.apache2)
if is_null(apache2) { apache2 = {} }
nginx = del(.nginx)
if is_null(nginx) { nginx = {} }
.platform = "HTTP"
.http = merge!(apache2, nginx)
}
.postgres = parse_regex(.message, r'^(?P<dt>\d+-\d+-\d+ \d+:\d+:\d+\.\d+ \S+) \[(?P<pid>\d+)\] (?:(?:(?P<username>\S+)@(?P<database>\S+))?\s*(?P<level>\w+):\s*(?P<message>.*))?') ?? {}
if .postgres != {} {
.platform = "PostgreSQL"
if exists(.postgres.pid) { .postgres.pid = to_int!(.postgres.pid) }
if exists(.postgres.level) { .level = downcase!(del(.postgres.level)) }
if exists(.postgres.message) { .message = del(.postgres.message) }
if exists(.postgres.dt) {
parsed_dt = to_string(.postgres.dt)
if !ends_with(parsed_dt, " UTC") {
.postgres.local_date_time = del(.postgres.dt)
} else {
.dt = del(.postgres.dt)
}
}
# extract message metadata
tmp = string!(.message)
.message_metadata = {}
ips = parse_regex_all!(tmp, r'\b(?P<ip>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\b')
if exists(ips[0].ip) { .message_metadata.ipv4_1 = ips[0].ip; tmp = replace(tmp, string!(ips[0].ip), "") }
if exists(ips[1].ip) { .message_metadata.ipv4_2 = ips[1].ip; tmp = replace(tmp, string!(ips[1].ip), "") }
if exists(ips[2].ip) { .message_metadata.ipv4_3 = ips[2].ip; tmp = replace(tmp, string!(ips[2].ip), "") }
if exists(ips[3].ip) { .message_metadata.ipv4_4 = ips[3].ip; tmp = replace(tmp, string!(ips[3].ip), "") }
if exists(ips[4].ip) { .message_metadata.ipv4_5 = ips[4].ip; tmp = replace(tmp, string!(ips[4].ip), "") }
# we match only full IPv6 addresses
ipv6s = parse_regex_all!(tmp, r'\b(?P<ip>(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4})\b')
if exists(ipv6s[0].ip) { .message_metadata.ipv6_1 = ipv6s[0].ip; tmp = replace(tmp, string!(ipv6s[0].ip), "") }
if exists(ipv6s[1].ip) { .message_metadata.ipv6_2 = ipv6s[1].ip; tmp = replace(tmp, string!(ipv6s[1].ip), "") }
if exists(ipv6s[2].ip) { .message_metadata.ipv6_3 = ipv6s[2].ip; tmp = replace(tmp, string!(ipv6s[2].ip), "") }
if exists(ipv6s[3].ip) { .message_metadata.ipv6_4 = ipv6s[3].ip; tmp = replace(tmp, string!(ipv6s[3].ip), "") }
if exists(ipv6s[4].ip) { .message_metadata.ipv6_5 = ipv6s[4].ip; tmp = replace(tmp, string!(ipv6s[4].ip), "") }
numbers = parse_regex_all!(tmp, r'(?P<num>\b\d+(?:\.\d+)?\b)')
if exists(numbers[0].num) { .message_metadata.param1 = to_int(numbers[0].num) ?? to_float(numbers[0].num) ?? null }
if exists(numbers[1].num) { .message_metadata.param2 = to_int(numbers[1].num) ?? to_float(numbers[1].num) ?? null }
if exists(numbers[2].num) { .message_metadata.param3 = to_int(numbers[2].num) ?? to_float(numbers[2].num) ?? null }
if exists(numbers[3].num) { .message_metadata.param4 = to_int(numbers[3].num) ?? to_float(numbers[3].num) ?? null }
if exists(numbers[4].num) { .message_metadata.param5 = to_int(numbers[4].num) ?? to_float(numbers[4].num) ?? null }
if exists(numbers[5].num) { .message_metadata.param6 = to_int(numbers[5].num) ?? to_float(numbers[5].num) ?? null }
if exists(numbers[6].num) { .message_metadata.param7 = to_int(numbers[6].num) ?? to_float(numbers[6].num) ?? null }
if exists(numbers[7].num) { .message_metadata.param8 = to_int(numbers[7].num) ?? to_float(numbers[7].num) ?? null }
if exists(numbers[8].num) { .message_metadata.param9 = to_int(numbers[8].num) ?? to_float(numbers[8].num) ?? null }
if exists(numbers[9].num) { .message_metadata.param10 = to_int(numbers[9].num) ?? to_float(numbers[9].num) ?? null }
} else {
del(.postgres)
}
.mysql = parse_regex(.message, r'^(?P<dt>\d+-\d+-\d+T\d+:\d+:\d+\.\d+\w+)\s+(?P<thread>\d+)\s+\[(?P<priority>\S+)\]\s*\[(?P<error_code>\S+)\]\s*\[(?P<subsystem>\S+)\]\s*(?P<message>.*)') ??
parse_regex(.message, r'^(?P<dt>\d+-\d+-\d+T\d+:\d+:\d+\.\d+\w+)\s+(?P<id>\d+)\s+(?P<command>[^\t]+)(?:\s+(?P<message>.*))?') ??
{}
if .mysql != {} {
.platform = "MySQL"
if exists(.mysql.dt) { .dt = del(.mysql.dt) }
if exists(.mysql.thread) { .mysql.thread = to_int!(.mysql.thread) }
if exists(.mysql.id) { .mysql.id = to_int!(.mysql.id) }
.message = del(.mysql.message)
# extract message metadata
tmp = string!(.message)
.message_metadata = {}
ips = parse_regex_all!(tmp, r'\b(?P<ip>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\b')
if exists(ips[0].ip) { .message_metadata.ipv4_1 = ips[0].ip; tmp = replace(tmp, string!(ips[0].ip), "") }
if exists(ips[1].ip) { .message_metadata.ipv4_2 = ips[1].ip; tmp = replace(tmp, string!(ips[1].ip), "") }
if exists(ips[2].ip) { .message_metadata.ipv4_3 = ips[2].ip; tmp = replace(tmp, string!(ips[2].ip), "") }
if exists(ips[3].ip) { .message_metadata.ipv4_4 = ips[3].ip; tmp = replace(tmp, string!(ips[3].ip), "") }
if exists(ips[4].ip) { .message_metadata.ipv4_5 = ips[4].ip; tmp = replace(tmp, string!(ips[4].ip), "") }
# we match only full IPv6 addresses
ipv6s = parse_regex_all!(tmp, r'\b(?P<ip>(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4})\b')
if exists(ipv6s[0].ip) { .message_metadata.ipv6_1 = ipv6s[0].ip; tmp = replace(tmp, string!(ipv6s[0].ip), "") }
if exists(ipv6s[1].ip) { .message_metadata.ipv6_2 = ipv6s[1].ip; tmp = replace(tmp, string!(ipv6s[1].ip), "") }
if exists(ipv6s[2].ip) { .message_metadata.ipv6_3 = ipv6s[2].ip; tmp = replace(tmp, string!(ipv6s[2].ip), "") }
if exists(ipv6s[3].ip) { .message_metadata.ipv6_4 = ipv6s[3].ip; tmp = replace(tmp, string!(ipv6s[3].ip), "") }
if exists(ipv6s[4].ip) { .message_metadata.ipv6_5 = ipv6s[4].ip; tmp = replace(tmp, string!(ipv6s[4].ip), "") }
numbers = parse_regex_all!(tmp, r'(?P<num>\b\d+(?:\.\d+)?\b)')
if exists(numbers[0].num) { .message_metadata.param1 = to_int(numbers[0].num) ?? to_float(numbers[0].num) ?? null }
if exists(numbers[1].num) { .message_metadata.param2 = to_int(numbers[1].num) ?? to_float(numbers[1].num) ?? null }
if exists(numbers[2].num) { .message_metadata.param3 = to_int(numbers[2].num) ?? to_float(numbers[2].num) ?? null }
if exists(numbers[3].num) { .message_metadata.param4 = to_int(numbers[3].num) ?? to_float(numbers[3].num) ?? null }
if exists(numbers[4].num) { .message_metadata.param5 = to_int(numbers[4].num) ?? to_float(numbers[4].num) ?? null }
if exists(numbers[5].num) { .message_metadata.param6 = to_int(numbers[5].num) ?? to_float(numbers[5].num) ?? null }
if exists(numbers[6].num) { .message_metadata.param7 = to_int(numbers[6].num) ?? to_float(numbers[6].num) ?? null }
if exists(numbers[7].num) { .message_metadata.param8 = to_int(numbers[7].num) ?? to_float(numbers[7].num) ?? null }
if exists(numbers[8].num) { .message_metadata.param9 = to_int(numbers[8].num) ?? to_float(numbers[8].num) ?? null }
if exists(numbers[9].num) { .message_metadata.param10 = to_int(numbers[9].num) ?? to_float(numbers[9].num) ?? null }
} else {
del(.mysql)
}
.mongodb = object!(parse_json(.message) ?? {})
if .mongodb != {} && exists(.mongodb.t."$$date") {
.platform = "MongoDB"
.dt = .mongodb.t."$$date"
.message = del(.mongodb.msg)
if .mongodb.s == "I" {
.level = "info"
} else if .mongodb.s == "W" {
.level = "warning"
} else if .mongodb.s == "E" {
.level = "error"
} else if .mongodb.s == "F" {
.level = "fatal"
} else if .mongodb.s == "D" {
.level = "debug"
} else if .mongodb.s == "D1" {
.level = "debug1"
} else if .mongodb.s == "D2" {
.level = "debug2"
} else if .mongodb.s == "D3" {
.level = "debug3"
} else if .mongodb.s == "D4" {
.level = "debug4"
} else if .mongodb.s == "D5" {
.level = "debug5"
}
# extract message metadata
tmp = string!(.message)
.message_metadata = {}
ips = parse_regex_all!(tmp, r'\b(?P<ip>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\b')
if exists(ips[0].ip) { .message_metadata.ipv4_1 = ips[0].ip; tmp = replace(tmp, string!(ips[0].ip), "") }
if exists(ips[1].ip) { .message_metadata.ipv4_2 = ips[1].ip; tmp = replace(tmp, string!(ips[1].ip), "") }
if exists(ips[2].ip) { .message_metadata.ipv4_3 = ips[2].ip; tmp = replace(tmp, string!(ips[2].ip), "") }
if exists(ips[3].ip) { .message_metadata.ipv4_4 = ips[3].ip; tmp = replace(tmp, string!(ips[3].ip), "") }
if exists(ips[4].ip) { .message_metadata.ipv4_5 = ips[4].ip; tmp = replace(tmp, string!(ips[4].ip), "") }
# we match only full IPv6 addresses
ipv6s = parse_regex_all!(tmp, r'\b(?P<ip>(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4})\b')
if exists(ipv6s[0].ip) { .message_metadata.ipv6_1 = ipv6s[0].ip; tmp = replace(tmp, string!(ipv6s[0].ip), "") }
if exists(ipv6s[1].ip) { .message_metadata.ipv6_2 = ipv6s[1].ip; tmp = replace(tmp, string!(ipv6s[1].ip), "") }
if exists(ipv6s[2].ip) { .message_metadata.ipv6_3 = ipv6s[2].ip; tmp = replace(tmp, string!(ipv6s[2].ip), "") }
if exists(ipv6s[3].ip) { .message_metadata.ipv6_4 = ipv6s[3].ip; tmp = replace(tmp, string!(ipv6s[3].ip), "") }
if exists(ipv6s[4].ip) { .message_metadata.ipv6_5 = ipv6s[4].ip; tmp = replace(tmp, string!(ipv6s[4].ip), "") }
numbers = parse_regex_all!(tmp, r'(?P<num>\b\d+(?:\.\d+)?\b)')
if exists(numbers[0].num) { .message_metadata.param1 = to_int(numbers[0].num) ?? to_float(numbers[0].num) ?? null }
if exists(numbers[1].num) { .message_metadata.param2 = to_int(numbers[1].num) ?? to_float(numbers[1].num) ?? null }
if exists(numbers[2].num) { .message_metadata.param3 = to_int(numbers[2].num) ?? to_float(numbers[2].num) ?? null }
if exists(numbers[3].num) { .message_metadata.param4 = to_int(numbers[3].num) ?? to_float(numbers[3].num) ?? null }
if exists(numbers[4].num) { .message_metadata.param5 = to_int(numbers[4].num) ?? to_float(numbers[4].num) ?? null }
if exists(numbers[5].num) { .message_metadata.param6 = to_int(numbers[5].num) ?? to_float(numbers[5].num) ?? null }
if exists(numbers[6].num) { .message_metadata.param7 = to_int(numbers[6].num) ?? to_float(numbers[6].num) ?? null }
if exists(numbers[7].num) { .message_metadata.param8 = to_int(numbers[7].num) ?? to_float(numbers[7].num) ?? null }
if exists(numbers[8].num) { .message_metadata.param9 = to_int(numbers[8].num) ?? to_float(numbers[8].num) ?? null }
if exists(numbers[9].num) { .message_metadata.param10 = to_int(numbers[9].num) ?? to_float(numbers[9].num) ?? null }
} else {
del(.mongodb)
}
.redis = parse_regex(.message, r'^(?P<pid>\d+):(?P<role_char>\w)\s+(?P<dt>\d+ \w+ \d+ \d{2}:\d{2}:\d{2}.\d+) (?P<level_symbol>.) (?P<message>.*)') ??
parse_regex(.message, r'^(?P<pid>\d+):(?P<role>\S+) \((?P<unix_timestamp>\d+)\) (?P<message>.*)') ??
{}
if .redis != {} {
.platform = "Redis"
if .redis.role_char == "M" {
.redis.role = "master"
} else if .redis.role_char == "S" {
.redis.role = "slave"
} else if .redis.role_char == "C" {
.redis.role = "RDB/AOF writing child"
} else if .redis.role_char == "X" {
.redis.role = "sentinel"
}
if .redis.level_symbol == "." {
.level = "debug"
} else if .redis.level_symbol == "-" {
.level = "verbose"
} else if .redis.level_symbol == "*" {
.level = "notice"
} else if .redis.level_symbol == "#" {
.level = "warning"
}
.redis.pid = to_int(.redis.pid) ?? null
if exists(.redis.dt) {
.dt = format_timestamp!(parse_timestamp(del(.redis.dt), "%d %b %Y %T%.f") ?? now(), "%+")
} else if exists(.redis.unix_timestamp) {
.dt = format_timestamp!(from_unix_timestamp(to_int!(del(.redis.unix_timestamp))) ?? now(), "%+")
}
.message = del(.redis.message)
# extract message metadata
tmp = string!(.message)
.message_metadata = {}
ips = parse_regex_all!(tmp, r'\b(?P<ip>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\b')
if exists(ips[0].ip) { .message_metadata.ipv4_1 = ips[0].ip; tmp = replace(tmp, string!(ips[0].ip), "") }
if exists(ips[1].ip) { .message_metadata.ipv4_2 = ips[1].ip; tmp = replace(tmp, string!(ips[1].ip), "") }
if exists(ips[2].ip) { .message_metadata.ipv4_3 = ips[2].ip; tmp = replace(tmp, string!(ips[2].ip), "") }
if exists(ips[3].ip) { .message_metadata.ipv4_4 = ips[3].ip; tmp = replace(tmp, string!(ips[3].ip), "") }
if exists(ips[4].ip) { .message_metadata.ipv4_5 = ips[4].ip; tmp = replace(tmp, string!(ips[4].ip), "") }
# we match only full IPv6 addresses
ipv6s = parse_regex_all!(tmp, r'\b(?P<ip>(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4})\b')
if exists(ipv6s[0].ip) { .message_metadata.ipv6_1 = ipv6s[0].ip; tmp = replace(tmp, string!(ipv6s[0].ip), "") }
if exists(ipv6s[1].ip) { .message_metadata.ipv6_2 = ipv6s[1].ip; tmp = replace(tmp, string!(ipv6s[1].ip), "") }
if exists(ipv6s[2].ip) { .message_metadata.ipv6_3 = ipv6s[2].ip; tmp = replace(tmp, string!(ipv6s[2].ip), "") }
if exists(ipv6s[3].ip) { .message_metadata.ipv6_4 = ipv6s[3].ip; tmp = replace(tmp, string!(ipv6s[3].ip), "") }
if exists(ipv6s[4].ip) { .message_metadata.ipv6_5 = ipv6s[4].ip; tmp = replace(tmp, string!(ipv6s[4].ip), "") }
numbers = parse_regex_all!(tmp, r'(?P<num>\b\d+(?:\.\d+)?\b)')
if exists(numbers[0].num) { .message_metadata.param1 = to_int(numbers[0].num) ?? to_float(numbers[0].num) ?? null }
if exists(numbers[1].num) { .message_metadata.param2 = to_int(numbers[1].num) ?? to_float(numbers[1].num) ?? null }
if exists(numbers[2].num) { .message_metadata.param3 = to_int(numbers[2].num) ?? to_float(numbers[2].num) ?? null }
if exists(numbers[3].num) { .message_metadata.param4 = to_int(numbers[3].num) ?? to_float(numbers[3].num) ?? null }
if exists(numbers[4].num) { .message_metadata.param5 = to_int(numbers[4].num) ?? to_float(numbers[4].num) ?? null }
if exists(numbers[5].num) { .message_metadata.param6 = to_int(numbers[5].num) ?? to_float(numbers[5].num) ?? null }
if exists(numbers[6].num) { .message_metadata.param7 = to_int(numbers[6].num) ?? to_float(numbers[6].num) ?? null }
if exists(numbers[7].num) { .message_metadata.param8 = to_int(numbers[7].num) ?? to_float(numbers[7].num) ?? null }
if exists(numbers[8].num) { .message_metadata.param9 = to_int(numbers[8].num) ?? to_float(numbers[8].num) ?? null }
if exists(numbers[9].num) { .message_metadata.param10 = to_int(numbers[9].num) ?? to_float(numbers[9].num) ?? null }
} else {
del(.redis)
}
better_stack_kubernetes_metrics_nodes_parser:
type: remap
inputs:
- better_stack_kubernetes_metrics_nodes
source: |
del(.source_type)
.dt = del(.timestamp)
metrics = []
for_each(append([], .items) ?? []) -> |_index, item| {
item.metadata.labels.node_name = item.metadata.name
item.metadata.labels.metrics_kind = .kind
cpu_string = to_string(item.usage.cpu) ?? ""
cpu_ratio = 0
cpu_err = null
if ends_with(cpu_string, "n") {
cpu_ratio, cpu_err = 1 / 1000000000 * to_float(replace(cpu_string, "n", ""))
} else if ends_with(cpu_string, "u") {
cpu_ratio, cpu_err = 1 / 1000000 * to_float(replace(cpu_string, "u", ""))
} else if ends_with(cpu_string, "m") {
cpu_ratio, cpu_err = 1 / 1000 * to_float(replace(cpu_string, "m", ""))
} else {
cpu_ratio, cpu_err = to_float(cpu_string)
}
if (cpu_err == null) {
metrics = push(metrics, {
"name": "cpu_ratio",
"kind": "absolute",
"gauge": {
"value": cpu_ratio
},
"tags": item.metadata.labels,
"dt": .timestamp,
"interval_ms": parse_duration(item.window, "ms") ?? null
})
}
memory_string = to_string(item.usage.memory) ?? ""
memory_bytes = 0
memory_err = null
if ends_with(memory_string, "Ki") {
memory_bytes, memory_err = 1024 * to_float(replace(memory_string, "Ki", ""))
} else if ends_with(memory_string, "K") {
memory_bytes, memory_err = 1000 * to_float(replace(memory_string, "K", ""))
} else if ends_with(memory_string, "Mi") {
memory_bytes, memory_err = 1024 * 1024 * to_float(replace(memory_string, "Mi", ""))
} else if ends_with(memory_string, "M") {
memory_bytes, memory_err = 1000 * 1000 * to_float(replace(memory_string, "M", ""))
} else if ends_with(memory_string, "Gi") {
memory_bytes, memory_err = 1024 * 1024 * 1024 * to_float(replace(memory_string, "Gi", ""))
} else if ends_with(memory_string, "G") {
memory_bytes, memory_err = 1000 * 1000 * 1000 * to_float(replace(memory_string, "G", ""))
} else {
memory_bytes, memory_err = to_float(memory_string)
}
if (memory_err == null) {
metrics = push(metrics, {
"name": "memory_bytes",
"kind": "absolute",
"gauge": {
"value": to_int(memory_bytes)
},
"tags": item.metadata.labels,
"dt": .timestamp,
"interval_ms": parse_duration(item.window, "ms") ?? null
})
}
}
. = metrics
better_stack_kubernetes_metrics_pods_parser:
type: remap
inputs:
- better_stack_kubernetes_metrics_pods
source: |
del(.source_type)
.dt = del(.timestamp)
metrics = []
for_each(append([], .items) ?? []) -> |_index, item| {
tags = del(item.metadata.labels)
tags.pod_name = del(item.metadata.name)
tags.pod_namespace = del(item.metadata.namespace)
tags.metrics_kind = .kind
for_each(append([], item.containers) ?? []) -> |_index, container| {
tags.container_name = del(container.name)
cpu_string = to_string(container.usage.cpu) ?? ""
cpu_ratio = 0
cpu_err = null
if ends_with(cpu_string, "n") {
cpu_ratio, cpu_err = 1 / 1000000000 * to_float(replace(cpu_string, "n", ""))
} else if ends_with(cpu_string, "u") {
cpu_ratio, cpu_err = 1 / 1000000 * to_float(replace(cpu_string, "u", ""))
} else if ends_with(cpu_string, "m") {
cpu_ratio, cpu_err = 1 / 1000 * to_float(replace(cpu_string, "m", ""))
} else {
cpu_ratio, cpu_err = to_float(cpu_string)
}
if (cpu_err == null) {
metrics = push(metrics, {
"name": "cpu_ratio",
"kind": "absolute",
"gauge": {
"value": cpu_ratio
},
"tags": tags,
"dt": .timestamp,
"interval_ms": parse_duration(item.window, "ms") ?? null
})
}
memory_string = to_string(container.usage.memory) ?? ""
memory_bytes = 0
memory_err = null
if ends_with(memory_string, "Ki") {
memory_bytes, memory_err = 1024 * to_float(replace(memory_string, "Ki", ""))
} else if ends_with(memory_string, "K") {
memory_bytes, memory_err = 1000 * to_float(replace(memory_string, "K", ""))
} else if ends_with(memory_string, "Mi") {
memory_bytes, memory_err = 1024 * 1024 * to_float(replace(memory_string, "Mi", ""))
} else if ends_with(memory_string, "M") {
memory_bytes, memory_err = 1000 * 1000 * to_float(replace(memory_string, "M", ""))
} else if ends_with(memory_string, "Gi") {
memory_bytes, memory_err = 1024 * 1024 * 1024 * to_float(replace(memory_string, "Gi", ""))
} else if ends_with(memory_string, "G") {
memory_bytes, memory_err = 1000 * 1000 * 1000 * to_float(replace(memory_string, "G", ""))
} else {
memory_bytes, memory_err = to_float(memory_string)
}
if (memory_err == null) {
metrics = push(metrics, {
"name": "memory_bytes",
"kind": "absolute",
"gauge": {
"value": to_int(memory_bytes)
},
"tags": tags,
"dt": .timestamp,
"interval_ms": parse_duration(item.window, "ms") ?? null
})
}
}
}
. = metrics