当前位置:网站首页>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
边栏推荐
猜你喜欢
LeetCode刷题|368最大整除子集(动态规划)
Redis 详解(基础+数据类型+事务+持久化+发布订阅+主从复制+哨兵+缓存穿透、击穿、雪崩)
JS performance optimization
Decentralized Collaborative Learning Framework for Next POI Recommendation
数据库基本概念:OLTP/OLAP/HTAP、RPO/RTO、MPP
Kids and COVID: why young immune systems are still on top
LeetCode刷题|897递增顺序搜索树
try --finally
阅读笔记:Meta Matrix Factorization for Federated Rating Predictions
多线程
随机推荐
Solution to page cache problem (use with caution)
[MySQL basics] startup options, system variables and status variables
【MySQL基础篇】启动选项、系统变量、状态变量
openvswitch vlan网络实践
Leetcode integer plus one
LeetCode刷题|13罗马数字转整数
Concurrent optimization request
【漏网之鱼】Ansible AWX调用playbook传参问题
High performance gateway for interconnection between VPC and IDC based on dpdk
Implementation of leetcode question brushing str ()
Tensorflow&&Pytorch常见报错
异常记录-11
使用百度智能云人脸检测接口实现照片质量检测
JS implementation of web page rotation map
Introduction to the top 12 domestic databases in 2021
异常记录-16
JS realizes modal box dragging
ubuntu下搭建mysql环境 & 初识SQL
[ES6 quick start]
Virtio and Vhost_ Net introduction