The scrape job configuration for blackbox probes is unusual, in the sense that both the prober module and the list of targets, whether static or discovered, need to be relayed to the exporter as HTTP GET parameters to the /probe endpoint. To make this work, a bit of relabel_configs magic is required, as seen in Chapter 5, Running a Prometheus Server.
Using the following Prometheus configuration snippet as an example, we're setting up an ICMP probe against the Prometheus instance, while blackbox_exporter is running on target01:
- job_name: 'blackbox-icmp'
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets:
- prometheus.prom.inet
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: target01:9115
The goal is to replace the address of the target with the address of blackbox_exporter, ensuring the internal __param_target keeps the address of the target. Focusing on how the relabel_configs is processed, the following happens:
- The __address__ value (which contains the address of the target) is stored into __param_target.
- __param_target value is then stored into the instance label.
- The blackbox_exporter host is then applied to __address__.
This enables to Prometheus to query blackbox_exporter (using __address__), keep the instance label with the target definition, and pass the parameters module and target (using the internal __param_target) to the /probe endpoint, which returns the metrics data.