Files
confdroid_alloy/templates/config.alloy.erb

80 lines
1.9 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-10 23:15:54 +01:00
// Add hostname as a label explicitly
loki.process "add_hostname" {
forward_to = [loki.relabel.add_labels.receiver]
stage.static_labels {
values = {
2025-03-10 23:20:56 +01:00
hostname = env("HOSTNAME"), // Pulls from $HOSTNAME, defaults to "unknown-host"
2025-03-10 23:15:54 +01:00
}
}
}
2025-03-10 22:30:46 +01:00
// Add hostname and job labels
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 {
source_labels = ["__host__"] // Internal hostname from constants.hostname
target_label = "hostname"
}
2025-03-11 11:53:38 +01:00
rule {
action = "replace"
target_label = "hostname"
2025-03-11 12:01:02 +01:00
replacement = "$HOSTNAME"
2025-03-11 11:53:38 +01:00
}
2025-03-10 22:30:46 +01:00
rule {
action = "replace"
target_label = "job"
replacement = "syslogs" // Or any name you prefer, e.g., "syslogs"
}
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 %>