解决 Prometheus 报错 sample limit exceeded in scrape target 抓取指标超限修复
排查 Prometheus 监控目标状态变为 DOWN,错误提示 sample limit exceeded (50000),分析 单端点样本超限与 sample_limit 配置调优。
问题现象
Prometheus Targets 页面显示核心微服务状态变红并标为 DOWN:
Down: sample limit exceeded (actual 54,201 > limit 50,000)
触发根因
- Prometheus 在抓取作业(
scrape_config)中配置了保护性的sample_limit: 50000; - 业务端在指标中加入了用户 ID、订单号或 UUID 等高基数(High Cardinality)标签,导致单次抓取吐出的时间线暴增突破上限;
- Prometheus 为防范内存爆满,主动截断并中止该端点的指标采集。
解决步骤
使用 metric_relabel_configs 在拉取时剔除高基数无用指标
在 prometheus.yml 中丢弃高频爆炸指标:
scrape_configs:
- job_name: 'my-service'
sample_limit: 100000
metric_relabel_configs:
- source_labels: [__name__]
regex: '(http_request_duration_seconds_bucket|jvm_gc_memory_allocated_bytes_total)'
action: keep
- regex: 'user_id|order_id'
action: labeldrop
适度调大该业务专用 job 的 sample_limit
按实际业务规模放宽限制至 150000。
验证确认
重载 Prometheus 配置:
curl -X POST http://localhost:9090/-/reload
端点状态变绿(UP),高基数噪声被清洗,内存占用健康稳定。


