From 2062f8cb69d95edb582f276f6bfae09fb6b052d9 Mon Sep 17 00:00:00 2001 From: josephk <87587150+joseph2021k@users.noreply.github.com> Date: Mon, 19 Feb 2024 00:49:04 +0100 Subject: [PATCH 1/2] Multiple targets and multiple modules in one Prometheus job --- content/docs/guides/multi-target-exporter.md | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/content/docs/guides/multi-target-exporter.md b/content/docs/guides/multi-target-exporter.md index 563667f0a..0ef352111 100644 --- a/content/docs/guides/multi-target-exporter.md +++ b/content/docs/guides/multi-target-exporter.md @@ -494,6 +494,49 @@ Often people combine these with a specific service discovery. Check out the [con That is it. Restart the Prometheus docker container and look at your [metrics](http://localhost:9090/graph?g0.range_input=30m&g0.stacked=0&g0.expr=probe_http_duration_seconds&g0.tab=0). Pay attention that you selected the period of time when the metrics were actually collected. +## Advanced querying. Multiple targets and multiple modules in one Prometheus job + +In the example above we used a single blackbox exporter probe module only. The `module` is specified as a job-level parameter of the `blackbox-http` job. Since it is a list, it can contain multiple elements, but the blackbox exporter only uses the first one. +However, we can use multiple blackbox exporter modules in a single job if we need to probe separate groups of targets with appropriate modules for each. +Instead of specifying the `module` param of the job, we can specify a `module` label in each `static_config`. +Additionally the `relabel_configs` sequence needs to be expanded with a new item, because we have to inject the module (as `__param_module`) in the requests at this point. + +```yaml +global: + scrape_interval: 5s + +scrape_configs: +- job_name: blackbox # To get metrics about the exporter itself + metrics_path: /metrics + static_configs: + - targets: + - localhost:9115 # The blackbox exporter’s real hostname:port + +- job_name: blackbox-probes # To get metrics about the exporter’s targets with different modules + metrics_path: /probe + static_configs: + - targets: # static_config: targets and http_2xx module + - http://prometheus.io + - https://prometheus.io + - http://example.com:8080 + labels: + module: http_2xx + - targets: # static_config: targets and icmp module + - prometheus.io + - example.com + labels: + module: icmp + relabel_configs: + - source_labels: [__address__] + target_label: __param_target + - source_labels: [__param_target] + target_label: instance + - source_labels: [module] + target_label: __param_module + - target_label: __address__ + replacement: localhost:9115 # The blackbox exporter’s real hostname:port +``` + # Summary In this guide, you learned how the multi-target exporter pattern works, how to run a blackbox exporter with a customised module, and to configure Prometheus using relabeling to scrape metrics with prober labels. From d0635e7376028d53531350efee05c1d55ad3ae47 Mon Sep 17 00:00:00 2001 From: josephk <87587150+joseph2021k@users.noreply.github.com> Date: Mon, 20 May 2024 12:25:43 +0200 Subject: [PATCH 2/2] Update multi-target-exporter.md Signed-off-by: josephk <87587150+joseph2021k@users.noreply.github.com> --- content/docs/guides/multi-target-exporter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/guides/multi-target-exporter.md b/content/docs/guides/multi-target-exporter.md index 0ef352111..1d43f6360 100644 --- a/content/docs/guides/multi-target-exporter.md +++ b/content/docs/guides/multi-target-exporter.md @@ -494,7 +494,7 @@ Often people combine these with a specific service discovery. Check out the [con That is it. Restart the Prometheus docker container and look at your [metrics](http://localhost:9090/graph?g0.range_input=30m&g0.stacked=0&g0.expr=probe_http_duration_seconds&g0.tab=0). Pay attention that you selected the period of time when the metrics were actually collected. -## Advanced querying. Multiple targets and multiple modules in one Prometheus job +## Example configuration: Multiple targets and multiple modules in one Prometheus job In the example above we used a single blackbox exporter probe module only. The `module` is specified as a job-level parameter of the `blackbox-http` job. Since it is a list, it can contain multiple elements, but the blackbox exporter only uses the first one. However, we can use multiple blackbox exporter modules in a single job if we need to probe separate groups of targets with appropriate modules for each.