Search code examples
configurationvirtual-machineprometheusscreen-scrapingtarget

Prometheus scrap_config: target contains a "/", but Prometheus does not accept that


I hope someone has a tip for me how to solve my problem in an efficient way.

I need to configure Prometheus scraping using the prometheus.yml file. The configuration has to be actually the same for hundreds of installations except the URL to each app. There a numorous VMs and each VM there several installation that shell be monitored (e.g. a VM with 10 installations). The metric path for all installations is "/actuator/prometheus". The URLs looks like

http://vm01.company.com:80/customer1/actuator/prometheus
http://vm01.company.com:80/customer2/actuator/prometheus
http://vm01.company.com:80/customer3/actuator/prometheus 
.....

I'd like to do something like this:

> scrape_configs:
>     - job_name: scrape-vm-job
>       metrics_path: /actuator/prometheus
>       static_configs:
>         - targets: ['vm01.company.com:80/customer1', 'vm01.company.com:80/customer2', 'vm01.company.com:80/customer3']

But if I try that, the slash is not accepted. I can add the /customer1 to the metrics_path and it works fine, but that would mean there have to be about 500 similar scraping job configs that only differ in the line for the target.

Ist there a way that Prometheus accepts the slash as part of the target?


Solution

  • I solved the problem using templating. An additional values yaml file is providing the needed information and the template loops through the file and creates the scraping job for that specific installation.