DEBUG.WIKI
RackNerd;$21.99/年 · 1GB KVM
搬瓦工;先看线路,再选 VPS;CN2 GIA · 对应线路套餐;查看线路 →
腾讯云;让你的想法跑起来;轻量服务器 · 建站 / Docker / API;查看产品 →

解决 Prometheus 报错 remote write dropped samples 丢点异常

分析 Prometheus 远端写入 remote_write 队列积压、丢点与 429 报错根因,详解队列并发、容量与重试参数调优步骤。

问题现象

Prometheus 抓取指标正常,但远程写入存储(如 VictoriaMetrics、Thanos Receive、Grafana Mimir)时产生大量丢点。Prometheus 日志频繁打印警告或报错:

level=warn ts=2026-11-15T08:00:00.123Z caller=dedupe.go:112 component=remote
msg="Dropped sample, queue is full" subendpoint=http://victoriametrics:8428/api/v1/write

同时 Prometheus 指标 prometheus_remote_storage_dropped_samples_total 持续上升,下游监控看板图表断崖缺失。

触发根因

  1. 远程存储端写入吞吐受限:目标 TSDB(如 VictoriaMetrics)处理能力饱和,或者其反向代理触发了 HTTP 429 Too Many Requests / 503 限流。
  2. Prometheus remote_write 队列参数过于保守:默认队列深度 capacity 和并发度 max_shards 偏小,突发大规模时序激增时写入管道被瞬间填满。
  3. 网络链路带宽或长连接复用受限:TCP 连接频繁新建或超时丢包。

诊断排查步骤

  1. 检查 Prometheus 当前 remote_write 运行指标:
curl -s http://localhost:9090/api/v1/query?query=rate(prometheus_remote_storage_dropped_samples_total[5m])
  1. 查看当前活跃分片数与队列饱和度:
curl -s http://localhost:9090/api/v1/query?query=prometheus_remote_storage_shards

解决步骤与操作命令

步骤一:调优 prometheus.yml 中 remote_write 队列配置

修改 prometheus.yml 中的 queue_config 块,提高吞吐能力与缓存深度:

remote_write:
  - url: "http://victoriametrics:8428/api/v1/write"
    remote_timeout: 30s
    queue_config:
      capacity: 50000
      max_shards: 200
      min_shards: 10
      max_samples_per_send: 5000
      batch_send_deadline: 5s
      min_backoff: 100ms
      max_backoff: 5s

步骤二:启用指标写入前过滤(write_relabel_configs)

剔除无用的大基数指标,直接降低写入带宽压力:

    write_relabel_configs:
      - source_labels: [__name__]
        regex: "container_tasks_state|kube_pod_status_reason"
        action: drop

步骤三:重载配置并观察

向 Prometheus 进程发送 SIGHUP 信号或触发热重载:

curl -X POST http://localhost:9090/-/reload

检查 Prometheus 日志确认配置生效:

journalctl -u prometheus -f | grep -i "remote"

确认 dropped_samples_total 指标增量归零,监控数据完整入库。