node_exporter tells you a host is up: CPU is idle, memory is free, the disk has room. It says nothing about whether your public URL actually answers. A web server can be running while the TLS certificate expired last night, the reverse proxy returns 502, or DNS points at a decommissioned load balancer. blackbox_exporter probes endpoints from outside — the same way a browser or an API client would — and exposes metrics like probe_success, probe_http_status_code, and probe_ssl_earliest_cert_expiry so Prometheus can alert when a site is down, returns the wrong status code, or its certificate is about to expire. This guide sets up the exporter, wires it into Prometheus with the relabeling trick that lets one exporter probe many targets, and gives you the queries to alert on.
What you’ll accomplish
- Run
blackbox_exporterwith modules for HTTP(S), TCP, ICMP, and DNS probes. - Test a probe directly against the exporter and read
probe_success. - Configure a Prometheus
scrape_configthat routes many targets through one exporter. - Query
probe_successand days-remaining on a TLS certificate for alerting. - Recognize the common misconfigurations that make a probe report
0when the site is actually fine.
Prerequisites
- A running Prometheus server you can edit
prometheus.ymlon and reload. - The ability to run the
blackbox_exporterbinary or container, reachable from Prometheus on its scrape port (default9115). - The list of endpoints you want to probe (public URLs, host:port pairs, or hostnames).
- Network egress from wherever the exporter runs to those endpoints. The exporter probes from its own vantage point, so run it where you want the “outside” to be.
One exporter probes many targets. You do not run one blackbox_exporter per URL. Prometheus passes each target to a single exporter as a URL parameter, and a relabel_configs block does the routing. That indirection is the one concept worth understanding before you touch the config.
How it works
A normal Prometheus scrape hits an exporter’s /metrics and takes whatever it finds. Blackbox works differently: Prometheus scrapes the exporter’s /probe endpoint and passes the real endpoint it wants checked as a target query parameter, plus a module that says how to check it. The exporter runs that probe against the endpoint, then returns the results as metrics for Prometheus to scrape in that same request.
Modules live in blackbox.yml and define how a probe behaves. http_2xx sends an HTTP(S) GET and counts a 2xx response as success; tcp_connect just opens a TCP connection; icmp sends a ping; dns resolves a name and checks the answer. You reference a module by name in the scrape config.
The routing is done by relabeling. In the scrape config you list your endpoints as ordinary targets, but a relabel_configs block rewrites the request so Prometheus actually scrapes the exporter:
__param_targetis set from the target label, so the endpoint becomes the?target=parameter.instanceis set to the target as well, so each series is labeled with the URL it describes, not the exporter.__address__is finally overwritten with the exporter’s host:port, so the HTTP request goes to the exporter.
That __param_target / __address__ dance is the whole trick. Get it right and one exporter serves your entire endpoint list; get it wrong and Prometheus scrapes the exporter’s own /metrics instead.
Step-by-step
Write a blackbox.yml with the modules you need. Start with an HTTP module that treats 2xx as healthy and one TCP module:
# blackbox.yml
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_status_codes: [] # defaults to 2xx
method: GET
fail_if_not_ssl: false
preferred_ip_protocol: ip4
tcp_connect:
prober: tcp
timeout: 5s
Run the exporter with that config mounted. The container reads /config/blackbox.yml and listens on 9115:
docker run -d --name blackbox \
-p 9115:9115 \
-v "$(pwd)/blackbox.yml:/config/blackbox.yml" \
prom/blackbox-exporter:latest \
--config.file=/config/blackbox.yml
Confirm it is listening:
curl -s http://localhost:9115/-/healthy
Expected output: Healthy.
Test a probe directly before touching Prometheus. Ask the exporter to probe a real URL with the http_2xx module and grep the result:
curl -s 'http://localhost:9115/probe?target=https://example.com&module=http_2xx' | grep -E '^probe_success|^probe_http_status_code'
Expected signal for a healthy site:
probe_http_status_code 200
probe_success 1
probe_success 1 means the probe passed end to end. If you see probe_success 0, the probe reached the exporter but the check failed — read the probe_http_* and probe_failed_due_to_regex lines in the full output to see why.
Add a scrape_config in prometheus.yml with the relabel block. List your endpoints under targets and route them through the exporter:
scrape_configs:
- job_name: blackbox_http
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://example.com
- https://api.example.com/health
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9115
Reload Prometheus so it picks up the new job. With --web.enable-lifecycle set, POST to the reload endpoint:
curl -s -X POST http://localhost:9090/-/reload
Expected signal: no output and an HTTP 200. In the Prometheus UI, Status → Targets now lists the blackbox_http job with one entry per URL, each UP.
Query the probe results. In the Prometheus expression browser or via curl to the query API, check success and certificate lifetime:
probe_success
(probe_ssl_earliest_cert_expiry - time()) / 86400
Expected output: probe_success returns 1 per healthy instance, and the second expression returns the number of days remaining on each certificate (for example 47.3). That second query is what you alert on to catch a cert before it expires.
Validate it works
The /probe endpoint is the fastest check. A healthy URL returns probe_success 1; point the same probe at a URL that is down or has a bad certificate and it returns probe_success 0:
curl -s 'http://localhost:9115/probe?target=https://expired.badssl.com&module=http_2xx' | grep '^probe_success'
Expected output: probe_success 0 — the TLS handshake fails on an expired certificate.
In Prometheus, confirm the series are labeled by URL, not by exporter:
probe_success{instance="https://example.com"}
That should return a single series with value 1. If the instance label reads localhost:9115 instead of the URL, the relabel block is wrong — see troubleshooting below.
Finally, confirm the cert-expiry math returns something sane:
(probe_ssl_earliest_cert_expiry{instance="https://example.com"} - time()) / 86400
A value like 62.9 means the certificate is valid for roughly 63 more days. An alert rule such as ... < 14 pages you two weeks before expiry.
Troubleshooting
probe_success is 0 because of a module mismatch. The most common cause is probing an HTTP URL with a module expecting TLS, or the reverse. If your module sets fail_if_not_ssl: true but you probe an http:// target, the probe fails by design. Match the module to the scheme, and check probe_http_ssl in the output — 0 on an https:// target means TLS never came up.
Prometheus scrapes the exporter’s own /metrics instead of /probe. If every instance shows the exporter’s internal metrics and no probe_* series appear, the relabel_configs block is missing or misordered. The three rules must run in order: copy __address__ into __param_target, copy __param_target into instance, then overwrite __address__ with the exporter address. Also confirm metrics_path: /probe is set on the job.
No probe_ssl or probe_http metrics at all. If the module named in params does not exist in blackbox.yml, the exporter returns an error and probe_success 0 with almost no detail. Curl the /probe URL by hand and read the plain-text error; a missing modules: block or a typo in the module name is usually the culprit. The exporter’s own /metrics exposes blackbox_module_unknown_total when this happens.
ICMP probes fail even though ping works from the shell. Sending ICMP echo requires an elevated capability. Run the container with --cap-add=NET_RAW (or the binary with CAP_NET_RAW), otherwise the icmp prober cannot open a raw socket and every ping probe reports probe_success 0.
Redirects or non-2xx codes report failure on a healthy endpoint. A health endpoint that returns 301 or 204 fails http_2xx because only 2xx counts by default. Set valid_status_codes: [301, 302] on a module for redirect targets, or list the exact code your health check returns. To follow redirects to the final page instead, leave follow_redirects: true (the default) and probe the canonical URL.
IPv4 versus IPv6 surprises. If a target resolves to both A and AAAA records and the exporter’s host has broken IPv6, probes intermittently fail. Pin the family with preferred_ip_protocol: ip4 (or ip6) in the module, and set ip_protocol_fallback: false if you want a hard failure rather than a silent fallback.
When this is the wrong approach
blackbox_exporter probes from one vantage point — wherever the exporter runs. It is not global synthetic monitoring: a probe from your own data center will not catch a regional CDN outage or a broken route that only affects users in another country. If you need “is this up from five continents”, you want a distributed synthetic-monitoring service, and blackbox is a complement to it, not a replacement.
It also checks reachability, not correctness. probe_success 1 means the endpoint answered with the expected status code and, at most, matched a regex you configured with fail_if_body_not_matches_regexp. It does not know whether the page rendered the right prices, the checkout flow works, or the API returned correct data. Pair blackbox with node_exporter for host health and application-level metrics for correctness — the three answer different questions, and dropping any one leaves a blind spot. For turning these probes into pages that reach the right person, see Prometheus alerting rules and routing alerts with Alertmanager. The authoritative references are the blackbox_exporter repository and the Prometheus configuration documentation.
If alerts fire into an empty room after hours, that’s exactly what 24/7 Monitoring & Response closes — book a monitoring and response review.