[英]Prometheus relabeling not working as expected
I would like to employ Prometheus' relabeling for adding a label hostname
, which should be a more concise version of instance
as provided by targets. 我想聘请普罗米修斯重新贴标签添加标签
hostname
,这应该是一个更简洁的版本, instance
由目标提供。 This should allow more compact legends in Grafana dashboards. 这应该允许Grafana仪表板更紧凑的传说。
For instance, when __address__
has been set to myhost.mydomain.com:8080
, hostname
should be set to myhost
. 例如,当
__address__
已被设置为myhost.mydomain.com:8080
, hostname
应设置为myhost
。 I am using __address__
rather than instance
as source_label
, because the second is apparently not yet set when relabeling occurs. 我使用
__address__
而不是instance
为source_label
,因为第二个是显然重新贴标签时发生尚未确定。
The relevant excerpt of my prometheus.yaml
looks as follows (it is meant to employ a lazy regular expression): 我的有关摘录
prometheus.yaml
如下所示(是指采用一种懒惰的正则表达式):
- job_name: 'node_exporter'
static_configs:
- targets: ['myhost1.mydomain.com:8080',
'myhost2.mydomain.com:8080']
relabel_configs:
- source_labels: ['__address__']
regex: '^([^\.:]+?)'
replacement: ${1}
target_label: 'hostname'
The expected new label hostname
is not yet added. 预期新的标签
hostname
还没有被添加。 What could be wrong in my setup? 出了什么问题在我的设置?
With this regex (with a non-capturing group ) things have come to work: '(.+?)(?:[\\\\.:].+)?'
与此正则表达式(与非捕获组 )事情已经来上班了:
'(.+?)(?:[\\\\.:].+)?'
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.