working instance
This commit is contained in:
@@ -1,29 +1,20 @@
|
||||
<% if @ay_manage_loki == true -%>
|
||||
|
||||
// Receive syslog messages
|
||||
loki.source.syslog "syslog" {
|
||||
listener {
|
||||
address = "0.0.0.0:514" // Adjust to your required listening port
|
||||
}
|
||||
forward_to = [loki.process.extract_hostname.receiver]
|
||||
logging{
|
||||
level = "info"
|
||||
format = "logfmt"
|
||||
write_to = [loki.process.alloy.receiver]
|
||||
}
|
||||
|
||||
// Process logs and extract hostname
|
||||
loki.process "extract_hostname" {
|
||||
stage.logfmt {
|
||||
mapping = {
|
||||
"hostname" = "syslog_hostname", // Extracts the hostname from syslog
|
||||
}
|
||||
}
|
||||
loki.process "alloy" {
|
||||
stage.labels {
|
||||
values = {
|
||||
"hostname" = "hostname", // Assigns extracted hostname to the label
|
||||
service_name = "alloy",
|
||||
}
|
||||
}
|
||||
forward_to = [loki.relabel.add_labels.receiver]
|
||||
forward_to = [loki.write.loki.receiver]
|
||||
}
|
||||
|
||||
|
||||
// Define file discovery for your logs
|
||||
local.file_match "system_logs" {
|
||||
path_targets = [
|
||||
@@ -37,21 +28,16 @@ local.file_match "system_logs" {
|
||||
// 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]
|
||||
forward_to = [loki.process.syslog.receiver]
|
||||
}
|
||||
|
||||
// Relabel logs to add hostname and job labels
|
||||
loki.relabel "add_labels" {
|
||||
loki.process "syslog" {
|
||||
|
||||
rule {
|
||||
action = "replace"
|
||||
target_label = "hostname"
|
||||
replacement = "host"
|
||||
stage.static_labels {
|
||||
values = {
|
||||
instance = constants.hostname,
|
||||
service = "linux_logs",
|
||||
}
|
||||
rule {
|
||||
action = "replace"
|
||||
target_label = "job"
|
||||
replacement = "syslogs"
|
||||
}
|
||||
forward_to = [loki.write.loki.receiver]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user