Ansible Grafana Alloy role to ship logs and metrics https://grafana.com/docs/alloy/latest/
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-27 13:28:09 +00:00
.forgejo/workflows feat: added initial version 2026-10-26 21:44:24 +01:00
defaults feat: added extra scrape targets, memory cap and collector disable 2026-10-27 14:27:07 +01:00
handlers feat: added alloy as root mode 2026-10-27 00:03:41 +01:00
meta feat: added initial version 2026-10-26 21:44:24 +01:00
tasks feat: added extra scrape targets, memory cap and collector disable 2026-10-27 14:27:07 +01:00
templates feat: added extra scrape targets, memory cap and collector disable 2026-10-27 14:27:07 +01:00
.gitignore feat: added initial version 2026-10-26 21:44:24 +01:00
CHANGELOG.md feat: added extra scrape targets, memory cap and collector disable 2026-10-27 14:27:07 +01:00
LICENSE feat: added initial version 2026-10-26 21:44:24 +01:00
README.md Prettified Code! 2026-10-27 13:28:09 +00:00

Alloy

Installs Grafana Alloy from the official apt repository and ships the host's metrics to Prometheus (remote_write) and its logs to Loki. One role for every Linux host: bare metal, VM or LXC.

What gets shipped

Metrics (instance = alloy_instance):

Job Source Content
node prometheus.exporter.unix (node exporter) CPU, memory, filesystems, disk I/O, network, load, pressure, hwmon/thermal, ZFS, systemd units, AMD GPUs (drm)
node textfile collectors (/var/lib/prometheus/node-exporter) SMART health (smartmon), NVMe health (nvme), pending apt updates (apt)
cadvisor prometheus.exporter.cadvisor Per-container CPU/memory/network (Docker only)
nvidia_gpu nvidia_gpu_exporter on 127.0.0.1:9835 NVIDIA GPU utilisation, memory, temperature, power
alloy prometheus.exporter.self Alloy itself (dropped samples, failed sends)

Logs (host = alloy_instance):

Job Source Labels
systemd-journal the systemd journal unit, identifier, level, transport, log_type="auth" for ssh/login/sudo/su/logind/user changes
docker/podman container stdout/stderr via the API socket container, compose_project, compose_service, stream
files alloy_log_files (dpkg, apt, unattended-upgrades) filename

The journal covers syslog, kernel messages, sshd (Accepted publickey, failed logins), console/tty logins (login, systemd-logind sessions), sudo/su and the Docker or Podman daemon. Debian 12+ has no rsyslog by default, so /var/log/syslog/auth.log don't exist; where rsyslog is installed they duplicate the journal and are not read.

Requirements

  • Debian or Ubuntu with systemd, become: true.
  • Prometheus with remote write enabled and/or Loki, reachable from the host.
  • NVIDIA: the driver (nvidia-smi) must already be installed.

Variables

Variable Default Description
alloy_loki_url "" Loki push URL (.../loki/api/v1/push). Empty = no logs.
alloy_prometheus_url "" Prometheus remote_write URL (.../api/v1/write). Empty = no metrics. One of the two is required.
alloy_basic_auth_username "" Basic auth for both endpoints (needs alloy_basic_auth_password).
alloy_basic_auth_password ""
alloy_bearer_token "" Bearer token, used when no basic auth is set.
alloy_tls_insecure_skip_verify false Skip TLS verification.
alloy_instance inventory_hostname Host name in the instance (metrics) and host (logs) labels.
alloy_external_labels {} Extra labels on everything, e.g. {customer: tni}.
alloy_version "" Pin the Alloy package (1.21.2). Empty = latest.
alloy_scrape_interval 60s
alloy_log_level warn Alloy's own log level.
alloy_listen_address 127.0.0.1:12345 Alloy UI/API. Keep it on localhost.
alloy_disable_reporting true No anonymous usage stats to Grafana Labs.
alloy_memory_max_mb 768 with cAdvisor, else 384 Memory cap (systemd MemoryMax, GOMEMLIMIT at 80 %). Only Alloy restarts when hit. 0 = none.
alloy_node_enable_collectors [systemd, drm] Node exporter collectors on top of the defaults.
alloy_node_disable_collectors [] Collectors to switch off, e.g. [cpufreq] where sysfs reads hang (some ARM firmware).
alloy_netdev_exclude veth/bridges/tap/fw* Network interfaces not reported (container/VM plumbing).
alloy_smart_enabled bare metal only SMART + NVMe timers; off in VMs/containers (no real disks).
alloy_nvidia_gpu auto auto = when nvidia-smi exists, or true/false.
alloy_nvidia_exporter_version 1.15.1 nvidia_gpu_exporter release (checksum-verified).
alloy_container_runtime auto auto = docker if /var/run/docker.sock exists, else podman if installed. Or docker/podman/none.
alloy_cadvisor_enabled true Container metrics (Docker only).
alloy_auth_identifiers sshd, sudo, su, login, ... Journal identifiers labelled log_type="auth".
alloy_logs_max_age 12h How far back the journal and container log history are shipped on the first start.
alloy_scrape_targets [] Extra targets: {job, address, path?, interval?}, e.g. an app's /metrics on localhost.
alloy_log_files dpkg, apt, unattended-upgrades Extra log files (globs allowed).
alloy_uninstall false Removes Alloy, its config, the collectors and the exporter.
alloy_purge false With alloy_uninstall: also deletes /var/lib/alloy and the textfile metrics.

Usage

- hosts: all
  become: true
  roles:
    - alloy
  vars:
    alloy_loki_url: https://monitoring.example.com/loki/api/v1/push
    alloy_prometheus_url: https://monitoring.example.com/api/v1/write
    alloy_basic_auth_username: alloy
    alloy_basic_auth_password: "{{ vault_alloy_password }}"
    alloy_external_labels:
      customer: example

How it works

  • Alloy comes from apt.grafana.com (key in /etc/apt/keyrings/grafana.asc) and runs as the package's alloy user. The role adds it to adm and systemd-journal - without them loki.source.journal starts fine but reads nothing.
  • Config: /etc/alloy/config.alloy (root:alloy 0640, it holds the credentials), checked with alloy fmt before it replaces the old one. Flags: /etc/default/alloy. After a change the role restarts Alloy and waits for /-/ready.
  • SMART/NVMe/apt metrics come from Debian's prometheus-node-exporter-collectors (smartmon/nvme/apt timers every 15 min writing .prom files); no node exporter package is installed. Its postinst enables all of its timers - the role disables the ones it doesn't use (ipmitool-sensor, mellanox-hca-temp, and smartmon/nvme in VMs).
  • Containers: Docker via /var/run/docker.sock (alloy joins group docker); Podman via its Docker-compatible API (podman.socket, the role gives group podman access). Either socket is root-equivalent - that's the price of reading container logs without running Alloy as root.
  • nvidia_gpu_exporter is installed from its .deb and bound to 127.0.0.1:9835 (the package default listens on all interfaces).

Limitations

  • Debian/Ubuntu only (apt).
  • On Debian 12 / Ubuntu 24.04 the collector package depends on prometheus-node-exporter; it gets installed but stays stopped and masked.
  • With cAdvisor (Docker + metrics) Alloy runs as root (drop-in alloy.service.d/root.conf): cAdvisor needs /var/lib/docker (0700 root), and as the alloy user it only sees the root cgroup. Group docker is root-equivalent anyway. Without cAdvisor it runs as alloy.
  • Intel GPUs aren't covered (node exporter's drm collector is AMD only).
  • wtmp/btmp/lastlog are binary and not shipped; logins are in the journal.