It's easy to check if HTTP and HTTPS endpoints are working with the Blackbox Exporter.

The Blackbox exporter supports several different types of probes, which includes HTTP. To demonstrate this let's start by downloading and running the blackbox exporter:

wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.12.0/blackbox_exporter-0.12.0.linux-amd64.tar.gz
tar -xzf blackbox_exporter-*.linux-amd64.tar.gz
cd blackbox_exporter-*
./blackbox_exporter

How the Blackbox exporter works is that the /probe endpoint takes module and target URL parameters. Modules are configured in blackbox.yml and the default config includes a http_2xx module which does a HTTP probe which considers any 2xx HTTP response successful. So if you visit http://localhost:9115/probe?module=http_2xx&target=https://www.robustperception.io/ you will see the result of a probe of https://www.robustperception.io/. In particular look at the probe_success metric, which will be 1 if the probe succeeded and 0 if it failed.

 

Now that the exporter is working, let's setup a Prometheus to use it:

wget https://github.com/prometheus/prometheus/releases/download/v2.4.2/prometheus-2.4.2.linux-amd64.tar.gz
tar -xzf prometheus-*.tar.gz
cd prometheus-*
cat <<'EOF' > prometheus.yml
global:
 scrape_interval: 10s
scrape_configs:
 - job_name: blackbox
   metrics_path: /probe
   params:
     module: [http_2xx]
   static_configs:
    - targets:
       - https://www.robustperception.io/
       - http://prometheus.io/blog
   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 blackbox exporter.
EOF
./prometheus

The relabel_configs change the usual targets into URL parameters on the blackbox exporter. As you can see, paths can be included and HTTP and HTTPS are handled in the same way.

If you wait a few seconds, you will see the result of probe_success in the expression browser. You may see a surprising failure if you don't have a working IPv6 setup, as the Blackbox exporter will prefer an IPv6 address if one is returned by DNS. You can adjust this behaviour by adding preferred_ip_protocol: "ip4" to the module's configuration.

 

If you wanted to alert on probes failing you should look at both the up and probe_success metrics, to catch either the exporter or target having issues:

groups:
- name: example
  rules:
   - alert: ProbeFailing
     expr: up{job="blackbox"} == 0 or probe_success{job="blackbox"} == 0
     for: 10m

 

Want to know more about blackbox monitoring? Contact us.