version: '3.8' services: app: build: context: .. dockerfile: deployment/Dockerfile ports: - "8111:8000" environment: - APP_ENV=development - LOG_LEVEL=INFO - METRICS_ENABLED=true # Redis 指标存储配置 - REDIS_HOST=redis - REDIS_PORT=6379 - REDIS_DB=0 # 指标配置文件路径 - METRICS_CONFIG_PATH=config/metrics.yaml volumes: - ../src:/app/src - ../config:/app/config restart: unless-stopped depends_on: redis: condition: service_healthy healthcheck: test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/healthz')"] interval: 30s timeout: 3s retries: 3 start_period: 5s # Redis - 用于集中式指标存储 redis: image: redis:7-alpine ports: - "6380:6379" volumes: - redis_data:/data command: redis-server --appendonly yes restart: unless-stopped healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 10s timeout: 3s retries: 3 prometheus: image: prom/prometheus:latest ports: - "9090:9090" volumes: - ../monitoring/prometheus.yml:/etc/prometheus/prometheus.yml - ../monitoring/alerts:/etc/prometheus/rules - prometheus_data:/prometheus command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' restart: unless-stopped depends_on: - app grafana: image: grafana/grafana:latest ports: - "3000:3000" environment: - GF_SECURITY_ADMIN_PASSWORD=admin volumes: - grafana_data:/var/lib/grafana - ../monitoring/grafana:/etc/grafana/provisioning restart: unless-stopped depends_on: - prometheus volumes: prometheus_data: grafana_data: redis_data: