version: "3.8"

networks:
  loki:
    driver: bridge
  monitoring_network:
    driver: bridge

services:
  loki:
    image: grafana/loki:2.9.2
    ports:
      - "3100:3100"
    command: -config.file=/etc/loki/local-config.yaml
    networks:
      - loki

  promtail:
    image: grafana/promtail:2.9.2
    volumes:
      - /var/log:/var/log
    command: -config.file=/etc/promtail/config.yml
    networks:
      - loki

  grafana:
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    entrypoint:
      - sh
      - -euc
      - |
        mkdir -p /etc/grafana/provisioning/datasources
        cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
        apiVersion: 1
        datasources:
        - name: Loki
          type: loki
          access: proxy
          orgId: 1
          url: http://loki:3100
          basicAuth: false
          isDefault: true
          version: 1
          editable: false
        EOF
        /run.sh
    image: grafana/grafana:latest
    ports:
      - "3050:3000"
    networks:
      - loki
      - monitoring_network

  prometheus:
    image: prom/prometheus
    container_name: prometheus
    ports:
      - "3034:9090"  # Expose Prometheus on port 3034
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    networks:
      - monitoring_network

  node_exporter:
    image: prom/node-exporter
    container_name: node_exporter
    ports:
      - "9100:9100"  # Expose Node Exporter on port 9100
    networks:
      - monitoring_network

  apache_exporter:
    image: bitnami/apache-exporter
    container_name: apache_exporter
    ports:
      - "8082:9117"  # Expose Apache Exporter on port 8082
    environment:
      - APACHE_URL=http://your_apache_container:80/server-status?auto  # Change to your Apache endpoint
    networks:
      - monitoring_network
