Search code examples
prometheus

Different Prometheus scrape URL for every target


Every instance of my application has a different URL. How can I configure prometheus.yml so that it takes path of a target along with the host name?

scrape_configs:
- job_name:       'example-random'

# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s

static_configs:
  - targets: ['localhost:8090','localhost:8080']
    labels:
      group: 'dummy'

Solution

  • You currently can't configure the metrics_path per target within a job but you can create separate jobs for each of your targets so you can define metrics_path per target.

    Your config file would look something like this:

    scrape_configs:
    - job_name:       'example-target-1'
      scrape_interval: 5s
      metrics_path: /target-1-path-to-metrics
      static_configs:
        - targets: ['localhost:8090']
          labels:
            group: 'dummy'
    
    - job_name:       'example-target-2'
      scrape_interval: 5s
      metrics_path: /totally-different-path-for-target-2
      static_configs:
        - targets: ['localhost:8080']
          labels:
            group: 'dummy-2'