-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaio-linux.alloy
More file actions
359 lines (295 loc) · 11.5 KB
/
aio-linux.alloy
File metadata and controls
359 lines (295 loc) · 11.5 KB
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
/* =============================================================================
* GRAFANA ALLOY CONFIGURATION - Linux System Monitoring
* =============================================================================
*
* ACTIVE SECTIONS:
* 1. TARGETS - Loki & Prometheus endpoints
* 2. SYSTEM LOGS & JOURNAL - Journal and file-based log collection
* 3. SYSTEM METRICS - System performance metrics (Prometheus node exporter)
* 4. SELF-MONITORING - Alloy self-metrics
* 5. PROXMOX GUEST METRICS - Proxmox guest metrics via local exporter
* 6. LOG PROCESSING AND FILTERING - Advanced log level filtering (WARNING+ only)
*
* For more details: https://github.com/IT-BAER/alloy-aio
* =============================================================================
*/
// =============================================================================
// SECTION 1: TARGETS
// =============================================================================
loki.write "default" {
endpoint {
url = "https://your-loki-instance.com/loki/api/v1/push"
}
}
prometheus.remote_write "default" {
endpoint {
url = "https://your-prometheus-instance.com/api/v1/write"
}
}
// =============================================================================
// SECTION 2: SYSTEM LOGS & JOURNAL
// =============================================================================
loki.source.journal "journal" {
max_age = "24h0m0s"
relabel_rules = discovery.relabel.journal.rules
forward_to = [loki.process.filter_journal.receiver]
labels = {
instance = constants.hostname,
source = "systemd-journal",
job = string.format("%s-logs", constants.hostname),
service_name = string.format("%s-logs", constants.hostname),
}
path = "/var/log/journal"
}
local.file_match "system" {
path_targets = [{
__address__ = "localhost",
__path__ = "/var/log/{syslog,messages,*.log}",
instance = constants.hostname,
job = string.format("%s-logs", constants.hostname),
}]
}
discovery.relabel "journal" {
targets = []
rule {
source_labels = ["__journal__systemd_unit"]
target_label = "unit"
}
rule {
source_labels = ["__journal__boot_id"]
target_label = "boot_id"
}
rule {
source_labels = ["__journal__transport"]
target_label = "transport"
}
rule {
source_labels = ["__journal_priority_keyword"]
target_label = "level"
}
}
loki.source.file "system" {
targets = local.file_match.system.targets
forward_to = [loki.process.filter_files.receiver]
}
// =============================================================================
// SECTION 3: SYSTEM METRICS
// =============================================================================
discovery.relabel "metrics" {
targets = prometheus.exporter.unix.metrics.targets
rule {
target_label = "instance"
replacement = constants.hostname
}
rule {
target_label = "job"
replacement = string.format("%s-metrics", constants.hostname)
}
}
prometheus.exporter.unix "metrics" { }
prometheus.scrape "metrics" {
targets = discovery.relabel.metrics.output
forward_to = [prometheus.relabel.node_to_instance.receiver]
scrape_interval = "10s"
scrape_timeout = "8s"
}
// Relabel Linux metrics to use instance_ prefix for unified metrics
prometheus.relabel "node_to_instance" {
forward_to = [prometheus.remote_write.default.receiver]
// Rename node_ prefix to instance_ prefix for unified metrics
rule {
source_labels = ["__name__"]
regex = "node_(.*)"
target_label = "__name__"
replacement = "instance_${1}"
}
// Keep all other metrics unchanged (this rule catches everything that doesn't match the above)
rule {
source_labels = ["__name__"]
regex = "(.*)"
target_label = "__name__"
replacement = "${1}"
}
}
// =============================================================================
// SECTION 4: SELF-MONITORING
// =============================================================================
// Monitor Alloy itself
prometheus.exporter.self "alloy" { }
// Label relabeling for Alloy self-monitoring
discovery.relabel "alloy_metrics" {
targets = prometheus.exporter.self.alloy.targets
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "alloy_metrics" {
targets = discovery.relabel.alloy_metrics.output
forward_to = [prometheus.remote_write.default.receiver]
scrape_interval = "10s"
scrape_timeout = "8s"
}
// =============================================================================
// SECTION 5: PROXMOX GUEST METRICS (LOCAL SCRIPT EXPORTER)
// =============================================================================
// Add discovery.relabel for proxmox guests
discovery.relabel "proxmox_guests" {
targets = [{ __address__ = "localhost:9221" }]
rule {
target_label = "instance"
replacement = constants.hostname
}
rule {
target_label = "job"
replacement = "proxmox-guests"
}
}
prometheus.scrape "proxmox_guests" {
targets = discovery.relabel.proxmox_guests.output
metrics_path = "/pve"
scheme = "http"
scrape_interval = "10s"
scrape_timeout = "8s"
forward_to = [prometheus.remote_write.default.receiver]
}
// =============================================================================
// SECTION 6: LOG PROCESSING AND FILTERING
// =============================================================================
// Process and filter journal logs - keep only WARNING level and above
loki.process "filter_journal" {
forward_to = [loki.write.default.receiver]
// Extract message and process fields from syslog format
stage.regex {
expression = "^(?P<timestamp>[^ ]+) (?P<hostname>[^ ]+) (?P<process>[^\\[\\s]+)(?:\\[(?P<pid>\\d+)\\])?: (?P<message>.*)$"
}
// Drop DEBUG level logs
stage.drop {
source = "level"
value = "debug"
drop_counter_reason = "debug_filtered"
}
// Drop INFO level logs
stage.drop {
source = "level"
value = "info"
drop_counter_reason = "info_filtered"
}
// Drop NOTICE level logs
stage.drop {
source = "level"
value = "notice"
drop_counter_reason = "notice_filtered"
}
// Also drop logs where level might be capitalized
stage.drop {
source = "level"
value = "DEBUG"
drop_counter_reason = "debug_caps_filtered"
}
stage.drop {
source = "level"
value = "INFO"
drop_counter_reason = "info_caps_filtered"
}
stage.drop {
source = "level"
value = "NOTICE"
drop_counter_reason = "notice_caps_filtered"
}
// Extract msg field from logfmt-style logs
stage.regex {
expression = "msg=\"(?P<msg>[^\"]*)\""
}
// Extract level from logfmt-style logs (e.g., level=error, level=info)
stage.regex {
expression = "(?i)level=(?P<content_level>emerg(?:ency)?|alert|crit(?:ical)?|err(?:or)?|warn(?:ing)?|notice|info|debug)"
}
// Normalize the extracted level to lowercase
stage.template {
source = "detected_level"
template = "{{ if .content_level }}{{ .content_level | ToLower }}{{ else if .level }}{{ .level | ToLower }}{{ else }}unknown{{ end }}"
}
// Add process as label
stage.labels {
values = {
process = "",
}
}
// Overwrite level label with detected level from log content for correct Grafana display
stage.labels {
values = {
level = "detected_level",
}
}
// Set message as the log content
stage.output {
source = "message"
}
// Add msg and detected_level as structured metadata
stage.structured_metadata {
values = {
msg = "msg",
detected_level = "detected_level",
}
}
}
// Process and filter file-based logs with intelligent level detection
loki.process "filter_files" {
forward_to = [loki.write.default.receiver]
// Extract message and process fields from syslog format
stage.regex {
expression = "^(?P<timestamp>[^ ]+) (?P<hostname>[^ ]+) (?P<process>[^\\[\\s]+)(?:\\[(?P<pid>\\d+)\\])?: (?P<message>.*)$"
}
// LEVEL DETECTION: Only extract log level from structured properties
stage.regex {
expression = "(?i)(?:level|severity|priority)\\s*[=:]\\s*[\"']?(?P<structured_level>emerg(?:ency)?|alert|crit(?:ical)?|err(?:or)?|warn(?:ing)?|notice|info|debug)[\"']?"
}
// Extract msg field from logfmt-style logs
stage.regex {
expression = "msg=\"(?P<msg>[^\"]*)\""
}
// LEVEL NORMALIZATION: Only use structured_level
stage.template {
source = "log_level"
template = "{{ if .structured_level }}{{ .structured_level | ToLower }}{{ else }}unknown{{ end }}"
}
// FILTERING: Drop all non-WARNING+ logs
stage.drop {
source = "log_level"
value = "debug"
drop_counter_reason = "file_debug_filtered"
}
stage.drop {
source = "log_level"
value = "info"
drop_counter_reason = "file_info_filtered"
}
stage.drop {
source = "log_level"
value = "notice"
drop_counter_reason = "file_notice_filtered"
}
stage.drop {
source = "log_level"
value = "unknown"
drop_counter_reason = "file_unknown_filtered"
}
// LABELING: Add searchable metadata
stage.labels {
values = {
level = "log_level",
process = "",
}
}
// Set message as the log content
stage.output {
source = "message"
}
// Add msg as structured metadata
stage.structured_metadata {
values = {
msg = "msg",
}
}
}