๐Ÿšฆ Blackbox Exporter Usage Guide

๐ŸŽฏ Overview

Prometheus Blackbox Exporter probes endpoints over network protocols (HTTP, HTTPS, TCP, ICMP, DNS) and exposes probe results as Prometheus metrics. Unlike nodeโ€‘level exporters, it measures service reachability and response characteristics from the perspective of the probe host.

๐Ÿ“Œ Common Use Cases

๐Ÿงญ How It Works

  1. Prometheus calls Blackbox Exporterโ€™s /probe endpoint.
  2. Prometheus passes target and module parameters.
  3. Blackbox Exporter performs the probe and returns metrics.
  4. Prometheus stores metrics for alerting and dashboards.

๐Ÿงฉ Key Components

๐Ÿ›  Example Blackbox Module Config (blackbox.yml)

modules:
  http_2xx:
    prober: http
    timeout: 5s
    http:
      method: GET
      preferred_ip_protocol: ip4
      valid_status_codes: [200, 301, 302]

  tcp_connect:
    prober: tcp
    timeout: 5s

  icmp:
    prober: icmp
    timeout: 5s
    preferred_ip_protocol: ip4

โš™๏ธ Example Prometheus Scrape Config

HTTP probe

scrape_configs:
  - job_name: blackbox_http
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
        - https://example.com
        - https://grafana.example.com
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: blackbox-exporter:9115

TCP probe

  - job_name: blackbox_tcp
    metrics_path: /probe
    params:
      module: [tcp_connect]
    static_configs:
      - targets:
        - postgres.example.com:5432
        - redis.example.com:6379
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: blackbox-exporter:9115

๐Ÿ“Š Important Metrics

๐Ÿ” Sample PromQL Queries

avg_over_time(probe_success[5m])
probe_success == 0
histogram_quantile(0.95, sum(rate(probe_duration_seconds_bucket[15m])) by (le, instance))
(probe_ssl_earliest_cert_expiry - time()) / 86400

๐Ÿšจ Example Alerts

groups:
  - name: blackbox.rules
    rules:
      - alert: BlackboxProbeFailed
        expr: probe_success == 0
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Probe failed for {{ $labels.instance }}"
          description: "Blackbox probe has been failing for 5 minutes."

      - alert: BlackboxHighLatency
        expr: probe_duration_seconds > 2
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "High probe latency for {{ $labels.instance }}"
          description: "Probe duration is above 2s for 10 minutes."

      - alert: CertificateExpiringSoon
        expr: (probe_ssl_earliest_cert_expiry - time()) < 86400 * 14
        for: 1h
        labels:
          severity: warning
        annotations:
          summary: "Certificate expiring soon for {{ $labels.instance }}"
          description: "TLS certificate will expire in less than 14 days."

๐Ÿš€ Deployment

Blackbox Exporter is deployed using Ansible.

Prerequisites

Use the same role ordering pattern used across this repository:

Example:

---
- name: Deploy Blackbox Exporter
  hosts: blackbox_exporter
  become: true
  roles:
    - global
    - users
    - docker_setup
    - blackbox_exporter_setup

Validate Before Deploy

Run a syntax check first:

ansible-playbook -i inventory/<env>/inventory.ini playbooks/<domain>/deploy_blackbox_exporter.yml --syntax-check

Deploy

Run the playbook:

ansible-playbook -i inventory/<env>/inventory.ini playbooks/<domain>/deploy_blackbox_exporter.yml

Post-Deployment Validation

Health check:

curl http://<blackbox-host>:9115/-/healthy

Probe test:

curl "http://<blackbox-host>:9115/probe?target=https://example.com&module=http_2xx"

Operational Verification

See also: Adding Blackbox Exporter Targets

๐Ÿงช Operational Tips

๐Ÿ›  Troubleshooting

๐Ÿ” Security Considerations

๐Ÿ“ Summary

Blackbox Exporter extends observability from host metrics to real network/service checks. A solid baseline includes: