深色模式
Remote Write 远端存储
本地 TSDB 存几个月就吃满磁盘。Remote Write 把数据旁路写入远端存储做长期保留与全局查询。
适用环境
- 已部署 Prometheus
- 已有远端存储接收端(本文以 Mimir 为例,Thanos 类似)
bash
# 查看当前存储用量,判断是否需要远端存储
du -sh /var/lib/prometheus 2>/dev/null1
2
2
操作步骤
1. 在 prometheus.yml 配置 remote_write
yaml
remote_write:
- url: http://mimir:9009/api/v1/push
queue_config:
max_samples_per_send: 2000
capacity: 10000
remote_timeout: 30s1
2
3
4
5
6
2
3
4
5
6
2. 只写需要的指标(降带宽)
yaml
write_relabel_configs:
- regex: 'job|instance|__name__'
action: labelkeep1
2
3
2
3
3. 重启/热加载使生效
bash
curl -X POST http://localhost:9090/-/reload1
验证
bash
# 查看 remote write 队列健康状况
curl -s http://localhost:9090/api/v1/status/tsdb | head -c 3001
2
2
在远端存储侧执行相同 PromQL,应能查到数据。
常见坑
远端写入失败不阻断本地
Remote write 是异步的,远端挂了本地照常,但会有队列积压,需监控 prometheus_remote_storage_queue_capacity。
不要双写造成重复
同时开多个 remote_write 到不同后端且查询端未去重,会导致指标翻倍。