| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- services:
- prometheus:
- image: registry.cn-chengdu.aliyuncs.com/reghao/prometheus:2.54.1
- container_name: prometheus
- restart: always
- ports:
- - "9090:9090"
- command:
- - '--config.file=/etc/prometheus/prometheus.yml'
- # 极致内存优化参数:控制内存中缓存的数据块数量
- - '--storage.tsdb.min-block-duration=2h'
- - '--storage.tsdb.max-block-duration=2h'
- # 减少历史保留时间,节省资源
- - '--storage.tsdb.retention.time=7d'
- - '--web.enable-admin-api'
- - '--web.enable-lifecycle'
- volumes:
- - /etc/localtime:/etc/localtime:ro
- - /opt/docker/prometheus/conf/prometheus.yml:/etc/prometheus/prometheus.yml
- - /opt/docker/prometheus/rules:/etc/prometheus/rules
- - /opt/docker/prometheus/data:/prometheus
- # 限制资源使用
- deploy:
- resources:
- limits:
- cpus: '0.5' # 最高使用 0.5 核
- memory: 512M # 强制上限
- reservations:
- memory: 128M # 启动预留
- logging:
- driver: "json-file"
- options:
- max-size: "10m" # 单个日志文件最大 10MB
- max-file: "3" # 最多保留 3 个归档文件
- grafana:
- image: registry.cn-chengdu.aliyuncs.com/reghao/grafana_grafana-oss:11.2.2
- container_name: grafana
- user: root # 相当于 -u root
- privileged: true
- restart: always
- ports:
- - "3000:3000"
- volumes:
- - /etc/localtime:/etc/localtime:ro
- - /opt/docker/grafana/data:/var/lib/grafana
- # --- 资源限制 ---
- deploy:
- resources:
- limits:
- cpus: '0.5'
- memory: 256M
- reservations:
- memory: 128M
- # --- 日志限制 ---
- logging:
- driver: "json-file"
- options:
- max-size: "10m"
- max-file: "2"
|