Add grafana_alloy role: scrape log files to Loki

This commit is contained in:
2026-07-06 13:07:50 +03:00
parent 5322a48353
commit bafa282482
11 changed files with 264 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
[Unit]
Description=Grafana Alloy
Wants=network-online.target
After=network-online.target
Documentation="https://grafana.com/docs/alloy/"
[Service]
User=alloy
Group=alloy
Type=simple
Environment=HOSTNAME=%H
ExecStart=/usr/bin/alloy run {{ grafana_alloy_config_dir }}/config.alloy \
--storage.path={{ grafana_alloy_data_dir }} \
--server.http.listen-addr=127.0.0.1:12345 \
--disable-reporting
ExecReload=/bin/kill -HUP $MAINPID
# Security hardening
ReadWritePaths={{ grafana_alloy_data_dir }}
ProtectSystem=strict
NoNewPrivileges=true
PrivateTmp=true
ProtectKernelModules=true
ProtectControlGroups=true
ProtectKernelTunables=true
ProtectClock=yes
RestrictSUIDSGID=true
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,24 @@
// {{ ansible_managed }}
local.file_match "logs" {
path_targets = [
{% for path in grafana_alloy_log_paths %}
{__path__ = "{{ path }}", job = "varlogs", host = constants.hostname},
{% endfor %}
]
}
loki.source.file "logs" {
targets = local.file_match.logs.targets
forward_to = [loki.process.default.receiver]
}
loki.process "default" {
forward_to = [loki.write.default.receiver]
}
loki.write "default" {
endpoint {
url = "{{ grafana_alloy_loki_url }}"
}
}