Love Grafana for server metrics monitoring? You’ll love Blackbox Exporter for website monitoring too!
In this tutorial, you will learn to install Blackbox Exporter on CentOS/RHEL and understand how to use it with Prometheus and Grafana to monitor website performance and uptime.
What is Blackbox Exporter?
Blackbox Exporter by Prometheus is used to probe endpoints like HTTPS, HTTP, TCP, DNS, and ICMP. After you define the endpoint, the Blackbox exporter generates hundreds of metrics that can be visualized using Grafana. Measuring response time is the most important feature of the Blackbox exporter.
Blackbox Exporter is a self-hosted solution. If you’re looking for something similar, but as SaaS or cloud-based, then you can try Grafana worldPing.
Let me show you how to install Blackbox exporter first.
Step 1: Download Blackbox Exporter
Go to the official page to download the latest Linux AMD Blackbox exporter package. I am downloading the blackbox_exporter-0.16.0.linux-amd64.tar.gz file.
Transfer the downloaded file to the server
Extract files from the package.
[centos@geekflare ~]$ tar -xzf blackbox_exporter-0.16.0.linux-amd64.tar.gz
Check all the files inside Blackbox exporter.
[centos@geekflare ~]$ cd blackbox_exporter-0.16.0.linux-amd64/
[centos@geekflare blackbox_exporter-0.16.0.linux-amd64]$ ls -l
-rwxr-xr-x. 1 centos centos 17050332 Nov 11 2019 blackbox_exporter
-rw-r--r--. 1 centos centos 629 Nov 11 2019 blackbox.yml
-rw-r--r--. 1 centos centos 11357 Nov 11 2019 LICENSE
-rw-r--r--. 1 centos centos 94 Nov 11 2019 NOTICE
Two files blackbox_exporter and blackbox.yml are important here.
blackbox_exporter: This is an executable file for running the service.
blackbox.yml: A YAML file with all the backbox exporter configurations which you define all the endpoints to probe and modules to run.
Below command will give you all the flags you can use with Blackbox exporter.
[centos@geekflare blackbox_exporter-0.16.0.linux-amd64]$ ./blackbox_exporter -h
usage: blackbox_exporter [<flags>]
-h, --help Show context-sensitive help (also try --help-long and --help-man).
Blackbox exporter configuration file.
The address to listen on for HTTP requests.
--timeout-offset=0.5 Offset to subtract from timeout in seconds.
--config.check If true validate the config file and then exit.
--history.limit=100 The maximum amount of items to keep in the history.
The URL under which Blackbox exporter is externally reachable (for example, if Blackbox exporter is served via a
reverse proxy). Used for generating relative and absolute links back to Blackbox exporter itself. If the URL has a
path portion, it will be used to prefix all HTTP endpoints served by Blackbox exporter. If omitted, relevant URL
components will be derived automatically.
Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
--version Show application version.
Step 2: Create User for Blackbox
This is optional.
You may either create a new user to run Blackbox or use existing Prometheus users to run it.
Provide permissions and assign ownership of all its files to the new user.
When you check the targets at http://localhost:9090/targets again, you will find a blackbox job running with the endpoint I defined.
Click on the Graph and run the query – probe_http_duration_seconds.
A visualization will get created on the data being monitored by Prometheus.
Now it is time to visualize the Blackbox job on Grafana.
There are many ways to get it started, but one of the quickest would be to start with a ready-made dashboard – Prometheus Blackbox Exporter.
Go to the Grafana dashboard, click on + sign and click on Import.
In Import via grafana.com, put the dashboard id 7587 and click on Load.
Then select the Prometheus data source and click on Import.
The Prometheus Blackbox Exporter dashboard will get imported.
You will be able to visualize metrics like Global Probe Duration, Status, HTTP Duration, Average Probe Duration, Average DNS Lookup, SSL Expiry, and many more.
These all are separate panels on the dashboard. Let me show the HTTP Duration panel in detail. This panel shows the visualization of time duration taken for connecting, processing, resolve, tls, and transfer requests.
There are a lot many options on the dashboard with which you can play around. You can change the time range for which you want the visualization to appear. You can also change the time interval in data refresh; here, the new data is coming in the dashboard every 5 seconds.
When you click on the HTTP Duration down arrow, you will get the options shown below. Click on edit.
Below the visualization panel, you will get a query editor. Currently, the query shown in the below snapshot is getting visualized – probe_http_duration_seconds.
There are hundreds of queries which you can easily visualize and add it to your dashboard as per the requirement.
You have plenty of options to change the visualization type also. The average probe duration is present on the dashboard in the text format. From the visualization panel on the right, click on the Guage option for average probe duration.
And this is how the visualization will change.
The above is just to give you an idea of how easy it is to monitor the website with Prometheus Blackbox and Grafana. There are plenty of options, and I would strongly suggest playing around with it to experience it. If you are curious about learning Grafana, then check out his online course.
Google Docs does a great job of keeping things simple. The default page setup works great for most documents, and common formatting options are right on the toolbar. However, when you need to do some advanced formatting, you’ll need to dig a little deeper.