services:
  # Prometheus - Metrics Collection
  prometheus:
    image: prom/prometheus:v3.9.1
    restart: unless-stopped
    ports:
      - "9091:9090"
    volumes:
      - ${PROMETHEUS_CONFIG_PATH}:/etc/prometheus/prometheus.yml:ro
      - ${PROMETHEUS_DATA_DIR}:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
      - '--web.enable-admin-api'

  # Grafana - Visualization Dashboard
  grafana:
    image: grafana/grafana:12.4.0
    restart: unless-stopped
    ports:
      - "3002:3000"
    volumes:
      - ${GRAFANA_DATA_DIR}:/var/lib/grafana
    environment:
      - GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER}
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD}
      - GF_USERS_ALLOW_SIGN_UP=false
      - GF_SERVER_DOMAIN=${GRAFANA_DOMAIN}
      - GF_SERVER_ROOT_URL=${GRAFANA_ROOT_URL}
      - GF_AUTH_DISABLE_LOGIN_FORM=${GRAFANA_DISABLE_LOGIN_FORM}
      - GF_SMTP_ENABLED=${GRAFANA_SMTP_ENABLED}
      - GF_SMTP_HOST=${GRAFANA_SMTP_HOST}
      - GF_SMTP_USER=${GRAFANA_SMTP_USER}
      - GF_SMTP_PASSWORD=${GRAFANA_SMTP_PASSWORD}
      - GF_SMTP_FROM_ADDRESS=${GRAFANA_SMTP_FROM}
    depends_on:
      - prometheus

  loki:
    image: grafana/loki:3.6.7
    restart: unless-stopped
    ports:
      - "3100:3100"
    volumes:
      - ${LOKI_CONFIG_PATH}:/etc/loki/local-config.yaml
      - ${LOKI_DATA_DIR}:/loki
    command:
      - '-config.file=/etc/loki/local-config.yaml'
      - '-target=all'

  alloy:
    image: grafana/alloy:v1.13.2
    restart: unless-stopped
    ports:
      - "12345:12345"
    volumes:
      - ${ALLOY_CONFIG_PATH}:/etc/alloy/config.alloy:ro
      - /var/log:/var/log:ro

  # Node Exporter - Host System Metrics
  node_exporter:
    image: prom/node-exporter:v1.10.2
    restart: unless-stopped
    ports:
      - "9100:9100"
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.rootfs=/rootfs'
      - '--path.sysfs=/host/sys'
      - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'

  # cAdvisor - Container Metrics
  cadvisor:
    image: gcr.io/cadvisor/cadvisor:v0.55.1
    restart: unless-stopped
    privileged: true
    ports:
      - "8081:8080"
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:ro
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    devices:
      - /dev/kmsg
    command:
      - '--housekeeping_interval=30s'
      - '--max_housekeeping_interval=35s'
      - '--event_storage_event_limit=default=0'
      - '--event_storage_age_limit=default=0'
      - '--disable_metrics=disk,diskIO,tcp,udp,percpu,sched,process,hugetlb,referenced_memory'
      - '--docker_only=true'

  # Blackbox Exporter - Endpoint Monitoring
  blackbox_exporter:
    image: prom/blackbox-exporter:v0.28.0
    restart: unless-stopped
    ports:
      - "9115:9115"
    volumes:
      - ${BLACKBOX_CONFIG_PATH}:/etc/blackbox_exporter/config.yml

  grafana-matrix-forwarder:
    build: ./grafana-matrix-forwarder
    restart: unless-stopped
    env_file:
      - .env
