version: '3.8'
name: knightcrawler-metrics

services:
  prometheus:
    image: prom/prometheus:v2.20.1
    volumes:
      - ./config/prometheus/config.yml:/etc/prometheus/prometheus.yml
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
    ports:
      - "9090:9090"
    networks:
      - knightcrawler-network
    
  grafana:
    image: grafana/grafana:latest
    volumes:
      - ./config/grafana/datasources:/etc/grafana/provisioning/datasources
      - ./config/grafana/dashboards/dashboards.yml:/etc/grafana/provisioning/dashboards/dashboards.yml
      - ./config/grafana/dashboards/logs.json:/var/lib/grafana/dashboards/logs.json
      - grafana-data:/var/lib/grafana
    ports:
      - "3000:3000"
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin_password
    depends_on:
      - prometheus
    networks:
      - knightcrawler-network

  postgres-exporter:
    image: prometheuscommunity/postgres-exporter
    env_file:
      - .env
    environment:
      DATA_SOURCE_NAME: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable"
    networks:
      - knightcrawler-network
      
  promtail:
    image: grafana/promtail:2.9.4
    volumes:
      - /var/lib/docker/containers:/var/lib/docker/containers:ro
      - /var/run/docker.sock:/var/run/docker.sock
      - ./config/promtail/config.yml:/etc/promtail/config.yml
    command: -config.file=/etc/promtail/config.yml
    depends_on:
      - prometheus
      - loki
    networks:
      - knightcrawler-network
      
  loki:
    image: grafana/loki:2.9.4
    command: -config.file=/etc/loki/local-config.yml
    depends_on:
      - prometheus
      - grafana
    volumes:
      - loki-data:/loki
      - ./config/loki/config.yml:/etc/loki/local-config.yml
    networks:
      - knightcrawler-network
        
volumes:
  loki-data:
  grafana-data:
      
networks:
  knightcrawler-network:
    external: true
