88 lines
1.9 KiB
Plaintext
88 lines
1.9 KiB
Plaintext
<% 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]
|
|
}
|
|
|
|
// Process logs and extract hostname
|
|
loki.process "extract_hostname" {
|
|
stage.logfmt {}
|
|
|
|
stage.labels {
|
|
values = {
|
|
hostname = "syslog_hostname"
|
|
}
|
|
}
|
|
forward_to = [loki.write.loki.receiver]
|
|
}
|
|
|
|
|
|
// Define file discovery for your logs
|
|
local.file_match "system_logs" {
|
|
path_targets = [
|
|
<% @log_targets_array.each do |target| -%>
|
|
{__path__ = "<%= target %>"},
|
|
<% end -%>
|
|
]
|
|
sync_period = "5s"
|
|
}
|
|
|
|
// 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]
|
|
}
|
|
|
|
// Relabel logs to add hostname and job labels
|
|
loki.relabel "add_labels" {
|
|
forward_to = [loki.write.loki.receiver]
|
|
|
|
rule {
|
|
action = "replace"
|
|
source_labels = ["__hostname"]
|
|
target_label = "hostname"
|
|
}
|
|
rule {
|
|
action = "replace"
|
|
target_label = "job"
|
|
replacement = "syslogs"
|
|
}
|
|
}
|
|
|
|
loki.write "loki" {
|
|
endpoint {
|
|
url = "<%= @ay_loki_url %>"
|
|
basic_auth {
|
|
username = "<%= @ay_loki_username %>"
|
|
password = "<%= @ay_loki_userpass %>"
|
|
}
|
|
}
|
|
}
|
|
<% end -%>
|
|
<% if @ay_manage_prom == true -%>
|
|
// Metrics collection
|
|
prometheus.exporter.unix "system_metrics" {
|
|
include_exporter_metrics = true
|
|
disable_collectors = ["mdadm"]
|
|
}
|
|
|
|
prometheus.scrape "scrape_system" {
|
|
targets = prometheus.exporter.unix.system_metrics.targets
|
|
forward_to = [prometheus.remote_write.prometheus.receiver]
|
|
scrape_interval = "15s"
|
|
}
|
|
|
|
prometheus.remote_write "prometheus" {
|
|
endpoint {
|
|
url = "<%= @ay_prom_url %>"
|
|
basic_auth {
|
|
username = "<%= @ay_loki_username %>"
|
|
password = "<%= @ay_loki_userpass %>"
|
|
}
|
|
}
|
|
}
|
|
<% end %> |