Scrape on different ports using same target file and file_sd_configs

38 views
Skip to first unread message

Venkata Sandeep

unread,
May 15, 2020, 5:31:04 AM5/15/20
to Prometheus Users
Hi Prometheus USers,

We have list of targets dynamically updated in the file called.target.yaml

- tagets
We would like to use targets.yaml file in multiple jobs as file_sd_configs (service discovery).

We want to scrape on different ports using the same targets file as below. How to achieve it?

- job_name: get-port-9001 //want to read metrics for port 9001
  file_sd_configs:
  - files:
    - targets.yaml   
- job_name: get-port-9002 //want to read metrics for port 9002
  file_sd_configs:
  - files:
    - targets.yaml   
- job_name: get-port-9003 //want to read metrics for port 9003
  file_sd_configs:
  - files:
    - targets.yaml   

Thanks
Sandeep

Julien Pivotto

unread,
May 15, 2020, 5:48:28 AM5/15/20
to Prometheus Users
On 15 May 02:31, Venkata Sandeep wrote:
> Hi Prometheus USers,
>
> We have list of targets dynamically updated in the file called.target.yaml
>
> - tagets
> - host1.abc.com
> - host2.abc.com
> - host3.abc.com
>
> We would like to use targets.yaml file in multiple jobs as file_sd_configs
> (service discovery).
>
> We want to scrape on different ports using the same targets file as below.
> How to achieve it?

Hi,

You can use relabel config

- job_name: get-port-9001 //want to read metrics for port 9001
file_sd_configs:
- files:
- targets.yaml
relabel_configs:
- source_labels: [__address__]
target_label: __address__
replacement: "${1}:9001"
- job_name: get-port-9002 //want to read metrics for port 9002
file_sd_configs:
- files:
- targets.yaml
relabel_configs:
- source_labels: [__address__]
target_label: __address__
replacement: "${1}:9002"

Regards

>
> - job_name: get-port-9001 //want to read metrics for port 9001
> file_sd_configs:
> - files:
> - targets.yaml
> - job_name: get-port-9002 //want to read metrics for port 9002
> file_sd_configs:
> - files:
> - targets.yaml
> - job_name: get-port-9003 //want to read metrics for port 9003
> file_sd_configs:
> - files:
> - targets.yaml
>
> Thanks
> Sandeep
>
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/97463959-a6f8-4af4-8bcd-9926c3cdda7a%40googlegroups.com.


--
Julien Pivotto
@roidelapluie

Brian Candler

unread,
May 15, 2020, 6:20:28 AM5/15/20
to Prometheus Users
On Friday, 15 May 2020 10:48:28 UTC+1, Julien Pivotto wrote:
You can use relabel config

- job_name: get-port-9001 //want to read metrics for port 9001
  file_sd_configs:
  - files:
    - targets.yaml  
  relabel_configs:
    - source_labels: [__address__]
      target_label: __address__
      replacement: "${1}:9001"
- job_name: get-port-9002 //want to read metrics for port 9002
  file_sd_configs:
  - files:
    - targets.yaml  
  relabel_configs:
    - source_labels: [__address__]
      target_label: __address__
      replacement: "${1}:9002"


And with a couple of extra lines, you can keep the port out of the instance label.  The metrics are still distinguished by their "job" label.

- job_name: get-port-9001 //want to read metrics for port 9001 
  file_sd_configs: 
  - files: 
    - targets.yaml   
  relabel_configs:
    - source_labels: [__address__]
      target_label: instance
    - source_labels: [__address__] 
      target_label: __address__ 
      replacement: "${1}:9001" 
- job_name: get-port-9002 //want to read metrics for port 9002 
  file_sd_configs: 
  - files: 
    - targets.yaml   
  relabel_configs: 
    - source_labels: [__address__]
      target_label: instance

Venkata Sandeep

unread,
May 15, 2020, 2:03:16 PM5/15/20
to Prometheus Users
It did work.
Thanks
Reply all
Reply to author
Forward
0 new messages