Prometheus - 从 file_sd 配置地址创建一个新标签
Prometheus - create a new label from file_sd configs address
我有一些 file_sd 配置,目标格式为 'ip hostname'
例如'10.10.11.12 foo'
我需要将 foo 值提取到新标签“hostname”,然后将添加端口值“:9100”添加到 ip 并将其分配给 target_label: instance
我尝试使用下面的代码,但不幸的是它不起作用。
relabel_configs:
- source_labels: [__address__]
regex: '([^ ]+)'
target_label: instance
- source_labels: [__address__]
regex: '(.+)(.+)'
target_label: instance
replacement: ''
- source_labels: [__address__]
regex: '(.+)(.+)'
target_label: __address__
replacement: ''
- source_labels: [__address__]
target_label: __address__
replacement: ':9100'
终于找到解决方案
relabel_configs:
- source_labels: [__address__]
regex: "(.+) (.+)"
replacement: ""
target_label: hostname
- source_labels: [__address__]
regex: "(.+) (.+)"
replacement: ""
target_label: "ip"
- source_labels: [__address__]
regex: "(.+) (.+)"
replacement: ":9100"
target_label: __address__
我有一些 file_sd 配置,目标格式为 'ip hostname' 例如'10.10.11.12 foo'
我需要将 foo 值提取到新标签“hostname”,然后将添加端口值“:9100”添加到 ip 并将其分配给 target_label: instance
我尝试使用下面的代码,但不幸的是它不起作用。
relabel_configs:
- source_labels: [__address__]
regex: '([^ ]+)'
target_label: instance
- source_labels: [__address__]
regex: '(.+)(.+)'
target_label: instance
replacement: ''
- source_labels: [__address__]
regex: '(.+)(.+)'
target_label: __address__
replacement: ''
- source_labels: [__address__]
target_label: __address__
replacement: ':9100'
终于找到解决方案
relabel_configs:
- source_labels: [__address__]
regex: "(.+) (.+)"
replacement: ""
target_label: hostname
- source_labels: [__address__]
regex: "(.+) (.+)"
replacement: ""
target_label: "ip"
- source_labels: [__address__]
regex: "(.+) (.+)"
replacement: ":9100"
target_label: __address__