working instance

This commit is contained in:
Arne Teuke
2025-03-11 16:51:44 +01:00
parent a3408c7882
commit 2b0bd7788a

View File

@@ -1,29 +1,20 @@
<% if @ay_manage_loki == true -%> <% if @ay_manage_loki == true -%>
// Receive syslog messages logging{
loki.source.syslog "syslog" { level = "info"
listener { format = "logfmt"
address = "0.0.0.0:514" // Adjust to your required listening port write_to = [loki.process.alloy.receiver]
}
forward_to = [loki.process.extract_hostname.receiver]
} }
// Process logs and extract hostname loki.process "alloy" {
loki.process "extract_hostname" { stage.labels {
stage.logfmt { values = {
mapping = { service_name = "alloy",
"hostname" = "syslog_hostname", // Extracts the hostname from syslog }
} }
} forward_to = [loki.write.loki.receiver]
stage.labels {
values = {
"hostname" = "hostname", // Assigns extracted hostname to the label
}
}
forward_to = [loki.relabel.add_labels.receiver]
} }
// Define file discovery for your logs // Define file discovery for your logs
local.file_match "system_logs" { local.file_match "system_logs" {
path_targets = [ path_targets = [
@@ -37,23 +28,18 @@ local.file_match "system_logs" {
// Scrape the logs from the matched files // Scrape the logs from the matched files
loki.source.file "system_logs" { loki.source.file "system_logs" {
targets = local.file_match.system_logs.targets targets = local.file_match.system_logs.targets
forward_to = [loki.relabel.add_labels.receiver] forward_to = [loki.process.syslog.receiver]
} }
// Relabel logs to add hostname and job labels loki.process "syslog" {
loki.relabel "add_labels" {
rule { stage.static_labels {
action = "replace" values = {
target_label = "hostname" instance = constants.hostname,
replacement = "host" service = "linux_logs",
}
} }
rule { forward_to = [loki.write.loki.receiver]
action = "replace"
target_label = "job"
replacement = "syslogs"
}
forward_to = [loki.write.loki.receiver]
} }
loki.write "loki" { loki.write "loki" {