RousselTMLEARNING

Observability

Testing URLs with the Blackbox Exporter: HTTP, TCP, DNS, ICMP, gRPC and credentials

Complete guide to the Prometheus Blackbox Exporter: how probes work, pros and cons, HTTP(S), TCP, DNS, ICMP and gRPC tests, protected URLs (basic auth, Bearer, OAuth2, mTLS) and secret storage, Prometheus and Kubernetes integration, alerts and security.

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?”.

CriterionWhite box (exporters)Black box (URL tests)
QuestionWhy is the service unhealthy?Does the service answer clients correctly?
Examplehttp_requests_total, node_memory_*probe_success, probe_http_duration_seconds
Detectssaturation, internal errors, leaksDNS, certificate, network, proxy, CDN, full outage
Misseswhat stops the request from arrivingthe 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).

Blackbox Exporter architecture
Prometheus triggers every probe; the Blackbox Exporter plays the client.

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: ip4
The five probers
Each module uses exactly one prober.

The 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:9115
Multi-target relabeling
Three relabeling rules are enough.
Common mistake : Without the last rule, Prometheus tries to connect to https://www.example.com:80/probe and the target shows as down in /targets. Without the second, every series carries instance="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 timeoutscrape_timeoutEffective timeout
5s10s5 s
30s10s (default)9.5 s
30s35s30 s
Best practice : For a page that is slow by nature, raise both the module timeout and the job scrape_timeout, which must stay below the scrape_interval.

3. Pros and cons #

What the Blackbox Exporter does well, its limits and the alternatives.

The advantages #

AdvantageIn practice
Light and simplea dependency-free Go binary, a few MB of memory, a short YAML configuration
Built into Prometheussame tools to store, query (PromQL), visualize (Grafana) and alert (Alertmanager)
Multi-protocolHTTP(S), TCP, DNS, ICMP and gRPC in one tool
Detailed measurementsper-phase timing, TLS version, certificate expiry, number of redirects
Configuration as codemodules and targets versioned in Git, service discovery, Probe resource on Kubernetes
Free and open sourceApache 2.0 licence, no limit on the number of tests
Multiple viewpointsone instance per network or region is enough to test from inside and outside

Drawbacks and limits #

LimitConsequenceWorkaround
One request per probeno multi-step journeys (log in, then cart, then payment)Grafana k6, Synthetic Monitoring, Playwright
No browserJavaScript is not executed: a page blank for the client can return 200k6 browser, RUM (Grafana Faro)
Regex-based content checkschecking a given JSON field is brittlededicated health page; CEL on JSON in recent versions
Credentials at module levelone module per credential set: configuration growsstrict naming, generated configuration
No built-in secret managementno direct link to Vault or a cloud vaultmounted files (*_file) fed by Kubernetes, Vault Agent, External Secrets
One location per instancea local outage looks like a site outageseveral instances and majority alerting
/probe calls whatever it is askedSSRF risk if the exporter is exposedrestricted network, --web.config.file
Result = metrics onlyno history of the responses received nor screenshotsdebug=true log, full synthetic tools
Privileged ICMPping needs CAP_NET_RAW or a kernel settingsetcap, net.ipv4.ping_group_range

Blackbox Exporter or another tool? #

ToolStrengthPick it when…
Blackbox Exporternative Prometheus integration, multi-protocolyou already run Prometheus and want many simple tests
Uptime Kumaweb UI, status pages, ready-made notificationsa small team wants a status page without writing YAML
Grafana k6JavaScript-scripted scenarios, browseryou need to test a full user journey
Grafana Cloud Synthetic Monitoringmanaged probes worldwide (engine derived from the Blackbox Exporter)you want to test from many regions without hosting anything
SaaS (Pingdom, Datadog Synthetics…)turnkey, SLA reportsbudget 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.yaml
Good to know : The image reads /etc/blackbox_exporter/config.yml by default and listens on port 9115. With Helm, modules are declared under the config.modules key of values.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/config

The 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.

