解决 Prometheus 报错 remote_write dropped samples 队列溢出
分析 Prometheus 远程写入抛出 dropped samples due to queue full 根因,详解 queue_config 并发分片与重试调优参数。
问题现象
Prometheus 向远端时序库(如 VictoriaMetrics、Thanos Receive、Cortex)推送指标时发生丢弃,Prometheus 日志输出:
ts=2026-11-15T08:52:00.123Z caller=dedup.go:112 component=remote level=warn remote_name=vm msg="Dropped samples, queue is full" dropped_samples=15023
监控指标 prometheus_remote_storage_dropped_samples_total 持续上升。
触发根因
- 远程存储端写入吞吐饱和(限流或写入慢):远端时序库接收并发能力有限,返回 HTTP 429 或处理延迟上升。
- Prometheus queue_config 并发分片(shards)配置过小:Prometheus 默认分配的
max_shards(如 10)无法匹配每秒数百万指标的大规模写入需求。 - 单批次大小(max_samples_per_send)设置过小:网络往返开销占比过高。
诊断排查步骤
- 检查 Prometheus 当前 remote_write 内部指标:
curl -s http://127.0.0.1:9090/metrics | grep "prometheus_remote_storage"
关注 prometheus_remote_storage_highest_timestamp_in_seconds 与 prometheus_remote_storage_queue_highest_sent_timestamp_seconds 的延迟差值。
解决步骤与操作命令
步骤一:调大 queue_config 并发分片上限
编辑 prometheus.yml,在 remote_write 段落下优化队列参数:
remote_write:
- url: "http://victoriametrics:8428/api/v1/write"
remote_timeout: 30s
queue_config:
capacity: 50000 # 队列内部样本容量
max_shards: 100 # 允许动态扩展的最大并发分片数
min_shards: 16 # 最小保底分片数
max_samples_per_send: 5000 # 单批发送的最大采样点数
batch_send_deadline: 5s # 批处理等待超时
min_backoff: 100ms
max_backoff: 5s
步骤二:开启只发送必要指标(metric_relabel_configs)
剔除无用且高基数的冷门指标,大幅减轻远程传输压力:
metric_relabel_configs:
- source_labels: [__name__]
regex: "(container_tasks_state|http_request_duration_seconds_bucket)"
action: drop
步骤三:重载 Prometheus 配置
curl -X POST http://127.0.0.1:9090/-/reload
验证方法
再次观察 Prometheus 的丢点监控指标:
curl -s http://127.0.0.1:9090/metrics | grep "prometheus_remote_storage_dropped_samples_total"
确认丢弃指标计数器停止增长,prometheus_remote_storage_shards 随着写入速率平稳扩缩容。


