当前位置:网站首页>Prometheus的relabel_configs和metric_relabel_configs解释及用法示例
Prometheus的relabel_configs和metric_relabel_configs解释及用法示例
2022-04-23 06:01:00 【洒满阳光的午后】
配置释义
先看两个配置的所处位置:
global:
......
# A list of scrape configurations.
scrape_configs:
# The job name assigned to scraped metrics by default.
- job_name: <job_name>
........
# List of target relabel configurations.
relabel_configs:
[ - <relabel_config> ... ]
# List of metric relabel configurations.
metric_relabel_configs:
[ - <relabel_config> ... ]
<relabel_config> relabel_config | Prometheus
# The source labels select values from existing labels. Their content is concatenated
# using the configured separator and matched against the configured regular expression
# for the replace, keep, and drop actions.
[ source_labels: '[' <labelname> [, ...] ']' ]
# Separator placed between concatenated source label values.
[ separator: <string> | default = ; ]
# Label to which the resulting value is written in a replace action.
# It is mandatory for replace actions. Regex capture groups are available.
[ target_label: <labelname> ]
# Regular expression against which the extracted value is matched.
[ regex: <regex> | default = (.*) ]
# Modulus to take of the hash of the source label values.
[ modulus: <int> ]
# Replacement value against which a regex replace is performed if the
# regular expression matches. Regex capture groups are available.
[ replacement: <string> | default = $1 ]
# Action to perform based on regex matching.
[ action: <relabel_action> | default = replace ]
区别:relabel_configs用于在抓取metrics之前修改target的已有标签,已有标签也即配置中的source_labels包括(可从Prometheus UI的target页面查看)__address__、__meta_filepath、__metrics_path__、__scheme__、job以及target中手动添加的其他标签。

metric_relabel_configs用于修改抓取后得到的metric的标签,可用的source_labels包括instance、job已经target中手动添加的其他标签。
用法示例
使用已有标签创建一个新标签
例如给指标添加一个IP标签,使用如下配置实现:
# relabel_config
- job_name: 'node'
file_sd_configs:
- refresh_interval: 1m
files:
- node_targets.yml
relabel_configs:
- source_labels: ['__address__']
regex: (.*):.*
target_label: 'IP'
或者使用metric_relabel_configs,注意该配置不对up指标生效。
# metric_relabel_config
- job_name: 'node'
file_sd_configs:
- refresh_interval: 1m
files:
- node_targets.yml
metric_relabel_configs:
- source_labels: ['instance']
regex: (.*):.*
target_label: 'IP'
给一组job中指标添加一个全新标签
例如添加一个公共标签env=“test”:
- job_name: 'node'
file_sd_configs:
- refresh_interval: 1m
files:
- config/node_targets.yml
relabel_configs:
- target_label: 'env'
replacement: 'test'
这里使用relabel_configs或者metric_relabel_configs均可,因为不涉及source_labels直接使用了字符串替代。
版权声明
本文为[洒满阳光的午后]所创,转载请带上原文链接,感谢
https://zhangrongjie.blog.csdn.net/article/details/121554543
边栏推荐
猜你喜欢
随机推荐
你应该知道的 JVM 基础知识
异常记录-5
异常记录-7
关于注解1
file_ get_ Two solutions to content accessing SSL errors
Sum (if) in MySQL_ Sum (if ()) in MySQL
Oracle数据库性能分析之常用视图
Oracle net service: listener and service name resolution method
bcc安装和基本工具使用说明
Will restarting the Oracle listener break the existing connection
fdfs启动
压力测试工具 Jmeter
2021年国产数据库12强介绍
Installing redis using a small leather panel in the window environment
volatile 关键字的三大特点【数据可见性、指令禁止重排性、不保证操作原子性】
Common views of Oracle database performance analysis
Oracle Net Service:监听器与服务名解析方法
Implementation of leetcode question brushing str ()
TP5 error reporting variable type error: array solution
2021-09-18



![[ES6 quick start]](/img/9e/4c4be5907c1f7b3485c2f4178b9150.png)





