
Your API returns HTTP 200, but the response is a maintenance page. A status-only uptime check stays green. Prometheus Blackbox Exporter can catch that failure by checking the body as well as the status. It also gives you a way to tell whether the API failed or your monitoring system lost contact with the exporter.
This guide sets up one HTTP probe on a CPU VM separate from the application. The test endpoint has a small, explicit contract. A GET request to /ready should return HTTP 200 with the plain-text body ready. Replace the example URL with an endpoint you operate and adjust the expected response to match it.
Prometheus asks the exporter to probe a URL. The exporter makes the request and returns metrics to Prometheus. The connection to the application originates on the exporter’s machine. That determines which DNS resolver, network route, and TLS trust store the check uses. How the Prometheus multi-target exporter pattern works.
Run Prometheus and Blackbox Exporter together on the monitoring VM for this example. Give the VM a route to the application’s public hostname, or the private hostname used by internal clients. For an API behind a reverse proxy such as Caddy or Nginx, use the hostname clients actually call so the probe crosses that proxy. A Docker Compose healthcheck can tell you whether a container is healthy from the inside. Keep it alongside the external check to narrow down failures.
Get the binaries for your VM’s operating system and architecture from the official Prometheus downloads. The shell examples assume a Linux VM with the blackbox_exporter, prometheus, and promtool executables in a working directory you can write to. Put the three YAML files below in that directory.
modules:
api_ready:
prober: http
timeout: 4s
http:
method: GET
valid_status_codes: [200]
follow_redirects: false
fail_if_body_not_matches_regexp: ['^ready$']
The bundled http_2xx module is a useful starting point for general web availability. An API with a specific readiness response needs a body check as well. The module named api_ready requires HTTP 200 and an exact body match. A redirect to a login screen should fail this check, so the module turns off redirects. A service that deliberately returns 204 with an empty body needs a different module. For HTTPS targets, leave certificate verification enabled. Blackbox Exporter HTTP configuration.
Start the exporter in one terminal on the monitoring VM. From a second terminal on the same VM, run the probe once before adding it to Prometheus. Replace the sample target in both the command and the configuration below.
./blackbox_exporter --config.file=blackbox.yml --web.listen-address=127.0.0.1:9115
curl -sS -G http://127.0.0.1:9115/probe \
--data-urlencode 'module=api_ready' \
--data-urlencode 'target=https://api.example.com/ready' \
| grep -E '^(probe_success|probe_http_status_code|probe_duration_seconds) '
Look for probe_success 1 and probe_http_status_code 200. The /metrics endpoint describes the exporter process itself. The /probe endpoint runs the named module against the target. Keep port 9115 on loopback with this layout. The exporter accepts a target parameter, so anyone who can reach that interface could direct requests from the monitoring VM. Prometheus security model.
Save the following as prometheus.yml. The first relabeling step passes the target URL to the exporter. The second keeps that URL as the instance label so you can identify the failing API in an alert. The final step points the actual scrape at the exporter on the VM. This configuration assumes both processes share the host network. In separate containers, loopback points back into each container.
global:
scrape_interval: 15s
scrape_timeout: 7s
evaluation_interval: 15s
rule_files: [alerts.yml]
scrape_configs:
- job_name: api_probe
metrics_path: /probe
params:
module: [api_ready]
static_configs:
- targets: ['https://api.example.com/ready']
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: '127.0.0.1:9115'
The probe has four seconds to check the target. Prometheus allows seven seconds for the full scrape, leaving time to return metrics before the next 15-second interval. A shorter probe timeout helps preserve a target failure as a readable result.
Save these rules as alerts.yml. probe_success describes the outcome of a probe. Prometheus sets up according to whether it collected metrics for the configured scrape. Both rules require 30 seconds of continuous failure. The observed time to alert also depends on when the next scrape and rule evaluation run. Prometheus alerting rules.
groups:
- name: api_availability
rules:
- alert: ApiReadinessFailed
expr: probe_success{job="api_probe"} == 0
for: 30s
annotations:
summary: 'Readiness check failed for {{ $labels.instance }}'
- alert: ApiProbeScrapeFailed
expr: up{job="api_probe"} == 0
for: 30s
annotations:
summary: 'Prometheus could not collect probe metrics for {{ $labels.instance }}'
Validate the configuration, start Prometheus in a second terminal, and open its local Alerts page at http://127.0.0.1:9090/alerts on the monitor. If the VM is remote, use your usual authenticated tunnel. For on-call notifications, route firing alerts through Alertmanager and test delivery to the intended receiver.
./promtool check config prometheus.yml
./prometheus --config.file=prometheus.yml --web.listen-address=127.0.0.1:9090
We ran Prometheus 3.16.0 and Blackbox Exporter 0.29.1 against a disposable HTTP service. To shorten the drill, we scraped and evaluated every three seconds, with a one-second probe timeout and a two-second scrape timeout. The alert hold remained 30 seconds. We read the firing and clearing states in Prometheus itself.
ready. Both up and probe_success were 1.maintenance kept up at 1 and dropped probe_success to 0. ApiReadinessFailed fired.probe_http_status_code. When we stopped the API listener, the HTTP status metric became 0 because no HTTP response arrived. Restoring the listener and the correct body cleared the alert.up 0. The probe series disappeared from the instant query, and ApiProbeScrapeFailed fired. Restarting the exporter restored both signals and cleared the alert.These failures were induced in separate processes on one test host. In a separate HTTPS check from that host, the exporter reached Hivenet’s public CPU page, received HTTP 200, and found the expected text. That single request verified reachability at that moment. A production check should exercise your own endpoint from the network where availability matters.
If the probe fails while the scrape succeeds, start with the target. Read the HTTP status, check the expected body, then look at DNS and TLS if no response arrived. If up drops, first check the exporter process, its listen address, and the scrape timeout. If the entire monitoring VM stops, its own Prometheus cannot notify you. Use an independently hosted heartbeat when that failure also needs to page someone.
A separate CPU instance with Hivenet is one place to run this monitor. Choose a location that can reach the same endpoint as your users. Before wiring the alert to the on-call team, repeat the wrong-body and recovery tests against a disposable service, then confirm the notification reaches its destination.
Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.