services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    user: "${DUID}:${DGID}"
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
      - ./prometheus/prometheus_db:/var/lib/prometheus
      - ./prometheus/prometheus_db:/prometheus
      - ./prometheus/prometheus_db:/etc/prometheus
      - ./prometheus/alert.rules:/etc/prometheus/alert.rules
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--web.route-prefix=/'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
    restart: unless-stopped
    ports:
      - '9090:9090'

  # cadvisor collects metrics about running containers
  cadvisor:
    image: gcr.io/cadvisor/cadvisor:v0.47.2
    container_name: cadvisor
    ports:
    - 8090:8080
    volumes:
    - /:/rootfs:ro
    - /var/run:/var/run:rw
    - /sys:/sys:ro
    - /var/lib/docker/:/var/lib/docker:ro
    - /var/run/docker.sock:/var/run/docker.sock:rw

  grafana:
    image: grafana/grafana
    user: "${DUID}:${DGID}"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=secure_pass
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    volumes:
      - ./grafana/grafana_config/grafana.ini:/etc/grafana/grafana.ini
      - ./grafana/grafana_db:/var/lib/grafana
      - ./grafana/grafana_provisioning/grafana-datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
      - ./grafana/grafana_provisioning/grafana-default-provisioning.yaml:/etc/grafana/provisioning/dashboards/default.yaml
      - ./grafana/grafana_dashboards/Docker-monitoring.json:/var/lib/grafana/dashboards/Docker-monitoring.json
      - ./grafana/grafana_dashboards/Loki-Logs.json:/var/lib/grafana/dashboards/Loki-Logs.json

    depends_on:
      - prometheus
    ports:
      - '3000:3000'

  # loki save and analyze logs
  loki:
    image: grafana/loki:2.8.0
    ports:
      - "3100:3100"
    command: -config.file=/etc/loki/local-config.yaml

  # promtail send docker logs to loki
  promtail:
    image: grafana/promtail:2.8.0
    volumes:
      - /var/log:/var/log
    command: -config.file=/etc/promtail/config.yml

  # grafana image renderer
  renderer:
    image: grafana/grafana-image-renderer:latest
    container_name: grafana-image-renderer
    expose:
      - "8081"
    environment:
      ENABLE_METRICS: "true"

  # fluent-bit send logs to loki
  fluent-bit:
    image: grafana/fluent-bit-plugin-loki:latest
    container_name: fluent-bit
    environment:
      - LOKI_URL=http://loki:3100/loki/api/v1/push
    volumes:
      - ./fluent_bit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
    ports:
      - "24224:24224"
      - "24224:24224/udp"

  # opentelemetry collector
  otel-collector:
    image: otel/opentelemetry-collector:latest
    ports:
      - 55680:55680
      - 4317:4317
    volumes:
      - ./otlp_collector/otel-config.yaml:/etc/otel-collector-config.yaml
    command: ["--config", "/etc/otel-collector-config.yaml"]

  # tempo is a distributed tracing backend
  tempo:
    image: grafana/tempo:latest
    command: [ "-config.file=/etc/tempo.yaml" ]
    volumes:
      - ./tempo/tempo.yaml:/etc/tempo.yaml
      - ./tempo/tempo-data:/tmp/tempo
    ports:
      - 3102:3100

