How to replace a label in a prometheus re-label step?

4.7k views Asked by At

I'm using the prometheus file based service discovery. However when pulling in my list of servers I realized that my service's metrics endpoint is /prometheus no /metrics

I've seen that I can use relabelling to fix this.

- job_name: 'servers-dev'
  file_sd_configs:
  - files: ['/prometheus/topology.json']

  relabel_configs:
  - source_labels: [?????]
    action: replace
    target_label: __metrics_path__  #I want this to be /prometheus
    regex: (.+)

How can I add in label using relabeling?

1

There are 1 answers

1
brian-brazil On BEST ANSWER

There's no need to use relabelling here, you can just add

  metrics_path: /prometheus

to the scrape config.

To do this with relabelling you'd do:

  - target_label: __metrics_path__
    replacement: /prometheus

as the defaults are such that you don't need to worry about the other config options.