Prometheus - add target specific label in static_configs

Krzysztof Rosiński picture Krzysztof Rosiński · Apr 14, 2018 · Viewed 25.2k times · Source

I have job definition as follows:

  - job_name: 'test-name'
    static_configs:
      - targets: [ '192.168.1.1:9100', '192.168.1.1:9101', '192.168.1.1:9102' ]
        labels:
          group: 'development'

Is there any way to annotate targets with labels? For instance, I would like to add 'service-1' label to '192.168.1.1:9100', 'service-2' to '192.168.1.1:9101' etc.

Answer

pan congwen picture pan congwen · Apr 16, 2019

I have the same question before. Here is my solution:

  1. use job_name as the group label
  2. add more target option to separate instance and add labels

For you the code may like this:

  - job_name: 'development'
      static_configs:
      - targets: [ '192.168.1.1:9100' ]
        labels:
          service: '1'
      - targets: [ '192.168.1.1:9101' ]
        labels:
          service: '2'