# docker-compose-metrics.yml
# Lancer en premier : docker compose -f docker-compose-metrics.yml up -d

services:
  prometheus-config-init:
    image: busybox:latest
    container_name: prometheus-config-init
    volumes:
      - prometheus-config-vol:/config
    command:
      - /bin/sh
      - -c
      - |
        cat > /config/prometheus.yml <<'EOF'
        global:
          scrape_interval: 15s
        scrape_configs:
          - job_name: 'prometheus'
            static_configs:
              - targets: ['localhost:9090']
          - job_name: 'observabilite'
            static_configs:
              - targets: ['172.17.0.1:9100']
          - job_name: 'scaphandre'
            static_configs:
              - targets: ['192.168.56.61:8080']
            fallback_scrape_protocol: "PrometheusText1.0.0"
          - job_name: 'apache_vmservices'
            static_configs:
              - targets: ['apache_exporter_service:9117']
          - job_name: 'vms'
            static_configs:
              - targets: ['192.168.56.18:9100']
        EOF
        echo "Prometheus config created"
    restart: "no"
    networks:
      - observability

  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus-observability
    volumes:
      - prometheus-config-vol:/etc/prometheus:ro
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
    ports:
      - "9090:9090"
    networks:
      - observability
    depends_on:
      - prometheus-config-init

  node_exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    restart: unless-stopped
    pid: "host"
    network_mode: "host"
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.sysfs=/host/sys'
      - '--collector.filesystem.ignored-mount-points="^/(sys|proc|dev|host|etc)($$|/)"'

volumes:
  prometheus-config-vol:

networks:
  observability:
    driver: bridge