最新消息:

prometheus中的relabel

Linux ipcpu 2714浏览 0评论

prometheus中的relabel.md

relabel顾名思义,就是标签重写,可以允许用户重写标签或者针对标签做一些过滤操作,Prometheus中的relabel有三种,应用范围和工作时段不一样,一定要区分

relabel_config
Relabeling is a powerful tool to dynamically rewrite the label set of a target before it gets scraped.
在被prometheus抓取之前修改,针对的是target

metric_relabel_configs
Metric relabeling is applied to samples as the last step before ingestion.
在被prometheus存储之前修改,针对的是Metric

alert_relabel_configs
Alert relabeling is applied to alerts before they are sent to the Alertmanager.
在被发送到alertmanager之前,针对的是alert

接下来我们详细介绍前两种,第三种我还没有用到。

1. relabel_config

第一种的relabel只针对targets页面出现的label,如下图

relabel_config的action类型

replace: 对标签和标签值进行替换。默认action。
keep: 满足特定条件的实例进行采集,其他的不采集。
drop: 满足特定条件的实例不采集,其他的采集。
hashmod: 这个我也没看懂啥意思,囧。
labelmap: 这个我也没看懂啥意思,囧。
labeldrop: 对抓取的实例特定标签进行删除。
labelkeep: 对抓取的实例特定标签进行保留,其他标签删除。

最常用的是当属Blackbox exporter.的替换了

 scrape_configs:
  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [http_2xx]  # Look for a HTTP 200 response.
    static_configs:
      - targets:
        - http://prometheus.io    # Target to probe with http.
        - https://prometheus.io   # Target to probe with https.
        - http://example.com:8080 # Target to probe with http on port 8080.
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115  # The blackbox exporter's real hostname:port.

还有drop某些label的target

    relabel_configs:
      - action: drop
        source_labels: ['buniess']
        regex: "MT"

2. metric_relabel_configs

这个针对的是metric中的label,如下图

比如我要过滤掉{code="404"}的metric

    metric_relabel_configs:
      - action: drop
        source_labels: ['code']
        regex: "404"

参考资料

https://prometheus.io/docs/prometheus/latest/configuration/configuration/

来自为知笔记(Wiz)

转载请注明:IPCPU-网络之路 » prometheus中的relabel

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址