![](/img/trans.png)
[英]how to make the node-exporter and cadvisor available to prometheus container only?
[英]How can I add a label to the cadvisor and node-exporter metrics?
我的节点导出器指标类似于:
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>",image="<image>",instance="10.1.1.3:8080",job="docker_info",name="<container name>"}
container_memory_usage_bytes{id="<id>",image="<image>",instance="10.1.1.16:8080",job="docker_info",name="<container name>"}
我想添加一个 label ,例如machine_name
,如下所示:
process_cpu_seconds_total{machine_name="cool_machine",instance="10.1.1.1:8080",job="node_info"}
container_memory_usage_bytes{machine_name="cool_machine",id="<id>",image="<image>",instance="10.1.1.1:8080",job="docker_info",name="<container name>"}
当我尝试按机器过滤时,我需要处理 IP (10.1.1.1),这对用户来说不是很友好。 我想配置 node-exporter 和 cadvisor 以将 label 添加到所有指标,这样我就可以识别机器,无论他们现在拥有的 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
...
我找到了解决方案,我可以metric_relabel_configs
使用 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
向static_configs
部分中定义的目标添加标签的最简单方法是使用labels
部分 - 请参阅这些文档。 例如,以下配置会将machine_name
label 添加到给定静态定义目标的抓取指标中:
scrape_configs:
- job_name: node_info
static_configs:
- targets: ['10.1.1.1:9100']
labels:
machine_name: cool_machine_1
- targets: ['10.1.1.2:9100']
labels:
machine_name: cool_machine_2
- targets: ['10.1.1.15:9100']
labels:
machine_name: cool_machine_15
- job_name: docker_info
static_configs:
- targets: ['10.1.1.1:8080']
labels:
machine_name: cool_machine_1
- targets: ['10.1.1.3:8080']
labels:
machine_name: cool_machine_3
- targets: ['10.1.1.16:8080']
labels:
machine_name: cool_machine_16
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.