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:29:25 +01:00
|
|
|
loki.process "syslog" {
|
|
|
|
|
stage.regex {
|
2025-03-11 13:41:04 +01:00
|
|
|
expression = `(?P<ts>[A-Z][a-z]{2}\s{1,2}\d{1,2}\s\d{2}:\d{2}:\d{2})\s(?P<host>[\w\.\@-]+)\s(?P<log>.*)$`
|
2025-03-11 12:55:28 +01:00
|
|
|
}
|
2025-03-11 13:29:25 +01:00
|
|
|
stage.labels {
|
|
|
|
|
values = {
|
2025-03-11 13:41:04 +01:00
|
|
|
hostname = "${host}"
|
2025-03-11 13:29:25 +01:00
|
|
|
}
|
2025-03-11 12:55:28 +01:00
|
|
|
}
|
2025-03-11 13:29:25 +01:00
|
|
|
stage.timestamp {
|
|
|
|
|
source = "ts"
|
|
|
|
|
format = "Jan _2 15:04:05"
|
2025-03-11 12:55:28 +01:00
|
|
|
}
|
2025-03-11 13:29:25 +01:00
|
|
|
stage.output {
|
|
|
|
|
source = "log"
|
2025-03-11 12:55:28 +01:00
|
|
|
}
|
2025-03-11 13:29:25 +01:00
|
|
|
forward_to = [loki.write.loki.receiver]
|
2025-03-10 14:23:27 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-11 13:41:04 +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 %>
|