add file control for main log files

This commit is contained in:
Arne Teuke
2025-03-10 22:30:46 +01:00
parent 1e3b8f0863
commit 4bb73da9a4
2 changed files with 24 additions and 15 deletions

View File

@@ -4,6 +4,7 @@
"maillog",
"missingok",
"postrotate",
"sharedscripts"
"sharedscripts",
"syslogs"
]
}

View File

@@ -1,25 +1,33 @@
<% if @ay_manage_loki == true -%>
logging {
level = "info"
format = "logfmt"
}
loki.source.file "system_logs" {
targets = [
// Define file discovery for your logs
local.file_match "system_logs" {
path_targets = [
<% @log_targets_array.each do |target| -%>
{__path__ = "<%= target %>"},
<% end -%>
]
forward_to = [loki.write.loki.receiver]
sync_period = "5s"
}
loki.process "enrich_server_logs" {
stage.static_labels {
values = {
hostname = sys.env("HOSTNAME"),
}
}
forward_to = [loki.write.loki.receiver]
// 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]
}
// Add hostname and job labels
loki.relabel "add_labels" {
forward_to = [loki.write.loki_endpoint.receiver]
rule {
source_labels = ["__host__"] // Internal hostname from constants.hostname
target_label = "hostname"
}
rule {
action = "replace"
target_label = "job"
replacement = "syslogs" // Or any name you prefer, e.g., "syslogs"
}
}
loki.write "loki" {