问题描述
我们正在容器中运行节点导出器.为了快速确定每个节点导出器在哪个主机上运行,我创建了一个如下所示的指标:host{host="$HOSTNAME",node="$CONTAINER_ID"} 1
We are running the node-exporter in containers. To quickly identify on which host each node-exporter is running, I created a metric that looks like this: host{host="$HOSTNAME",node="$CONTAINER_ID"} 1
我正在寻找一种方法来提取 host=
中的主机名,并为每个节点导出器实例创建一个标签作为主机名标签.我尝试了多种配置,但似乎都不起作用.当前的 prometheus 配置如下所示:
I'm looking for a way to extract the hostname in host=
and create a label for each node-exporter instance as a hostname label. I tried numerous configurations and none seem to work. Current prometheus config looks like this:
scrape_configs:
- job_name: 'node'
scrape_interval: 10s
scrape_timeout: 5s
metrics_path: /metrics
scheme: http
dns_sd_configs:
- names:
- tasks.master-nodeexporter
refresh_interval: 30s
type: A
port: 9100
relabel_configs:
- source_labels: ['host']
regex: '"(.*)".*'
target_label: 'hostname'
replacement: '$1'
推荐答案
这是不可能的,因为目标重新标记发生在刮取之前.
This is not possible, as target relabelling happens before the scrape.
您首先要做的是使用服务发现来获得正确的主机名,而 dns_sd_configs
则无法做到这一点.您可能会查看 Consul 和 https://www.robustperception.io/controlling 之类的内容-实例标签/
What you want to do here is use service discovery to have the right hostname in the first place, which is not possible with dns_sd_configs
. You might look at something like Consul and https://www.robustperception.io/controlling-the-instance-label/
这篇关于普罗米修斯从公制标签创建标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!