# Monitoring stack — Prometheus + postgres-exporter + Grafana
# Start: cd monitoring && docker compose up -d --build
# UI: Grafana http://192.168.1.211:3002 · Prometheus http://192.168.1.211:9090

services:
  prometheus:
    image: prom/prometheus:v2.53.2
    container_name: prometheus-homelab
    restart: unless-stopped
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - ./prometheus/targets:/etc/prometheus/targets:ro
      - prometheus-homelab-data:/prometheus
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --web.enable-lifecycle
    extra_hosts:
      - "host.docker.internal:host-gateway"
    networks:
      - homelab-monitor

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

  grafana:
    build:
      context: ..
      dockerfile: Dockerfile.grafana
    image: grafana-homelab:latest
    container_name: grafana-homelab
    restart: unless-stopped
    ports:
      - "3002:3000"
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-WaQTUw2t}
      GF_USERS_DEFAULT_THEME: dark
      GF_SERVER_ROOT_URL: http://192.168.1.211:3002
      PG_USER: mo
      PG_DATABASE: homelab
      HOMELAB_PG_PASSWORD: ${PG_PASSWORD:-WaQTUw2t}
    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:
  prometheus-homelab-data:
  grafana-homelab-data:

networks:
  homelab-monitor:
    name: homelab-monitor
    driver: bridge
