You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker环境下如何通过Prometheus的relabel_config为NetApp Harvest2指标添加前缀?

Fixing NetApp Harvest Metric Prefix Issue (Correcting Prometheus Configuration Mistakes)

Let's break down what's going wrong with your current setup and fix it step by step:

1. You're using the wrong relabel stage for renaming metrics

Your current config uses relabel_configs to modify the __name__ label (metric name), but that's not where this operation belongs:

  • relabel_configs runs before Prometheus scrapes metrics — it only handles target metadata like instance, job, or custom labels attached to scrape targets. At this point, no metric data exists yet, so trying to modify __name__ here does nothing useful.
  • To modify actual metric names (and labels on scraped metrics), you need to use metric_relabel_configs, which runs after metrics are collected from the target.

2. Your keep rule is filtering out all Harvest targets

You've repeated custom_labels four times in source_labels and used a regex that expects four non-empty values separated by semicolons. Unless every one of your Harvest targets has this label with exactly four values formatted that way, this rule will discard all targets entirely — which explains why the Harvest collector disappears from Prometheus/Grafana.

Corrected Prometheus Config

Here's the adjusted config that adds the netapp_ prefix correctly and fixes the target filtering issue:

job_name: harvest
scrape_interval: 1m
scrape_timeout: 1m
metrics_path: /metrics
# Remove or adjust the relabel_configs only if you need to filter targets based on metadata
# relabel_configs:
#   - action: keep
#     source_labels: [custom_labels]  # Only list the label once, even if it has multiple values
#     regex: '.+;.+;.+;.+'  # Keep this only if your targets actually have 4 semicolon-separated values
# Use metric_relabel_configs to rename metrics
metric_relabel_configs:
  - action: replace
    source_labels: [__name__]
    regex: (.*)
    target_label: __name__
    replacement: 'netapp_$1'
file_sd_configs:
  - refresh_interval: 10s
    files:
    - targets/harvest.yml

Key Notes:

  • If you don't actually need the keep rule (e.g., you don't need to filter targets), just delete that entire relabel_configs block — it's likely the main reason your collector wasn't showing up.
  • If you do need to filter targets by custom_labels, remember that Prometheus automatically joins multiple values of the same label with semicolons. You only need to list the label once in source_labels, not four times.

How to Verify:

  1. Update your Prometheus config file with the above changes
  2. Restart Prometheus to apply the config
  3. Check the Targets page in Prometheus (e.g., http://your-prometheus-ip:9090/targets) — the harvest job should now show as UP
  4. In Prometheus's query editor, search for metrics starting with netapp_ — you should see all Harvest metrics prefixed correctly

内容的提问来源于stack exchange,提问作者Philip

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 20:52:38