Manual probe with debug=true
The log shows at which step the probe fails.
Classic trap : A failed probe still returns HTTP 200 to Prometheus, with probe_success 0. The target therefore stays “UP” in /targets: watch probe_success, not up.
Best practice : An unknown module name makes the /probe request fail (code 400) and increments blackbox_module_unknown_total: a typo in targets.yml shows 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
OptionDefaultRole
valid_status_codes2xxaccepted codes (e.g. [200, 301], or [401] to check a page is protected)
valid_http_versionsallaccepted HTTP versions
methodGETHTTP method
follow_redirectstruefollow redirects; the code judged is that of the last response
fail_if_ssl / fail_if_not_sslfalserequire or forbid HTTPS on the final response
preferred_ip_protocolip6address family tried first
ip_protocol_fallbacktruefall back to the other family if the first one does not exist
Common mistake : The preferred_ip_protocol: ip6 default is surprising: on an IPv6-less network the probe falls back to IPv4, but probe_ip_protocol changes and resolution is done twice. Set ip4 explicitly if your network has no IPv6, or ip_protocol_fallback: false to 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: 1MB
Good to know : Recent versions add fail_if_body_json_matches_cel and fail_if_body_json_not_matches_cel, which evaluate a CEL expression on a JSON body (for example body.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: true

Every 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: true hides exactly the failures you want to catch (expired certificate, wrong name, unknown authority). For an internal authority, provide ca_file instead 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.

HTTP probe phases
Here, time is spent on the server side (processing).
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 : With tls: true or starttls, 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: ip4

The 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.

Two authentication levels
(1) protects the exporter, (2) authenticates the probe to the target.
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 : This basic_auth is sent to the Blackbox Exporter, which ignores it if unprotected; the target receives an anonymous request and answers 401. Result: probe_success 0 and probe_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_password

password 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_key

The 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-api

The 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.key

The 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-clair

headers 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 #

MethodWhere the secret livesVerdict
Value in blackbox.ymlconfiguration file, often in Gitavoid
*_file fields + mounted fileseparate file, restricted permissionsrecommended
Docker / Compose secrets/run/secrets/…recommended outside Kubernetes
Kubernetes Secret as a volumemounted in the podrecommended; fed by External Secrets or Vault
Credentials in the URL (https://user:pwd@…)instance label, API, dashboardsavoid
# 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_password
Good to know : Do not rely on environment variable expansion in blackbox.yml: use the password_file, credentials_file, client_secret_file, cert_file/key_file fields, 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:9115
Good to know : The module label stays on the series: it lets you filter dashboards and route alerts (for example team to 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) >= 2
Best 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: web
Common mistake : The release label must match the probeSelector of your Prometheus resource; 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 #

MetricProberMeaning
probe_successall1 if the probe succeeded, 0 otherwise
probe_duration_secondsalltotal probe duration (gauge)
probe_http_status_codehttpcode of the last response
probe_http_duration_seconds{phase}httpduration by phase
probe_http_redirects, probe_http_ssl, probe_http_versionhttpredirects, final HTTPS, HTTP version
probe_failed_due_to_regexhttp, tcp1 if the failure comes from a regular expression
probe_ssl_earliest_cert_expiryhttp, tcp, grpcexpiry timestamp of the first certificate
probe_tls_version_info{version}http, tcpnegotiated TLS version
probe_dns_lookup_time_secondsalltarget name resolution time
probe_ip_protocolall4 or 6: family used
probe_dns_answer_rrsdnsnumber of records in the answer
probe_icmp_duration_seconds{phase}icmpresolve, setup, round trip
probe_grpc_healthcheck_response{serving_status}grpcstate 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_seconds is a gauge, not a histogram: histogram_quantile() does not apply. Use avg_over_time(), max_over_time() or quantile_over_time(0.95, probe_duration_seconds[1h]).
Best practice : Keep a for: of at least two probe intervals on ProbeFailed: 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 NetworkPolicy allows only Prometheus.
  • Restrict the listen address (--web.listen-address=127.0.0.1:9115 if 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.yml and target files, validate in CI with --config.check and promtool.
  • 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 #

SymptomLikely 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 credentialscredentials in scrape_config instead of the module
probe_success 0, probe_http_status_code 0DNS, connection, TLS or timeout: run the probe with debug=true
Failure after exactly 9.5 sdefault 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 resolvestarget = 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'

Official sources #

Related articles

Time-based vs event-based SLO: understanding, computing and choosing (with the Qonto example)

Differences between time-based SLOs (time slices, uptime) and event-based SLOs (good events over total): defi…

The observability trilemma: cost, completeness and performance, and how solutions resolve it

Understanding the observability trilemma (cost, data completeness, query performance), its three trade-offs, …

Prometheus recording rules: speeding up your queries and dashboards

Understand and master Prometheus recording rules: evaluation, naming convention, pitfalls (ratios, empty seri…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!