Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus - add target specific label in static_configs

Tags:

prometheus

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.

like image 968
Krzysztof Rosiński Avatar asked Apr 14 '18 08:04

Krzysztof Rosiński


People also ask

How do I add labels to Prometheus metrics?

Unfortunately, it is not possible to change the labels on old metrics in Prometheus. The storage is only updated by new scrapes and then it becomes immutable.

How do you add targets in Prometheus?

Prometheus has a scraping configuration that allows you to add target you want to scrape. This is the documentation (a good starting point). Thanks for the answer. I actually fixed it mapping these configs by editing the configmap.

What are target labels Prometheus?

The answer in Prometheus is target labels. At a minimum you'll have a job label to indicate the type of thing you're monitoring, and an instance label to identify the specific process. You might also have others for the environment, datacenter, team etc.


2 Answers

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' 
like image 96
pan congwen Avatar answered Oct 06 '22 06:10

pan congwen


Can be like this

  - job_name: 'node'     static_configs:     - targets: ['192.168.1.117:9100']       labels:         instance: 'linux-ina'     - targets: ['192.168.1.138:9100']       labels:         instance: 'linux-inb' 

Tag name can be replaced with instance

enter image description here enter image description here

like image 26
zxf曾爷 Avatar answered Oct 06 '22 06:10

zxf曾爷