This should work:

  - job_name: blackbox
    file_sd_configs:
      - files:
        - /etc/prometheus/blackbox.d/*.yml
    metrics_path: /probe
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [module]
        target_label: __param_module
      - target_label: __address__
        replacement: 127.0.0.1:9115  # Blackbox exporter

That is, you set a label "module" in your targets file, and it gets copied 
to __param_module.  Your targets files /etc/prometheus/blackbox.d/foo.yml 
look like this:

- labels:
    module: icmp
  targets:
    - 1.1.1.1
    - 2.2.2.2
- labels:
    module: dns
  targets:
    - 3.3.3.3
... etc

All your blackbox scrapes are done in a single job.

The actual config I use is a little more complex than that:

  - job_name: blackbox
    file_sd_configs:
      - files:
        - /etc/prometheus/blackbox.d/*.yml
    metrics_path: /probe
    relabel_configs:
      - source_labels: [__address__]
        regex: '([^/]+)'  # name or address only
        target_label: instance
      - source_labels: [__address__]
        regex: '([^/]+)'  # name or address only
        target_label: __param_target
      - source_labels: [__address__]
        regex: '(.+)/(.+)'  # name/address
        target_label: instance
        replacement: '${1}'
      - source_labels: [__address__]
        regex: '(.+)/(.+)'  # name/address
        target_label: __param_target
        replacement: '${2}'
      - source_labels: [module]
        target_label: __param_module
      - target_label: __address__
        replacement: 127.0.0.1:9115  # Blackbox exporter

This lets me use target entries of the form 
"<instance-label>/<address-or-hostname>", e.g.

- labels:
    module: icmp
  targets:
    - google-primary/8.8.8.8
    - google-secondary/8.8.4.4

so my metrics have meaningful instance labels 
<https://www.robustperception.io/controlling-the-instance-label>.

On Friday, 6 August 2021 at 10:17:06 UTC+1 Sebastian N. wrote:

> Hey guys,
>
> In the following discussion 
> <https://groups.google.com/g/prometheus-users/c/a0uePOVkG1c/m/4u0NwDN5AwAJ> 
> about the blackbox exporter Julius Volz mentioned the following:
>
> The Blackbox targets to probe (like "https://google.com";) can come from 
> file_sd (or any other SD), no problem. You still need a scrape config in 
> the Prometheus config that actually scrapes the Blackbox exporter, but it 
> can get targets to probe from file_sd. *You can even vary the Blackbox 
> Exporter probe module to use for each target by setting a "__param_module" 
> hidden label on each target to override any "module" HTTP param that is set 
> in the scrape config itself.*
>
> During my research I have not found an example that shows me how I can 
> override module parameters on a per-target basis. My use case is that I'd 
> like to set a different user agent or toggle the follow_redirects flag for 
> some hosts without having to create another scraping job for that.  
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/1896d4f9-3536-42bf-8da8-0a7b98827160n%40googlegroups.com.

Reply via email to