'How to relabel address with it's current value and a label

In a json config file (referred to from file_sd_configs ) I have entries such as

[
...
    "targets": [ "10.123.456.789"],
    "labels": { "node_exporter_port": "9300" }
  },
...

]

In Prometheus configuration I'd like to relabel_configs so that the value of __address__ is the current value of address plus the port. Attempts such as the following do not work:

relabel_configs:
  - source_labels: [node_exporter_port]
    regex: (.*)
    target_label: __address__
    replacement: [__address__]:${1}

EDIT: The following seems to work:

relabel_configs:
  - source_labels: [__address__, node_exporter_port]
    separator:     ';'
    regex: '(.*);(.*)'
    target_label: __address__
    replacement: ${1}:${2}

Is this idiomatic?



Solution 1:[1]

If you change the separator to colon you can remove the regex and replacement, as the defaults do what you need.

The port label should be prefixed with __ so that it doesn't end up as a target label.

Solution 2:[2]

The following relabeling config appends the port from node_exporter_port label to the __address__ label:

- source_labels: [__address__, node_exporter_port]
  target_label: __address__
  separator: ':'

It joins the original __address__ label value and the node_exporter_port label value with the given separator: ':'.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 brian-brazil
Solution 2 valyala