1. Why test URLs? #
Black-box monitoring complements internal metrics.
White box and black box #
Exporters and instrumentation give a white-box view: the application and the host describe their own state (requests received, errors, memory). This view has a blind spot: everything that happens before the application. An expired certificate, a deleted DNS record, a misconfigured load balancer or a firewall rule block users while no internal metric moves, since requests never arrive.
A URL test (or synthetic probe) takes the black-box view: it behaves like a client, sends a real request and judges what comes back. It answers the only question that matters to users: “does it work, and how fast?”.
| Criterion | White box (exporters) | Black box (URL tests) |
|---|---|---|
| Question | Why is the service unhealthy? | Does the service answer clients correctly? |
| Example | http_requests_total, node_memory_* | probe_success, probe_http_duration_seconds |
| Detects | saturation, internal errors, leaks | DNS, certificate, network, proxy, CDN, full outage |
| Misses | what stops the request from arriving | the cause, and untested paths |
Best practice : Both approaches work together: alert on the symptom seen by the probe (the site no longer answers), diagnose with internal metrics.
What you can check #
- Availability: expected HTTP code, open port, valid DNS answer.
- Content: presence (or absence) of text in the page, response headers.
- Performance: total duration and per-phase detail (DNS, connect, TLS, processing, transfer).
- Certificates: expiry date, negotiated TLS version, chain of trust.
- Network: ICMP reachability, round-trip time.
- Non-HTTP services: SSH, SMTP, LDAPS, Redis, gRPC health.
Good to know : The Blackbox Exporter is the Prometheus project's official exporter for these tests (repository prometheus/blackbox_exporter). This chapter uses version 0.27 and Prometheus 3.2. How the Blackbox Exporter works #
An exporter that measures nothing until asked.
A probe on demand #
A classic exporter such as Node Exporter describes the host it runs on. The Blackbox Exporter has nothing to describe: it waits to be called on /probe?target=<target>&module=<module>. On each call, it runs the test described by the module against the target, then returns the result metrics. So Prometheus decides the list of targets and the test frequency (the scrape_interval).
The exporter also exposes /metrics (its own behaviour), /config (loaded configuration), /-/reload and a home page on port 9115 listing recent probes and their log.
Modules and probers #
The configuration (blackbox.yml) holds no targets, only modules. A module has a name, a prober (the test type), a timeout and options. You write one module per way of testing, then reuse it for as many targets as needed.
# blackbox.yml: one module = one reusable test type
modules:
http_2xx:
prober: http
timeout: 5s
http:
preferred_ip_protocol: ip4The multi-target pattern #
On the Prometheus side, one job is enough for dozens of URLs. Relabeling turns each listed target into a query parameter, keeps the URL as the instance label, then replaces the address to scrape with the Blackbox Exporter's.
# prometheus.yml: one job, several URLs
scrape_configs:
- job_name: blackbox-http
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://www.example.com
- https://api.example.com/health
relabel_configs:
# the URL to test becomes the ?target= parameter
- source_labels: [__address__]
target_label: __param_target
# and the instance label (readable in dashboards)
- source_labels: [__param_target]
target_label: instance
# Prometheus actually scrapes the Blackbox Exporter
- target_label: __address__
replacement: blackbox:9115Common mistake : Without the last rule, Prometheus tries to connect tohttps://www.example.com:80/probeand the target shows as down in/targets. Without the second, every series carriesinstance="blackbox:9115"and they become indistinguishable.
The timeout #
Prometheus sends its scrape_timeout in the X-Prometheus-Scrape-Timeout-Seconds header. The Blackbox Exporter keeps the smaller of the module timeout and that value minus --timeout-offset (0.5 s by default), so it answers before Prometheus gives up.
| Module timeout | scrape_timeout | Effective timeout |
|---|---|---|
| 5s | 10s | 5 s |
| 30s | 10s (default) | 9.5 s |
| 30s | 35s | 30 s |
Best practice : For a page that is slow by nature, raise both the moduletimeoutand the jobscrape_timeout, which must stay below thescrape_interval.
3. Pros and cons #
What the Blackbox Exporter does well, its limits and the alternatives.
The advantages #
| Advantage | In practice |
|---|---|
| Light and simple | a dependency-free Go binary, a few MB of memory, a short YAML configuration |
| Built into Prometheus | same tools to store, query (PromQL), visualize (Grafana) and alert (Alertmanager) |
| Multi-protocol | HTTP(S), TCP, DNS, ICMP and gRPC in one tool |
| Detailed measurements | per-phase timing, TLS version, certificate expiry, number of redirects |
| Configuration as code | modules and targets versioned in Git, service discovery, Probe resource on Kubernetes |
| Free and open source | Apache 2.0 licence, no limit on the number of tests |
| Multiple viewpoints | one instance per network or region is enough to test from inside and outside |
Drawbacks and limits #
| Limit | Consequence | Workaround |
|---|---|---|
| One request per probe | no multi-step journeys (log in, then cart, then payment) | Grafana k6, Synthetic Monitoring, Playwright |
| No browser | JavaScript is not executed: a page blank for the client can return 200 | k6 browser, RUM (Grafana Faro) |
| Regex-based content checks | checking a given JSON field is brittle | dedicated health page; CEL on JSON in recent versions |
| Credentials at module level | one module per credential set: configuration grows | strict naming, generated configuration |
| No built-in secret management | no direct link to Vault or a cloud vault | mounted files (*_file) fed by Kubernetes, Vault Agent, External Secrets |
| One location per instance | a local outage looks like a site outage | several instances and majority alerting |
/probe calls whatever it is asked | SSRF risk if the exporter is exposed | restricted network, --web.config.file |
| Result = metrics only | no history of the responses received nor screenshots | debug=true log, full synthetic tools |
| Privileged ICMP | ping needs CAP_NET_RAW or a kernel setting | setcap, net.ipv4.ping_group_range |
Blackbox Exporter or another tool? #
| Tool | Strength | Pick it when… |
|---|---|---|
| Blackbox Exporter | native Prometheus integration, multi-protocol | you already run Prometheus and want many simple tests |
| Uptime Kuma | web UI, status pages, ready-made notifications | a small team wants a status page without writing YAML |
| Grafana k6 | JavaScript-scripted scenarios, browser | you need to test a full user journey |
| Grafana Cloud Synthetic Monitoring | managed probes worldwide (engine derived from the Blackbox Exporter) | you want to test from many regions without hosting anything |
| SaaS (Pingdom, Datadog Synthetics…) | turnkey, SLA reports | budget matters less than owning the tooling |
Best practice : A common mix: Blackbox Exporter for the hundreds of simple checks (availability, certificates, DNS, ports), a scenario tool for the two or three critical journeys.
4. Installing and configuring #
Docker, binary or Helm, then validate, reload and debug.
Installation #
# Docker
docker run -d --name blackbox -p 9115:9115 \
-v "$PWD/blackbox.yml:/etc/blackbox_exporter/config.yml:ro" \
prom/blackbox-exporter:v0.27.0
# Binary (Linux amd64)
curl -LO https://github.com/prometheus/blackbox_exporter/releases/download/v0.27.0/blackbox_exporter-0.27.0.linux-amd64.tar.gz
tar xzf blackbox_exporter-0.27.0.linux-amd64.tar.gz
./blackbox_exporter-0.27.0.linux-amd64/blackbox_exporter --config.file=blackbox.yml
# Kubernetes (Helm)
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install blackbox prometheus-community/prometheus-blackbox-exporter \
-n monitoring --create-namespace -f values.yamlGood to know : The image reads/etc/blackbox_exporter/config.ymlby default and listens on port 9115. With Helm, modules are declared under theconfig.moduleskey ofvalues.yaml.
Validate, reload, debug #
# Check the syntax without starting
blackbox_exporter --config.file=blackbox.yml --config.check
# Reload after a change (or kill -HUP)
curl -X POST http://localhost:9115/-/reload
# Run a probe by hand, with the detailed log
curl -s 'http://localhost:9115/probe?module=http_2xx&target=https://www.example.com&debug=true'
# Show the loaded configuration (passwords are masked)
curl -s http://localhost:9115/configThe debug=true parameter is the main diagnostic tool: instead of metrics only, the exporter returns the step-by-step probe log, the metrics it would have produced and the module configuration used.
Classic trap : A failed probe still returns HTTP 200 to Prometheus, withprobe_success 0. The target therefore stays “UP” in/targets: watchprobe_success, notup.
Best practice : An unknown module name makes the/proberequest fail (code 400) and incrementsblackbox_module_unknown_total: a typo intargets.ymlshows up in the exporter's metrics.
5. HTTP and HTTPS tests #
Status, content, method, TLS, IPv4/IPv6 and response-time breakdown.
Status code, version and redirects #
modules:
# Simple availability: any 2xx code, IPv4 preferred
http_2xx:
prober: http
timeout: 5s
http:
preferred_ip_protocol: ip4
# Public site: HTTPS required, 200 expected after at most 3 redirects
https_site:
prober: http
timeout: 10s
http:
method: GET
valid_status_codes: [200]
valid_http_versions: ["HTTP/1.1", "HTTP/2.0"]
follow_redirects: true
fail_if_not_ssl: true
preferred_ip_protocol: ip4
ip_protocol_fallback: true| Option | Default | Role |
|---|---|---|
valid_status_codes | 2xx | accepted codes (e.g. [200, 301], or [401] to check a page is protected) |
valid_http_versions | all | accepted HTTP versions |
method | GET | HTTP method |
follow_redirects | true | follow redirects; the code judged is that of the last response |
fail_if_ssl / fail_if_not_ssl | false | require or forbid HTTPS on the final response |
preferred_ip_protocol | ip6 | address family tried first |
ip_protocol_fallback | true | fall back to the other family if the first one does not exist |
Common mistake : Thepreferred_ip_protocol: ip6default is surprising: on an IPv6-less network the probe falls back to IPv4, butprobe_ip_protocolchanges and resolution is done twice. Setip4explicitly if your network has no IPv6, orip_protocol_fallback: falseto test IPv6 specifically.
Checking the response content #
A 200 code does not guarantee the page is correct: a custom error page or a maintenance page often return 200. Regular expressions on the body and headers catch these cases; on failure, probe_failed_due_to_regex equals 1.
modules:
# API health page: status and content
http_api_health:
prober: http
timeout: 5s
http:
valid_status_codes: [200]
fail_if_body_not_matches_regexp:
- '"status":\s*"(UP|ok)"'
fail_if_body_matches_regexp:
- '(?i)maintenance|exception'
fail_if_header_not_matches:
- header: Content-Type
regexp: 'application/json'
fail_if_header_matches:
- header: Server
regexp: 'Apache/2\.2'
allow_missing: true
body_size_limit: 1MBGood to know : Recent versions addfail_if_body_json_matches_celandfail_if_body_json_not_matches_cel, which evaluate a CEL expression on a JSON body (for examplebody.status == "UP"). Check they exist in your version's documentation before using them.
Best practice : Test a health page designed for it (/health,/ready) rather than the home page: short response, stable content, and it can check dependencies (database, cache).
Method, headers and body #
modules:
# POST request with a JSON body
http_post_search:
prober: http
timeout: 5s
http:
method: POST
headers:
Content-Type: application/json
Accept: application/json
body: '{"query": "prometheus", "limit": 1}'
valid_status_codes: [200, 201]
fail_if_body_not_matches_regexp: ['"results"']body_file replaces body for a large body. Headers are also used to force a Host, a language (Accept-Language) or a User-Agent easy to spot in server logs.
TLS and certificates #
modules:
# Probe a given server (by IP) while checking the public name's certificate
https_backend:
prober: http
timeout: 10s
http:
headers:
Host: www.example.com
tls_config:
server_name: www.example.com
ca_file: /etc/blackbox_exporter/ca/internal-ca.pem
min_version: TLS12
insecure_skip_verify: false
fail_if_not_ssl: trueEvery HTTPS probe produces certificate metrics: probe_ssl_earliest_cert_expiry (expiry of the first certificate in the chain to expire), probe_ssl_last_chain_expiry_timestamp_seconds (expiry of the verified chain), probe_tls_version_info (negotiated version) and probe_ssl_last_chain_info (fingerprint, subject, issuer).
Common mistake :insecure_skip_verify: truehides exactly the failures you want to catch (expired certificate, wrong name, unknown authority). For an internal authority, provideca_fileinstead of disabling verification.
Proxy #
Behind an outbound proxy, proxy_url (e.g. http://proxy.example.com:3128) routes the probe through the proxy; skip_resolve_phase_with_proxy: true lets the proxy resolve the name, useful when the probing host has no access to public DNS.
Breaking down the response time #
probe_http_duration_seconds carries a phase label: resolve, connect, tls, processing (waiting for the first byte) and transfer. A rise in processing points at the server; a rise in resolve points at DNS; connect and tls point at the network or load balancer.
sum by (phase) (probe_http_duration_seconds{instance="https://www.example.com"})6. TCP, DNS, ICMP and gRPC tests #
Testing what is not a web page.
TCP: ports, TLS and text dialogues #
The target is written host:port. Without options, the probe succeeds if the connection is established. query_response chains expect (expected regex), send (text sent) and an optional starttls, which makes it possible to test text protocols.
modules:
# Port open?
tcp_connect:
prober: tcp
timeout: 5s
# TLS service (LDAPS, IMAPS…): handshake and certificate
tcp_tls:
prober: tcp
timeout: 5s
tcp:
tls: true
tls_config:
insecure_skip_verify: false
# SSH banner
ssh_banner:
prober: tcp
timeout: 5s
tcp:
query_response:
- expect: "^SSH-2.0-"
- send: "SSH-2.0-blackbox-ssh-check"
# SMTP with STARTTLS (full dialogue)
smtp_starttls:
prober: tcp
timeout: 10s
tcp:
query_response:
- expect: "^220 ([^ ]+) ESMTP (.+)$"
- send: "EHLO prober\r"
- expect: "^250-STARTTLS"
- send: "STARTTLS\r"
- expect: "^220"
- starttls: true
- send: "EHLO prober\r"
- expect: "^250-AUTH"
- send: "QUIT\r"Good to know : Withtls: trueorstarttls, certificate metrics (probe_ssl_earliest_cert_expiry) are produced too: this is how to watch certificate expiry on a mail or LDAP server.
DNS: does the server answer correctly? #
Mind the direction: the target is the DNS server queried (1.1.1.1, ns1.example.com:53), the name to resolve lives in the module (query_name). You check the response code (valid_rcodes) and the answer, authority and additional sections by regex.
modules:
# Does DNS server 1.1.1.1 resolve www.example.com?
dns_example:
prober: dns
timeout: 5s
dns:
query_name: www.example.com
query_type: A
transport_protocol: udp
preferred_ip_protocol: ip4
valid_rcodes: [NOERROR]
validate_answer_rrs:
# at least one A record in the answer
fail_if_none_matches_regexp:
- '.*\tIN\tA\t.*'Other options: transport_protocol: tcp, dns_over_tls: true (port 853), recursion_desired: false to query an authoritative server. Metrics: probe_dns_answer_rrs, probe_dns_duration_seconds by phase.
ICMP and gRPC #
modules:
icmp:
prober: icmp
timeout: 5s
icmp:
preferred_ip_protocol: ip4
payload_size: 56
dont_fragment: false
# gRPC service implementing grpc.health.v1
grpc_health:
prober: grpc
timeout: 5s
grpc:
service: "" # empty = overall server state
tls: true
preferred_ip_protocol: ip4The ICMP probe measures reachability and round-trip time (probe_icmp_duration_seconds{phase="rtt"}). It needs privileges: either the CAP_NET_RAW capability (setcap cap_net_raw+ep blackbox_exporter, securityContext.capabilities.add: [NET_RAW] on Kubernetes), or a group allowed by net.ipv4.ping_group_range for unprivileged ping. Recent Docker versions allow the latter by default in containers.
The gRPC probe calls the standard grpc.health.v1.Health/Check service on a host:port target; probe_grpc_healthcheck_response{serving_status="SERVING"} equals 1 when the service reports ready.
Best practice : A ping that answers does not prove the service works: use ICMP to tell “host unreachable” from “service stopped”, alongside a TCP or HTTP probe, never instead of it.
7. Testing protected URLs: credentials #
Basic auth, Bearer, OAuth2, mTLS, secret storage and traps.
Two levels not to mix up #
A protected URL answers 401 or 403 to an anonymous probe. You then need to provide credentials… in the right place. Two separate connections exist: Prometheus → Blackbox Exporter, then Blackbox Exporter → target. Target credentials are declared in the Blackbox Exporter module.
scrape_configs:
- job_name: intranet
metrics_path: /probe
params: { module: [http_2xx] }
# WRONG: these credentials are used to scrape the Blackbox Exporter, not the site
basic_auth:
username: svc-monitoring
password_file: /etc/prometheus/intranet_password
static_configs:
- targets: [https://intranet.example.com]Trap number one : Thisbasic_authis sent to the Blackbox Exporter, which ignores it if unprotected; the target receives an anonymous request and answers 401. Result:probe_success 0andprobe_http_status_code 401, although “credentials are configured”.
Basic authentication #
modules:
# Password read from a file (never in plain text in the YAML)
http_basic_intranet:
prober: http
timeout: 5s
http:
valid_status_codes: [200]
basic_auth:
username: svc-monitoring
password_file: /etc/blackbox_exporter/secrets/intranet_passwordpassword exists too, but puts the secret in the configuration file. password_file keeps it in a separate file, mounted from a secret manager, that can be rotated without editing blackbox.yml.
Bearer token and Authorization header #
modules:
# “Authorization: Bearer <token>” header
http_bearer_api:
prober: http
timeout: 5s
http:
authorization:
type: Bearer
credentials_file: /etc/blackbox_exporter/secrets/api_token
# Other scheme: “Authorization: ApiKey <key>”
http_apikey_api:
prober: http
http:
authorization:
type: ApiKey
credentials_file: /etc/blackbox_exporter/secrets/api_keyThe authorization block produces the Authorization: <type> <token> header (type Bearer by default). The old bearer_token field still works but is deprecated.
Watch out : A static JWT token expires: the day it does, every probe fails at once and the alert looks like a general outage. Prefer a long-lived technical token dedicated to monitoring, or OAuth2, which renews the token.
OAuth 2.0 (client credentials) #
modules:
# The token is obtained (then renewed) from the authorization server
http_oauth2_api:
prober: http
timeout: 10s
http:
oauth2:
client_id: blackbox-probe
client_secret_file: /etc/blackbox_exporter/secrets/oauth_client_secret
token_url: https://auth.example.com/realms/prod/protocol/openid-connect/token
scopes: [api.read]
endpoint_params:
audience: orders-apiThe exporter requests a token from token_url using the client credentials flow, caches it and renews it before expiry. This is the right method for APIs behind Keycloak, Entra ID or Auth0. Create a dedicated client with only the read scope needed.
Client certificate (mTLS) #
modules:
# Client certificate required by the server
https_mtls_partner:
prober: http
timeout: 10s
http:
fail_if_not_ssl: true
tls_config:
ca_file: /etc/blackbox_exporter/secrets/partner-ca.pem
cert_file: /etc/blackbox_exporter/secrets/client.crt
key_file: /etc/blackbox_exporter/secrets/client.keyThe same tls_config block works for TCP and gRPC probes. The private key must be readable by the exporter's user (nobody in the official image).
API key in a header #
modules:
# Avoid: the key shows in plain text on /config
http_header_key:
prober: http
http:
headers:
X-API-Key: 8f2c1d0e-cle-en-clairheaders values are not treated as secrets: they show in plain text on /config and on the home page, whereas password, credentials or client_secret are shown as <secret>. If the API accepts Authorization: ApiKey …, use the authorization block; otherwise, strictly restrict access to port 9115.
Storing secrets #
| Method | Where the secret lives | Verdict |
|---|---|---|
Value in blackbox.yml | configuration file, often in Git | avoid |
*_file fields + mounted file | separate file, restricted permissions | recommended |
| Docker / Compose secrets | /run/secrets/… | recommended outside Kubernetes |
| Kubernetes Secret as a volume | mounted in the pod | recommended; fed by External Secrets or Vault |
Credentials in the URL (https://user:pwd@…) | instance label, API, dashboards | avoid |
# Docker Compose: secrets mounted read-only
services:
blackbox:
image: prom/blackbox-exporter:v0.27.0
volumes:
- ./blackbox.yml:/etc/blackbox_exporter/config.yml:ro
- ./secrets:/etc/blackbox_exporter/secrets:ro# Kubernetes: Secret mounted in the Blackbox Exporter pod (Helm chart)
kubectl -n monitoring create secret generic blackbox-probe-secrets \
--from-file=intranet_password=./intranet_password \
--from-file=api_token=./api_token# values.yaml du chart prometheus-blackbox-exporter
extraSecretMounts:
- name: probe-secrets
secretName: blackbox-probe-secrets
mountPath: /etc/blackbox_exporter/secrets
readOnly: true
config:
modules:
http_basic_intranet:
prober: http
http:
basic_auth:
username: svc-monitoring
password_file: /etc/blackbox_exporter/secrets/intranet_passwordGood to know : Do not rely on environment variable expansion inblackbox.yml: use thepassword_file,credentials_file,client_secret_file,cert_file/key_filefields, or generate the file at deploy time (Ansible, Helm).
Monitoring accounts: the rules #
- One dedicated technical account per application, never a personal account: a colleague leaving must not trigger alerts.
- Minimal rights: read-only, on a health page when possible.
- No MFA nor interactive SSO: the probe cannot fill in a form. To test an SSO login end to end, use a scenario tool.
- Beware of lockouts: one probe every 15 s with an outdated password is 240 failures per hour; many directories lock the account, sometimes together with others sharing the same policy.
- One module per credential set, named
<prober>_<auth>_<service>(e.g.http_basic_intranet). - Check the protection too: an anonymous module with
valid_status_codes: [401]confirms an admin page is not open to everyone.
8. Integrating with Prometheus #
Target files, multiple locations, Kubernetes and exporter monitoring.
A target file and one module per target #
Rather than one job per module, keep a single job and let each target pick its module through a label, copied into __param_module. Adding a test means adding two lines to an automatically reloaded file.
# targets.yml: the list of tests, editable without touching prometheus.yml
- targets: [https://www.example.com, https://shop.example.com]
labels: { module: https_site, team: web }
- targets: [https://api.example.com/health]
labels: { module: http_api_health, team: api }
- targets: [https://intranet.example.com]
labels: { module: http_basic_intranet, team: it }scrape_configs:
- job_name: blackbox
metrics_path: /probe
file_sd_configs:
- files: [/etc/prometheus/targets/*.yml]
refresh_interval: 1m
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
# the module comes from the target's label
- source_labels: [module]
target_label: __param_module
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: blackbox:9115Good to know : Themodulelabel stays on the series: it lets you filter dashboards and route alerts (for exampleteamto the right team in Alertmanager).
Probing from several locations #
# One instance per location, same target list
scrape_configs:
- job_name: blackbox-paris
metrics_path: /probe
file_sd_configs: [{ files: [/etc/prometheus/targets/*.yml] }]
relabel_configs:
- { source_labels: [__address__], target_label: __param_target }
- { source_labels: [module], target_label: __param_module }
- { source_labels: [__param_target], target_label: instance }
- { target_label: probe_location, replacement: paris }
- { target_label: __address__, replacement: blackbox-paris.example.net:9115 }
# … same job for blackbox-frankfurt with probe_location: frankfurt
# Alert only if at least two locations fail
count by (instance) (probe_success == 0) >= 2Best practice : Run at least one instance outside your infrastructure (another cloud, another region): if your whole network goes down, the internal probe goes down with it and cannot alert.
On Kubernetes: the Probe resource #
With the Prometheus Operator, the Probe resource generates the job and the relabeling. It can list static URLs or discover Ingress objects carrying a label.
apiVersion: monitoring.coreos.com/v1
kind: Probe
metadata:
name: sites-publics
namespace: monitoring
labels:
release: kube-prometheus-stack
spec:
jobName: blackbox-sites
interval: 30s
module: https_site
prober:
url: blackbox-prometheus-blackbox-exporter.monitoring.svc:9115
path: /probe
targets:
staticConfig:
static:
- https://www.example.com
- https://shop.example.com
labels:
team: webCommon mistake : Thereleaselabel must match theprobeSelectorof yourPrometheusresource; otherwise the probe is silently ignored.
Monitoring the exporter #
# The exporter itself: reloaded configuration, unknown modules
scrape_configs:
- job_name: blackbox-exporter
static_configs:
- targets: [blackbox:9115]To watch: blackbox_exporter_config_last_reload_successful (0 = invalid configuration, the old one stays active), blackbox_module_unknown_total (misspelled module) and up{job="blackbox-exporter"}.
9. Metrics, dashboards and alerts #
The series to know and ready-to-use alert rules.
Essential metrics #
| Metric | Prober | Meaning |
|---|---|---|
probe_success | all | 1 if the probe succeeded, 0 otherwise |
probe_duration_seconds | all | total probe duration (gauge) |
probe_http_status_code | http | code of the last response |
probe_http_duration_seconds{phase} | http | duration by phase |
probe_http_redirects, probe_http_ssl, probe_http_version | http | redirects, final HTTPS, HTTP version |
probe_failed_due_to_regex | http, tcp | 1 if the failure comes from a regular expression |
probe_ssl_earliest_cert_expiry | http, tcp, grpc | expiry timestamp of the first certificate |
probe_tls_version_info{version} | http, tcp | negotiated TLS version |
probe_dns_lookup_time_seconds | all | target name resolution time |
probe_ip_protocol | all | 4 or 6: family used |
probe_dns_answer_rrs | dns | number of records in the answer |
probe_icmp_duration_seconds{phase} | icmp | resolve, setup, round trip |
probe_grpc_healthcheck_response{serving_status} | grpc | state reported by the service |
Alert rules #
groups:
- name: blackbox
rules:
- alert: ProbeFailed
expr: probe_success == 0
for: 2m
labels: { severity: critical }
annotations:
summary: "{{ $labels.module }} probe failing on {{ $labels.instance }}"
- alert: ProbeSlow
expr: avg_over_time(probe_duration_seconds[5m]) > 2
for: 10m
labels: { severity: warning }
annotations:
summary: "Average response time above 2 s on {{ $labels.instance }}"
- alert: CertificateExpiresSoon
expr: (probe_ssl_earliest_cert_expiry - time()) / 86400 < 14
for: 1h
labels: { severity: warning }
annotations:
summary: "The certificate of {{ $labels.instance }} expires in less than 14 days"
- alert: CertificateExpiresVerySoon
expr: (probe_ssl_earliest_cert_expiry - time()) / 86400 < 3
labels: { severity: critical }
annotations:
summary: "The certificate of {{ $labels.instance }} expires in less than 3 days"
- alert: TlsVersionObsolete
expr: probe_tls_version_info{version=~"TLS 1\\.[01]"} == 1
labels: { severity: warning }
annotations:
summary: "{{ $labels.instance }} still negotiates TLS 1.0 or 1.1"
- alert: BlackboxConfigReloadFailed
expr: blackbox_exporter_config_last_reload_successful == 0
for: 5m
labels: { severity: warning }
annotations:
summary: "Blackbox Exporter configuration not reloaded"Common mistake :probe_duration_secondsis a gauge, not a histogram:histogram_quantile()does not apply. Useavg_over_time(),max_over_time()orquantile_over_time(0.95, probe_duration_seconds[1h]).
Best practice : Keep afor:of at least two probe intervals onProbeFailed: a single failure (lost packet, restart) must not wake the on-call. For certificates, a 14-day alert leaves time to act before the critical one.
Useful queries and dashboards #
# 30-day availability (in %)
avg_over_time(probe_success{job="blackbox"}[30d]) * 100
# Slowest phase of each URL
topk by (instance) (1, probe_http_duration_seconds)
# Days left before expiry, soonest first
sort((probe_ssl_earliest_cert_expiry - time()) / 86400)avg_over_time(probe_success[30d]) gives an availability measured from outside, the basis of an availability SLI (see the SRE course). For long periods, store it with a recording rule. In Grafana, community “Prometheus Blackbox Exporter” dashboards (ID 7587, for example) give a starting point to adapt.
10. Securing and operating #
Protecting the exporter, best practices, common mistakes and commands.
An exporter that calls any URL #
Anyone who can reach port 9115 can make the exporter send a request to any address, internal ones included (Server-Side Request Forgery), with a module's credentials if they pick one. The Blackbox Exporter has no target allowlist: protection comes from the network and authentication.
# web.yml: authentication and TLS on the Blackbox Exporter itself
basic_auth_users:
prometheus: $2y$10$Wq0f6M2tJ3wq3y6n3xkG0e0Hq1YxYp7l1W2r3N4c5V6b7M8n9O0pq # bcrypt hash
tls_server_config:
cert_file: /etc/blackbox_exporter/tls/server.crt
key_file: /etc/blackbox_exporter/tls/server.key# Generate the hash
htpasswd -nBC 10 prometheus | cut -d: -f2
blackbox_exporter --config.file=blackbox.yml --web.config.file=web.yml# On the Prometheus side, this is the right level: we authenticate to the exporter
scrape_configs:
- job_name: blackbox
metrics_path: /probe
scheme: https
basic_auth:
username: prometheus
password_file: /etc/prometheus/secrets/blackbox_password
tls_config:
ca_file: /etc/prometheus/secrets/ca.pem- Never expose the exporter to the Internet; on Kubernetes, a
NetworkPolicyallows only Prometheus. - Restrict the listen address (
--web.listen-address=127.0.0.1:9115if Prometheus runs on the same host). - Split instances: one for anonymous public tests, another, more locked down, for credentialed modules.
Best practices #
- Test what users see: public name, HTTPS, from outside.
- Prefer dedicated health pages, lightweight and side-effect free.
- A 30 s to 1 min interval is usually enough; 15 s for critical services.
- Version
blackbox.ymland target files, validate in CI with--config.checkandpromtool. - Identify the probe in server logs (dedicated
User-Agent) and exclude it from audience statistics. - Always alert on certificate expiry, non-HTTP services included.
- Keep secrets out of the configuration (
*_file) and one technical account per application.
Common mistakes #
| Symptom | Likely cause |
|---|---|
Target “DOWN” in /targets, connection error to the site | __address__ → blackbox:9115 rule missing |
All series share the same instance | __param_target to instance copy forgotten |
probe_http_status_code 401 despite credentials | credentials in scrape_config instead of the module |
probe_success 0, probe_http_status_code 0 | DNS, connection, TLS or timeout: run the probe with debug=true |
| Failure after exactly 9.5 s | default scrape_timeout (10 s) minus the offset |
| Code 400 “Unknown module” | wrong module name or configuration not reloaded |
| ICMP: “socket: permission denied” | neither CAP_NET_RAW nor ping_group_range |
| DNS probe failing while the name resolves | target = name to resolve instead of the DNS server |
Commands to know #
blackbox_exporter --config.file=blackbox.yml --config.check
curl -X POST localhost:9115/-/reload
curl -s 'localhost:9115/probe?module=http_2xx&target=https://example.com&debug=true'
curl -s localhost:9115/config
curl -s localhost:9115/metrics | grep blackbox_
promtool check config prometheus.yml
curl -s localhost:9090/api/v1/targets | jq '.data.activeTargets[] | {instance: .labels.instance, health}'
curl -s --get --data-urlencode 'query=probe_success == 0' localhost:9090/api/v1/query | jq '.data.result[].metric.instance'