# Grafana — aparte stack (projectmap: homelab-command).
#
# Start (vanuit deze map):
#   export PG_PASSWORD='jouw_postgres_wachtwoord'
#   docker compose -f docker-compose.grafana.yml up -d --build
#
# UI: http://<NAS-IP>:3002  (standaard host-poort; 3001 was bezet op deze host)
#    login: admin / GRAFANA_ADMIN_PASSWORD
#
# Vereist: postgres container heet postgres-homelab en luistert intern op 5432.
# Eénmalig (DNS tussen Prometheus en postgres-exporter op Synology bridge):
#   sh scripts/docker_monitoring_join.sh homelab-monitor
# Daarna: docker network connect homelab-monitor postgres-homelab   # als exporter DB niet bereikt
#
# Dashboards (Grafana.com IDs): PostgreSQL 9628, Proxmox 10347, Neo4j 10371,
# Synology overview 14364, Node Exporter 1860 — onder folder "Infrastructure".
# Prometheus scrape: postgres-exporter + optioneel Neo4j :2004 / Proxmox via targets/extra.yml.

services:
  prometheus:
    image: prom/prometheus:v2.53.2
    container_name: prometheus-homelab
    restart: unless-stopped
    ports:
      - "${PROMETHEUS_PORT:-9090}:9090"
    volumes:
      - ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - ./monitoring/prometheus/targets:/etc/prometheus/targets:ro
      - prometheus-homelab-data:/prometheus
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --web.enable-lifecycle
    networks:
      - homelab-monitor

  postgres-exporter:
    image: prometheuscommunity/postgres-exporter:latest
    container_name: postgres-exporter-homelab
    restart: unless-stopped
    ports:
      - "${POSTGRES_EXPORTER_PORT:-9187}:9187"
    environment:
      DATA_SOURCE_NAME: "postgresql://${PG_USER:-mo}:${PG_PASSWORD}@postgres-homelab:5432/${PG_DATABASE:-homelab}?sslmode=disable"
    networks:
      - homelab-monitor

  grafana:
    build:
      context: .
      dockerfile: Dockerfile.grafana
    image: grafana-homelab:latest
    container_name: grafana-homelab
    restart: unless-stopped
    ports:
      - "${GRAFANA_PORT:-3002}:3000"
    environment:
      GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:-admin}
      GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-changeme_grafana}
      GF_USERS_DEFAULT_THEME: dark
      GF_SERVER_ROOT_URL: ${GRAFANA_ROOT_URL:-http://localhost:3002}
      PG_USER: ${PG_USER:-mo}
      PG_DATABASE: ${PG_DATABASE:-homelab}
      HOMELAB_PG_PASSWORD: ${PG_PASSWORD:-}
    volumes:
      - grafana-homelab-data:/var/lib/grafana
      - ./grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro
      - ./grafana/dashboards/homelab:/var/lib/grafana/dashboards/homelab:ro
      - ./grafana/dashboards/imported:/var/lib/grafana/dashboards/imported:ro
    depends_on:
      - prometheus
    networks:
      - homelab-monitor

volumes:
  grafana-homelab-data:
  prometheus-homelab-data:

networks:
  homelab-monitor:
    driver: bridge
