How can I add static label to all metrics from a discovered service?

25 views
Skip to first unread message

Shaolin Zheng

unread,
Mar 23, 2020, 5:32:23 AM3/23/20
to Prometheus Users
We can add new static label to static_configs like this:

static_configs:
- targets:
  - address1
  - address2
  labels:
    mynewlabel1
: value

Now I want to add new label to targets that coming from service discovery. But seems like it only supports relabel_configs, which allow me to transfer any existing label, but not create a new label from zero.

Any suggestion how I can achieve that?

BTW my real problem is to add a cluster label to all the metrics from current Kubernetes cluster

Brian Candler

unread,
Mar 23, 2020, 5:59:41 AM3/23/20
to Prometheus Users
Relabeling allows creation of arbitrary labels.  This ought to work to set foo="bar" (untested)

      - source_labels: []
        target_label: foo
        replacement: bar

If for some reason source_labels cannot be an empty list, then use any other label which exists and its value will be ignored, e.g.

      - source_labels: [__address__]
        target_label: foo
        replacement: bar

Shaolin Zheng

unread,
Mar 23, 2020, 8:52:26 AM3/23/20
to Prometheus Users
Great, thanks
Reply all
Reply to author
Forward
0 new messages