---
volumes:
  akvorado-prometheus:

services:
  # Store metrics
  prometheus:
    extends:
      file: versions.yml
      service: prometheus
    profiles: [ prometheus ]
    restart: unless-stopped
    volumes:
      - akvorado-prometheus:/prometheus
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      # Those are the defaults
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      # Those are not the defaults
      - --web.enable-remote-write-receiver
      - --web.external-url=/prometheus
      - --storage.tsdb.retention.time=30d
    healthcheck:
      interval: 20s
      test: ["CMD",
             "promtool", "check", "healthy", "--url=http://127.0.0.1:9090/prometheus"]
    expose:
      - 9090/tcp
    labels:
      - traefik.enable=true
      - traefik.http.routers.prometheus.rule=PathPrefix(`/prometheus`)
      - traefik.http.routers.prometheus.entrypoints=private
      - metrics.port=9090
      - metrics.path=/prometheus/metrics

  # Fetch metrics
  alloy:
    extends:
      file: versions.yml
      service: alloy
    profiles: [ prometheus ]
    restart: unless-stopped
    user: root                  # for access to /var/run/docker.sock
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./config.alloy:/etc/alloy/config.alloy
    extra_hosts:
      - "host.docker.internal:host-gateway"
    expose:
      - 12345
    command:
      - run
      - /etc/alloy
      - --storage.path=/var/lib/alloy/data
      - --server.http.listen-addr=0.0.0.0:12345
      - --server.http.ui-path-prefix=/alloy
    depends_on:
      prometheus:
        condition: service_healthy
      kafka:
        condition: service_healthy
    labels:
      - traefik.enable=true
      - traefik.http.routers.alloy.rule=PathPrefix(`/alloy`)
      - traefik.http.routers.alloy.entrypoints=private
      - metrics.port=12345

  # Node exporter for host metrics
  node-exporter:
    extends:
      file: versions.yml
      service: node-exporter
    profiles: [ prometheus ]
    restart: unless-stopped
    volumes:
      - /:/host:ro,rslave
    network_mode: host
    pid: host
    command:
      - --path.rootfs=/host
    expose:
      - 9100/tcp
    labels:
      - metrics.port=9100

  # cAdvisor for container metrics
  cadvisor:
    extends:
      file: versions.yml
      service: cadvisor
    profiles: [ prometheus ]
    restart: unless-stopped
    privileged: true
    volumes:
      - /:/rootfs:ro
      - /sys:/sys:ro
      - /dev/disk/:/dev/disk:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/lib/docker/:/var/lib/docker:ro
    devices:
      - /dev/kmsg:/dev/kmsg
    command:
      # Minimize the amount of metrics reported, notably don't report anything from host
      - --docker_only
      - --store_container_labels=false
      - --disable_root_cgroup_stats
      - --enable_metrics=cpu,cpuLoad,diskIO,memory,network,oom_event,process,tcp,udp
    expose:
      - 8080/tcp
    labels:
      - metrics.port=8080
