Blackbox exporter: HTTP, TCP and certificate probes without instrumenting the app
Your application passes its own health checks, yet a customer cannot log in: the certificate expired overnight, or a firewall closed port 443. The blackbox exporter covers exactly this case. It plays the part of an outside visitor and tells you whether the door opens, with nothing installed inside the application. The facts come from the prometheus/blackbox_exporter repository (README,…
The blackbox exporter is an open-source tool that allows monitoring and checking the health of various services without requiring any instrumentation inside the application itself. This is particularly useful when dealing with third-party services, legacy software, load balancers, databases, or certificates. The blackbox exporter probes HTTP, HTTPS, DNS, TCP, ICMP, and gRPC protocols to determine if the service is reachable, responds as expected, and if its certificate is still valid.
The exporter operates by scraping the Prometheus server on the /probe endpoint, which takes two parameters: the target (the service to check) and the module (the method to use for checking). It then performs the specified probe and returns metrics about that single attempt. Adding new targets only requires adding a line to the Prometheus configuration, and the probe_success metric is 1 when the probe succeeds and 0 otherwise, which can be used to trigger alerts.
To set up HTTP and TCP probes, two modules are defined: valid_status_codes and fail_if_not_ssl for HTTP, and prober with tls: true for TCP. The configuration file can be reloaded without a restart through SIGHUP, POST to /-/reload, or by using --config.enable-auto-reload. A malformed configuration file is not applied. The targets are then wired into Prometheus using relabeling, and a second job scrapes the exporter itself on /metrics to ensure all probes remain active.
Certificates are particularly important, as the exporter publishes probe_ssl_earliest_cert_expiry, which is a Unix timestamp representing the remaining time until the certificate expires. This can be used to set a threshold for alerting, such as 14 days before expiry. The README warns about the default behavior of DNS resolution on every probe and recommends using a caching resolver or setting the preferred_ip_protocol to IPv4.
When setting up the blackbox exporter, keep in mind that the exporter makes requests to any target it is given, so it should be protected with TLS and basic authentication, and should never be published on the internet. To check if the exporter is working correctly, you can call http://localhost:9115/probe?target=https://example.org&module=http_2xx, and the response should contain probe_success 1.
Monitoring the exporter through Prometheus' Status > Targets page ensures the blackbox job is marked as "UP". Good practice includes running one probe per important journey, running the exporter from several network locations, and alerting on the certificate well before expiry.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to