# Prometheus + Grafana for fleet observability and the FAK gateway.
# Default: Docker Desktop (Windows / macOS) bridge networking — works out of the
# box when fleet_bottleneck.py and fak serve run on the same machine.
#
# Network path (default):
#   Grafana → http://prometheus:9091 → Prometheus → host.docker.internal:9095 → fleet_bottleneck.py
#   Grafana → http://prometheus:9091 → Prometheus → host.docker.internal:8080 → fak serve
#
# Start the metrics sources first (on the host):
#   python tools/fleet_bottleneck.py serve --port 9095
#   ./fak serve --addr 127.0.0.1:8080
# Then bring the stack up:
#   cd tools/grafana && docker compose up -d
# Open http://localhost:3000  (admin / fleet)
#
# Linux / DGX (host networking): uncomment every "network_mode: host" line, comment
# out the ports/extra_hosts blocks, and update:
#   - prometheus.yml: targets → "localhost:9095" and "localhost:8080"
#   - provisioning/datasources/datasource.yml: Prometheus url → "http://localhost:9091"

services:
  prometheus:
    image: prom/prometheus:v3.2.1
    container_name: fleet-prometheus
    restart: unless-stopped
    # network_mode: host  # [LINUX] uncomment; comment ports/extra_hosts below
    ports:
      - "9091:9091"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - ./prometheus-alerts.yml:/etc/prometheus/prometheus-alerts.yml:ro
      - fleet-prometheus-data:/prometheus
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
      - "--storage.tsdb.retention.time=30d"
      - "--web.enable-lifecycle"
      - "--web.listen-address=:9091"

  grafana:
    image: grafana/grafana:11.5.2
    container_name: fleet-grafana
    restart: unless-stopped
    depends_on:
      - prometheus
    # network_mode: host  # [LINUX] uncomment; comment ports/extra_hosts below
    ports:
      - "127.0.0.1:3000:3000"  # localhost only
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=fleet
      - GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/var/lib/grafana/dashboards/fleet-bottleneck-overview.json
      - GF_SERVER_HTTP_PORT=3000
    volumes:
      - ./provisioning:/etc/grafana/provisioning:ro
      - ./dashboards:/var/lib/grafana/dashboards:ro
      - fleet-grafana-data:/var/lib/grafana

volumes:
  fleet-prometheus-data:
  fleet-grafana-data:
