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-11 13:57: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 14:29:02 +01:00
|
|
|
// Relabel logs to add hostname and job labels
|
2025-03-11 13:57:46 +01:00
|
|
|
loki.relabel "add_labels" {
|
|
|
|
|
forward_to = [loki.write.loki.receiver]
|
2025-03-11 14:29:02 +01:00
|
|
|
|
2025-03-11 14:52:15 +01:00
|
|
|
rule {
|
2025-03-11 15:28:26 +01:00
|
|
|
action = "replace"
|
2025-03-11 15:37:37 +01:00
|
|
|
source_labels = ["__journal__hostname"]
|
2025-03-11 15:28:26 +01:00
|
|
|
target_label = "hostname"
|
2025-03-11 14:40:39 +01:00
|
|
|
}
|
2025-03-11 14:59:18 +01:00
|
|
|
rule {
|
2025-03-11 13:57:46 +01:00
|
|
|
action = "replace"
|
|
|
|
|
target_label = "job"
|
2025-03-11 14:29:02 +01:00
|
|
|
replacement = "syslogs"
|
2025-03-11 12:55:28 +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 %>
|