问题描述
我的节点导出器指标如下:
process_cpu_seconds_total{instance="10.1.1.1:8080",job="node_info"}
process_cpu_seconds_total{instance="10.1.1.2:8080",job="node_info"}
process_cpu_seconds_total{instance="10.1.1.15:8080",job="node_info"}
管理人员:
container_memory_usage_bytes{id="<id>",image="<image>",instance="10.1.1.1:8080",job="docker_info",name="<container name>"}
container_memory_usage_bytes{id="<id>",instance="10.1.1.3:8080",instance="10.1.1.16:8080",name="<container name>"}
process_cpu_seconds_total{machine_name="cool_machine",job="node_info"}
container_memory_usage_bytes{machine_name="cool_machine",id="<id>",name="<container name>"}
当我尝试按机器进行过滤时,我需要处理IP(10.1.1.1),这对用户来说不是很友好。 我想配置node-exporter和cadvisor为所有指标添加标签,这样无论我现在拥有的IP是什么,我都可以识别机器。
顺便说一下,更改DNS以使机器在另一个地址中应答对我来说不是很多选择。
我的普罗米修斯配置类似于:
global:
scrape_interval: 5s
external_labels:
monitor: 'machines_monitor'
scrape_configs:
- job_name: 'node_info'
static_configs:
- targets:
- 10.1.1.1:8080
- 10.1.1.2:8080
- 10.1.1.15:8080
- job_name: 'docker_info'
static_configs:
- targets:
- 10.1.1.1:8080
- 10.1.1.3:8080
- 10.1.1.16:8080
我可以为机器创建一个scrape_configs
并以此开始过滤,但是我不知道这是一个好主意,也许是Prometheus的性能问题。
我正在尝试为指标添加标签,但是我非常欢迎其他帮助识别机器的方法。
解决方法
您可以尝试以下操作:
scrape_configs:
- job_name: 'node_info'
static_configs:
- targets:
- 10.1.1.1:8080
- 10.1.1.2:8080
- 10.1.1.15:8080
relabel_configs:
- source_labels: [__address__]
regex: '10\.1\.1\.1.+'
replacement: cool_machine_1
target_label: machine_name
- source_labels: [__address__]
regex: '10\.1\.1\.2.+'
replacement: cool_machine_2
target_label: machine_name
...
,
我已经找到了解决方案,可以为此使用Prometheus metric_relabel_configs
,我的配置将如下所示:
global:
scrape_interval: 5s
external_labels:
monitor: 'machines_monitor'
scrape_configs:
- job_name: 'node_info'
static_configs:
- targets:
- 10.1.1.1:8080
- 10.1.1.2:8080
- 10.1.1.15:8080
metric_relabel_configs:
- source_labels:
- instance
target_label: instance
regex: '10\.1\.1\.1(.*)'
action: replace
replacement: cool_machine
还有一个相关的问题: Prometheus create label from metric label
在这里,我们可以看到其他一些示例: https://gist.github.com/trastle/1aa205354577ef0b329d4b8cc84c674a
以下是相关文章: https://www.robustperception.io/controlling-the-instance-label