2025-02-24 15:23:20 +01:00
|
|
|
<% if @ay_manage_loki == true -%>
|
2025-02-24 13:24:45 +01:00
|
|
|
|
2025-03-11 16:51:44 +01:00
|
|
|
logging{
|
2025-03-11 17:05:50 +01:00
|
|
|
level = "debug"
|
2025-03-11 16:51:44 +01:00
|
|
|
format = "logfmt"
|
|
|
|
|
write_to = [loki.process.alloy.receiver]
|
2025-03-11 15:54:01 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-11 16:51:44 +01:00
|
|
|
loki.process "alloy" {
|
|
|
|
|
stage.labels {
|
|
|
|
|
values = {
|
|
|
|
|
service_name = "alloy",
|
|
|
|
|
}
|
2025-03-11 16:14:26 +01:00
|
|
|
}
|
2025-03-11 16:51:44 +01:00
|
|
|
forward_to = [loki.write.loki.receiver]
|
2025-03-11 15:54:01 +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
|
2025-03-11 16:51:44 +01:00
|
|
|
forward_to = [loki.process.syslog.receiver]
|
2025-03-11 13:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-11 16:51:44 +01:00
|
|
|
loki.process "syslog" {
|
2025-03-11 14:29:02 +01:00
|
|
|
|
2025-03-11 16:51:44 +01:00
|
|
|
stage.static_labels {
|
|
|
|
|
values = {
|
2025-03-11 16:53:15 +01:00
|
|
|
fqdn = constants.hostname,
|
2025-03-11 16:51:44 +01:00
|
|
|
service = "linux_logs",
|
|
|
|
|
}
|
2025-03-11 12:55:28 +01:00
|
|
|
}
|
2025-03-11 16:51:44 +01:00
|
|
|
forward_to = [loki.write.loki.receiver]
|
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
|
2025-03-12 14:18:45 +01:00
|
|
|
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 %>
|