<p>Prometheus allows me to dynamically load targets with file_sd_config from a .json file like this</p>

<pre><code>#prometheus.yaml
- job_name: 'kube-metrics'
  file_sd_configs:
  - files:
    - 'targets.json'
</code></pre>

<pre><code>[
  {
    "labels": {
      "job": "kube-metrics"
    },
    "targets": [
      "http://node1:8080",
      "http://node2:8080"
    ]
  }
]
</code></pre>

<p>However my targets differ in the <code>metrics_path</code> and not the host (I want to scrape metrics for every kubernetes node on <code>&lt;kube-api-server&gt;/api/v1/nodes/&lt;node-name&gt;/proxy/metrics/cadvisor</code>) but I can only set the <code>metrics_path</code> at the job level and not per target. Is this even achievable with prometheus or do I have to write my own code to scrape all these metrics and export them at a single target. Also I couldn't find a list of all supported auto discovery mechanisms, did I miss something in the docs?</p>

<p>You can use <a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config" rel="noreferrer">relabel_config</a> in Prometheus config to change <code>__metrics_path__</code> label config.</p>

<p>The principe is to provide the metrics path in your targets under the form <code>host:port/path/of/metrics</code> (note: drop the <code>http://</code>, it is in <code>scheme</code> parameter of <code>scrape_config</code>)</p>

<pre><code>[
  {
    "targets": [
      "node1:8080/first-metrics",
      "node2:8080/second-metrics"
    ]
  }
]
</code></pre>

<p>And then replace the related meta-labels with the parts</p>

<pre><code>- job_name: 'kube-metrics'
  file_sd_configs:
  - files:
    - 'targets.json'
  relabel_configs:
    - source_labels: [__address__]
      regex:  '[^/]+(/.*)'            # capture '/...' part
      target_label: __metrics_path__  # change metrics path
    - source_labels: [__address__]
      regex:  '([^/]+)/.*'            # capture host:port
      target_label: __address__       # change target
</code></pre>

<p>You can reuse this method on any label known at configuration time to modify the config of the scrape.</p>

<p>On Prometheus, use the service discovery page to check your config has been correctly modified. </p>

<p>The official list of service discovery is in <a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#configuration" rel="noreferrer">the configuration documentation</a>: look for the <code>*_sd_config</code> in the index.</p>
