🚀 Setting Up Blackbox Exporter with Prometheus
📥 Download and Extract Blackbox Exporter
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.23.0/blackbox_exporter-0.23.0.linux-amd64.tar.gz
tar xvfz blackbox_exporter-0.23.0.linux-amd64.tar.gz
cd blackbox_exporter-0.23.0.linux-amd64
📁 Move Binary to /usr/local/bin/
sudo mv blackbox_exporter /usr/local/bin/
📌 Create Configuration Directory and Edit Config File
sudo mkdir -p /etc/blackbox_exporter
sudo vi /etc/blackbox_exporter/blackbox_exporter.yml
📝 blackbox_exporter.yml
Configuration
---
modules:
http_2xx:
prober: http
timeout: 10s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2", "HTTP/2.0"]
valid_status_codes: []
follow_redirects: true
fail_if_ssl: false
fail_if_not_ssl: false
🎯 Configure Prometheus to Use Blackbox Exporter
vi /etc/prometheus/blackbox.yml
📝 blackbox.yml
Configuration
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2.0"]
valid_status_codes: [200, 301, 302]
method: GET
no_follow_redirects: false
🔧 Create Systemd Service for Blackbox Exporter
vi /etc/systemd/system/blackbox_exporter.service
📝 blackbox_exporter.service
Configuration
[Unit]
Description=Blackbox Exporter
After=network-online.target
[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/blackbox_exporter --config.file=/etc/blackbox_exporter/blackbox_exporter.yml --log.level=debug
Restart=always
[Install]
WantedBy=multi-user.target
🌐 Configure Prometheus to Scrape Blackbox Exporter
vi /etc/prometheus/prometheus.yml
📝 prometheus.yml
Configuration
- job_name: 'office_smartlocs'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- http://asifahmadkhan.com
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: localhost:9115 # The Blackbox Exporter's address
- source_labels: [__param_target]
target_label: instance
✅ Verify Probing
curl "http://localhost:9115/probe?target=http://asifahmadkhan.com&module=http_2xx"
🔄 Restart Services and Verify Status
# Reload systemd daemon (if you've made changes to service files)
sudo systemctl daemon-reload
# Restart Blackbox Exporter
sudo systemctl restart blackbox_exporter
# Restart Prometheus
sudo systemctl restart prometheus
# Check status to ensure they are running
sudo systemctl status blackbox_exporter
sudo systemctl status prometheus
🎉 Congratulations! Blackbox Exporter is now set up and integrated with Prometheus. 🚀