Files
confdroid_alloy/templates/config.alloy.erb

99 lines
2.3 KiB
Plaintext
Raw Normal View History

2025-02-24 15:23:20 +01:00
<% if @ay_manage_loki == true -%>
2025-02-24 13:24:45 +01:00
2025-03-10 22:30:46 +01:00
// Define file discovery for your logs
local.file_match "system_logs" {
path_targets = [
2025-02-24 13:24:45 +01:00
<% @log_targets_array.each do |target| -%>
{__path__ = "<%= target %>"},
<% end -%>
]
2025-03-10 22:30:46 +01:00
sync_period = "5s"
2025-02-24 13:24:45 +01:00
}
2025-03-10 22:30:46 +01:00
// Scrape the logs from the matched files
loki.source.file "system_logs" {
targets = local.file_match.system_logs.targets
forward_to = [loki.relabel.add_labels.receiver]
}
2025-03-11 12:55:28 +01:00
// Parse hostname from log lines (if structured)
loki.process "parse_hostname" {
2025-03-11 12:24:46 +01:00
forward_to = [loki.relabel.add_labels.receiver]
2025-03-11 12:55:28 +01:00
stage.match {
selector = "{filename=~\"/var/log/.*\"}"
stage.regex {
expression = "^(?P<timestamp>[^ ]+ [^ ]+) (?P<hostname>[^ ]+) .*"
source = "__content__"
}
stage.labels {
values = {
hostname = "hostname", // Extracted from log line
}
}
}
// Fallback: Set hostname explicitly if not parsed
2025-03-11 12:24:46 +01:00
stage.static_labels {
values = {
2025-03-11 12:55:28 +01:00
hostname_fallback = system.hostname, // e.g., fm002
2025-03-11 12:24:46 +01:00
}
}
}
2025-03-11 12:55:28 +01:00
// Refine labels
2025-03-10 22:30:46 +01:00
loki.relabel "add_labels" {
2025-03-10 22:43:44 +01:00
forward_to = [loki.write.loki.receiver]
2025-03-10 22:30:46 +01:00
rule {
action = "replace"
target_label = "job"
2025-03-11 12:55:28 +01:00
replacement = "syslogs"
}
rule {
source_labels = ["__path__"]
target_label = "filename"
}
// Prefer parsed hostname, fallback to system.hostname
rule {
source_labels = ["hostname"]
target_label = "hostname"
}
rule {
source_labels = ["hostname_fallback"]
target_label = "hostname"
action = "replace"
replacement = "${__label:hostname_fallback}" // Only if hostname is unset
2025-03-10 22:30:46 +01:00
}
2025-03-10 14:23:27 +01:00
}
2025-02-24 13:24:45 +01:00
loki.write "loki" {
endpoint {
2025-02-24 13:41:09 +01:00
url = "<%= @ay_loki_url %>"
2025-02-24 13:24:45 +01:00
basic_auth {
username = "<%= @ay_loki_username %>"
password = "<%= @ay_loki_userpass %>"
}
}
2025-02-24 15:23:20 +01:00
}
<% end -%>
<% if @ay_manage_prom == true -%>
// Metrics collection
prometheus.exporter.unix "system_metrics" {
include_exporter_metrics = true
2025-02-24 16:07:26 +01:00
disable_collectors = ["mdadm"]
2025-02-24 15:23:20 +01:00
}
prometheus.scrape "scrape_system" {
targets = prometheus.exporter.unix.system_metrics.targets
forward_to = [prometheus.remote_write.prometheus.receiver]
2025-02-24 16:07:26 +01:00
scrape_interval = "15s"
2025-02-24 15:23:20 +01:00
}
prometheus.remote_write "prometheus" {
endpoint {
url = "<%= @ay_prom_url %>"
basic_auth {
username = "<%= @ay_loki_username %>"
password = "<%= @ay_loki_userpass %>"
}
}
}
<% end %>