file_sd_configs common label

28 views
Skip to first unread message

Senthil

unread,
Jun 4, 2020, 3:24:09 PM6/4/20
to Prometheus Users
Hi Team,
Is it possible to common labels? For example if there is two targets can i have a common labels for both and specific label for both ?

[
  {
    "targets": [
      "localhost:9100"
    ],
    "labels": {
      "job": "slave"
    }
  },
  {
    "targets": [
      "localhost:9200"
    ],
    "labels": {
      "job": "master"
    }
  }
]

Brian Candler

unread,
Jun 6, 2020, 7:57:51 AM6/6/20
to Prometheus Users
Yes, by adding the common labels to each target group:

[
  {
    "targets": [
      "localhost:9100"
    ],
    "labels": {
      "env": "production",

      "job": "slave"
    }
  },
  {
    "targets": [
      "localhost:9200"
    ],
    "labels": {
      "env": "production",
      "job": "master"
    }
  }
]


(pre-process your JSON if you don't like doing that by hand).  Alternatively, if the labels are common to *all* targets in that file, then you can add them using label rewriting in the prometheus job config.

Note though: it is generally not a good idea to override the "job" label.  This is one used by prometheus itself to identify the scrape job, and helps to keep metrics unique.

Senthil

unread,
Jun 6, 2020, 2:28:27 PM6/6/20
to Prometheus Users
thanks. 
Reply all
Reply to author
Forward
0 new messages