Install Blackbox Exporter for Prometheus

Blackbox Exporter for Prometheus


What is Prometheus Blackbox Exporter?

Prometheus provides a wide variety of exporters to expose metrics according to different use cases. Blackbox Exporter is one of the most commonly used metrics exporters of Prometheus. Blackbox Exporter can be used to expose metrics related to the endpoints which we need to monitor. This is an official exporter of Prometheus written in the Go programming language.
Blackbox Exporter allows probing of endpoints over HTTP, HTTPS, DNS, TCS, and ICMP.

Today's Agenda

In this post, we will learn how to install Prometheus Blackbox Exporter to monitor crucial endpoints of our application. We will probe these endpoints on the basis of their status codes.

Prerequisite

This post has been prepared for the audience who :
  1. Have access to a Linux-based system although the steps are almost similar in other platforms like CentOS or MacOS.
  2. Have a basic understanding of Linux based systems and their commands.
  3. Have Prometheus installed already to which we will add the exporter configuration. If not already done, please follow Setup Prometheus for Monitoring.

Let's get started


Run the below shell script with the root user on the server. You will see Blackbox Exporter running as a service on port 9115 in your machine.
Note: You can update the version of Blackbox Exporter in the shell script in shaded regions.

#!/bin/bash

set -e

if [[ $EUID -ne 0 ]]; then
  echo "Permission Denied! This script must be run as root"
  exit 1
fi

## Download blackbox-exporter package and extract
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/

blackbox_exporter-0.16.0.linux-amd64.tar.gz
tar xfz blackbox_exporter-*.*-amd64.tar.gz

cp blackbox_exporter-*.*-amd64/blackbox_exporter /usr/local/bin
chown root:root /usr/local/bin/blackbox_exporter
chmod 755 /usr/local/bin/blackbox_exporter

mkdir -p /etc/blackbox_exporter
cat > /etc/blackbox_exporter/blackbox.yml << EOF
modules:
  http_2xx:
    prober: http
    timeout: 10s
    http:
      method: GET
      valid_status_codes: []
EOF

chown root:root /etc/blackbox_exporter/blackbox.yml
chmod 644 /etc/blackbox_exporter/blackbox.yml

rm -rf blackbox_exporter*

## Create blackbox-exporter service
cat > /etc/systemd/system/blackbox_exporter.service << EOF
[Unit]
Description=Blackbox Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/blackbox_exporter --config.file /etc/

blackbox_exporter/blackbox.yml

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start blackbox_exporter
systemctl enable blackbox_exporter


Please follow our post Configure Exporters in Prometheus to understand how to connect Blackbox Exporter with Prometheus to start getting the system metrics.

You can also create a new user for Blackbox Exporter to make the necessary changes in the script.

If you want to know how you can create a new user in Linux, please go through our post on Setup Prometheus for Monitoring posts and follow Step 1 of the post.

Finally, run the below command to check if Blackbox Exporter has started exposing the system metrics at port 9115.

$ curl localhost:9115/metrics


OUTPUT


Blackbox Exporter running on port 9115
Blackbox Exporter running on port 9115







Comments