iac/ansible/roles/monitoring_agent/templates/docker-compose.yml.j2
Sergei Poljanski 2359370e24
All checks were successful
deploy / ansible (push) Successful in 7m59s
monitoring: collapse session scopes, fix cadvisor healthcheck
Each SSH login from Ansible and CI deploys creates its own
session-N.scope unit. As a journal label that made 3400+ streams and
Loki rejected new ones with 429, dropping container logs. Map them all
to session.scope.

cAdvisor's image healthcheck probes localhost:8080, but it listens on
the VPC address on 9180, so both containers showed unhealthy.

Assisted-by: Claude:opus-5-5
2026-11-13 06:42:10 +04:00

72 lines
2.3 KiB
Django/Jinja

# Managed by Ansible (role monitoring_agent).
services:
node-exporter:
image: prom/node-exporter:{{ monitoring_node_exporter_version }}
container_name: node-exporter
command:
- --path.rootfs=/host
- --web.listen-address={{ vpc_ip }}:{{ monitoring_node_exporter_port }}
- --collector.textfile.directory=/textfile
- --collector.filesystem.mount-points-exclude=^/(dev|proc|run|sys|var/lib/docker/.+)($|/)
network_mode: host
pid: host
volumes:
- /:/host:ro,rslave
- {{ monitoring_textfile_dir }}:/textfile:ro
restart: unless-stopped
mem_limit: 64m
cadvisor:
image: ghcr.io/google/cadvisor:{{ monitoring_cadvisor_version }}
container_name: cadvisor
command:
- --listen_ip={{ vpc_ip }}
- --port={{ monitoring_cadvisor_port }}
- --docker_only=true
- --housekeeping_interval=30s
- --store_container_labels=false
- --whitelisted_container_labels=com.docker.compose.project,com.docker.compose.service
- --disable_metrics=percpu,sched,tcp,udp,hugetlb,referenced_memory,cpu_topology,resctrl,advtcp,process
network_mode: host
privileged: true
devices:
- /dev/kmsg
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro
healthcheck:
# The image probes localhost:8080; we listen on the VPC address only.
test: ["CMD", "wget", "-q", "--tries=1", "--spider", "http://{{ vpc_ip }}:{{ monitoring_cadvisor_port }}/healthz"]
interval: 30s
timeout: 3s
retries: 3
restart: unless-stopped
mem_limit: 192m
alloy:
image: grafana/alloy:{{ monitoring_alloy_version }}
container_name: alloy
command:
- run
- --server.http.listen-addr={{ vpc_ip }}:12345
- --storage.path=/var/lib/alloy/data
- /etc/alloy/config.alloy
network_mode: host
volumes:
- ./config.alloy:/etc/alloy/config.alloy:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- /var/log/journal:/var/log/journal:ro
- /run/log/journal:/run/log/journal:ro
- /etc/machine-id:/etc/machine-id:ro
{% if inventory_hostname == 'asxpio-ops' %}
- /opt/traefik/logs:/traefik-logs:ro
{% endif %}
- alloy-data:/var/lib/alloy/data
restart: unless-stopped
mem_limit: 256m
volumes:
alloy-data: