Prometheus之自定义标签
前言:
我们一般通过grafana导入Dashboard模板用来展示数据,但是有时候需要自己定义展示项目,这时需要自己在Prometheus重新自定义标签,并在grafana进行应用。
1、Prometheus标签重命名
[root@prome-01 prometheus]# pwd
/opt/prometheus
[root@prome-01 prometheus]# cat prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
remote_write:
- url: http://192.66.255.120:8428/api/v1/write
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets: ['192.66.255.120:9093']
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
- "/opt/rules/*_rules.yml"
# 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'.
- job_name: 'prometheus-server'
file_sd_configs:
- refresh_interval: 1m
files:
- targets/server.yml
relabel_configs:
- source_labels: [__address__]
target_label: instance
regex: (.*):(.*)
replacement: $1
action: replace
- job_name: 'Linux'
file_sd_configs:
- refresh_interval: 1m
files:
- targets/linux.json
2、在target yml文件中定义标签
[root@prome-01 prometheus]# cat targets/server.yml
- targets: [ '192.66.255.120:9100' ]
labels: {'ProjectName': '用户中心-生产', 'TargetName': '普罗米修斯服务端', 'Zone': 'ZZW'}
3、grafana利用自定义标签定义展示项目
- 点击服务器资源总览表右上角三个点
- 点击编辑
- 进入编辑界面,点击Transform data(转换数据)
- 点击Filter fields by name,选择TargetName标签,此标签是在prometheus yml文件中定义的标签,会自动加载过来。
- 给标签命名
4、标签重命名参考