prometheus 重新打标

定义在job字段内
示例1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

consul_sd_configs:
- server: "192.168.1.40:8500"
tags:
- "prometheus"
refresh_interval: 2m

# All nodes
- job_name: 'nodes'
consul_sd_configs:
- server: "192.168.1.40:8500"
tags:
- "nodes"
refresh_interval: 2m

relabel_configs:
- source_labels:
- __scheme__
- __address__
- __metrics_path__
regex: "(http|https)(.*)"
separator: ""
target_label: "endpoint" # 添加标记,值为replacement内容
replacement: "${1}://${2}"
action: replace

metric_relabel_configs: # 删除指标
#- source_labels:
# - __name__
# regex: "go_info.*"
# action: drop
# metric_relabel_configs:
- source_labels:
- __name__
regex: "salar.*"
action: drop

示例2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'nodes'
file_sd_configs:
- files:
- targets/nodes-*.yaml
refresh_interval: 1m

relable_configs:
- regex: "(app)"
replacement: "${1}_name" # 重命名为xxx_name
action: labelmap # 标签名的重命名

- regex: "(app)" #删除app这个标签
action: labeldrop

总结

drop: 正则匹配成功就删除
keep: 正则匹配成功就保留

relabel_configs:
抓取前的标记,针对target自身标记,将来自服务发现的元数据标签中的信息附加到指标上标签上和过滤目标的作用

metric_relabel_configs:
抓取后的标记,针对抓取指标的标记,用于删除指标、从指标中删除标签、添加编辑修改指标的值