version: '3.8'

# To run redis exporter, run: docker compose --profile redis up
# To run memcached and its exporter: docker compose --profile memcached up
#
# Note you may still need to disable/change scraping job configs
# in prometheus.yml
#
volumes:
  prometheus_data:
  grafana_data:
  memcached_data:

services:
  change_vol_ownership:
    image: alpine
    user: root
    volumes:
      - memcached_data:/memcached
    command: chown -R 11211:11211 /memcached

  prometheus:
    image: prom/prometheus:v3.0.0
    restart: always
    volumes:
      - ./prometheus:/etc/prometheus/
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/usr/share/prometheus/console_libraries'
      - '--web.console.templates=/usr/share/prometheus/consoles'
    ports:
      - 9090:9090
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      node-exporter:
        condition: service_started
      change_vol_ownership:
        condition: service_completed_successfully

  memcached:
    image: memcached
    restart: unless-stopped
    ports:
      - "11211:11211"
    command: "-t 8 -m 10000 -c 10000 --pidfile=/memcached/memcached.pid"
    pid: host
    volumes:
      - memcached_data:/memcached
    profiles: [memcached]


  node-exporter:
    image: prom/node-exporter
    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|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)'
    ports:
      - 9100:9100
    restart: always
    deploy:
      mode: global

  grafana:
    image: grafana/grafana:10.1.10
    user: '472'
    restart: always
    environment:
      # do not really need it, just to leave it as an example on how to install plugins here
      - GF_INSTALL_PLUGINS=grafana-clock-panel
      - GF_RENDERING_SERVER_URL=http://renderer:8081/render
      - GF_RENDERING_CALLBACK_URL=http://grafana:3000/
    volumes:
      - grafana_data:/var/lib/grafana
      - ./grafana/provisioning/:/etc/grafana/provisioning/
    env_file:
      - ./grafana/config.monitoring
    ports:
      - 3000:3000
    depends_on:
      - prometheus

  memcached-exporter:
    image: prom/memcached-exporter
    container_name: memcached-exporter
    restart: unless-stopped
    ports:
      - "9150:9150"
    pid: host
    command:
      - --memcached.address=memcached:11211
      - --memcached.pid-file=/memcached/memcached.pid
    volumes:
      - memcached_data:/memcached
    profiles: [memcached]
    depends_on:
      - memcached

  redis-exporter:
    image: quay.io/oliver006/redis_exporter
    profiles: [redis]
    ports:
      - 9121:9121
    extra_hosts:
      - "host.docker.internal:host-gateway"
    restart: always
    environment:
      - REDIS_ADDR=host.docker.internal:6379

  renderer:
    image: grafana/grafana-image-renderer:latest
    ports:
      - 8081
