如何手动删除Prometheus和Grafana数据并设置存储保留限制
解决Prometheus磁盘占满问题并配置存储保留限制
一、彻底清除历史监控数据
你删除容器后磁盘没释放,是因为Prometheus的监控数据存在Docker**命名卷prometheus_data**里,容器删除不会自动清理卷数据,直接删除该卷即可释放空间:
- 停止并删除Prometheus容器(如果还没操作):
docker stop prometheus && docker rm prometheus
- 删除存储监控数据的命名卷:
docker volume rm prometheus_data
二、修改Docker Compose配置,添加存储保留参数
在原Prometheus的command段中补充缺失的两个限制参数,修改后的完整配置如下:
prometheus: image: prom/prometheus:latest container_name: prometheus restart: unless-stopped volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml - prometheus_data:/prometheus command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' - '--web.console.libraries=/etc/prometheus/console_libraries' - '--web.console.templates=/etc/prometheus/consoles' - '--web.enable-lifecycle' - '--storage.tsdb.retention.time=60m' # 新增:仅保留最近60分钟的数据 - '--storage.tsdb.retention.size=512MB' # 新增:数据存储上限512MB expose: - 9090 networks: - monitoring grafana: image: grafana/grafana:latest ports: - 3000:3000 networks: - monitoring
三、重新启动服务
执行以下命令重新部署服务,新的存储限制会立即生效:
docker-compose up -d
重启后Prometheus会自动创建新的prometheus_data卷,后续会严格按照配置的时间和容量限制自动清理旧数据,避免磁盘再次被占满。
内容的提问来源于stack exchange,提问作者Teoman shipahi
相关产品推荐
相关产品推荐

