Reputation: 880
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.
Upvotes: 68
Views: 117575
Reputation: 657
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
Upvotes: 44
Reputation: 3720
You can use file-based service discovery to achieve this. See this blog post for more details.
Upvotes: 2
Reputation: 9634
The targets do not have to be simple ip:port pairs, you can include extra info and use re-labelling to split out the ip and port from a nice instance name:
scrape_configs:
- job_name: 'prometheus_metrics'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter_metrics'
scrape_interval: 5s
static_configs:
- targets: ["157.xxx.xxx.xxx:9100@db56a", "176.xxx.xxx.xxx:9100@db56b"]
labels:
role: 'postgres_ha'
- targets: ["46.xxx.xxx.xxx:9100@p1a", "176.xxx.xxx.xxx:9100@p1b", "136.xxx.xxx.xxx:9100@p1c"]
labels:
role: 'pulsar'
relabel_configs:
- source_labels: [ __address__ ]
regex: '(.*)@(.*)'
replacement: $2
target_label: instance
- source_labels: [ __address__ ]
regex: '(.*)@(.*)'
replacement: $1
target_label: __address__
Upvotes: 2
Reputation: 946
I have the same question before. Here is my solution:
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'
Upvotes: 93
Reputation: 620
You can find information in here - Prometheus Good Config
But I have used these and it worked
- job_name: 'PostgreSQL-exporter'
scrape_interval: 60s
scrape_timeout: 60s
static_configs:
- targets: ['localhost:9187']
- labels:
name: value-for-the-name
Upvotes: 0
Reputation: 34142
For different services you should usually vary the job label, so I would suggest duplicating the scrape config with a job_name of service1 for one and service2 for the other.
Upvotes: 3