# Turnkey Prometheus + Grafana stack for the CCAM `/api/metrics` endpoint.
#
#   cd monitoring && docker compose up -d
#   open http://localhost:3000   (admin / admin)
#
# The "CCAM — Overview" dashboard and the Prometheus datasource are
# pre-provisioned, so there is nothing to click after start. Prometheus scrapes
# the dashboard running on the HOST (a plain `npm start` on :4820) via
# host.docker.internal — see ./prometheus/prometheus.yml to change the target
# or add a bearer token when DASHBOARD_TOKEN is set. See ./README.md.
services:
  prometheus:
    image: prom/prometheus:latest
    container_name: ccam-prometheus
    restart: unless-stopped
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --web.enable-lifecycle
      - --web.console.templates=/etc/prometheus/consoles
    volumes:
      - ./prometheus:/etc/prometheus:ro
      - prometheus-data:/prometheus
    ports:
      - "127.0.0.1:9090:9090"
    # Lets the container reach a CCAM server running on the host (Linux needs the
    # explicit host-gateway mapping; Docker Desktop resolves it natively).
    extra_hosts:
      - "host.docker.internal:host-gateway"

  grafana:
    image: grafana/grafana:latest
    container_name: ccam-grafana
    restart: unless-stopped
    depends_on:
      - prometheus
    env_file:
      - ./grafana.defaults.env
    volumes:
      - ./grafana/provisioning:/etc/grafana/provisioning:ro
      - ./grafana/dashboards:/var/lib/grafana/dashboards:ro
      - grafana-data:/var/lib/grafana
    ports:
      - "127.0.0.1:3000:3000"

volumes:
  prometheus-data:
  grafana-data:
