How to Monitor Website Performance with Blackbox Exporter and Grafana?
Do you love Grafana to monitor server metrics? You will also love Blackbox Exporter for website monitoring!
In this tutorial, you will learn how 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 a black box exporter?
Prometheus Blackbox Exporter is used to probe endpoints such as HTTPS, HTTP, TCP, DNS, and ICMP. After defining the endpoint, the Blackbox exporter generates hundreds of metrics that can be visualized with Grafana. Measuring response time is the most important feature of the Blackbox exporter.
Blackbox Exporter is a self-hosted solution. If you are looking for something similar, but SaaS or cloud based, you can try Grafana worldPing.
previous requirements
Prometheus and Grafana must be pre-installed. Follow this article to install Prometheus and Grafana.
Install Blackbox Exporter
Let me first show you how to install the Blackbox exporter.
Step 1: Download the Blackbox Exporter
Visit the official page to download the latest AMD Blackbox Linux export package. I am downloading the blackbox_exporter-0.16.0.linux-amd64.tar.gz file.
- Transfer the downloaded file to the server
- Extract the package file.
[centos@geekflare ~]$ tar -xzf blackbox_exporter-0.16.0.linux-amd64.tar.gz
Check all the files inside the Blackbox exporter.
[centos@geekflare ~]$ cd blackbox_exporter-0.16.0.linux-amd64/
[centos@geekflare blackbox_exporter-0.16.0.linux-amd64]$ ls -l total 16672 -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 November 11, 2019 LICENSE -rw-r–r–. 1 cents cents 94 November 11, 2019 NOTICE
The two files blackbox_exporter and blackbox.yml are important here.
- blackbox_exporter: This is the executable to run the service.
- blackbox.yml – A YAML file with all of the following box exporter configurations in which you define all of the endpoints to poll and modules to run.
The following command will give you all the flags you can use with the Blackbox exporter.
[centos@geekflare blackbox_exporter-0.16.0.linux-amd64]$ ./blackbox_exporter -h usage: blackbox_exporter [<flags>]
Flags: -h, –help Show contextual help (also try –help-long and –help-man). –config.file=”blackbox.yml” Blackbox exporter configuration file. –web.listen-address=”:9115″ The address to listen for HTTP requests. –timeout-offset=0.5 Offset to subtract timeout in seconds. –config.check If true, check the configuration file and then exit. –history.limit=100 Maximum number of entries saved in history. –web.external-url=
–log.format=logfmt Output format of the log message. One of: [logfmt, json]
–version Shows the version of the application.
Step 2: Create a user for Blackbox
This is optional.
You can create a new user to run Blackbox or use existing Prometheus users to run it.
Grant permissions and assign ownership of all your files to the new user.
[centos@geekflare ~]$ sudo useradd -rs /bin/blackbox false
[centos@geekflare ~]$ sudo chmod -R 777 /home/centos/blackbox_exporter-0.16.0.linux-amd64
[centos@geekflare ~]$ sudo chown -R blackbox:blackbox /home/centos/blackbox_exporter-0.16.0.linux-amd64
Step 3: Set up the black box service
It’s time to configure Blackbox Exporter as a service within systemd. Create a blackbox.service file and put the lines mentioned below in the file and save it.
[centos@geekflare ~]$ sudo gedit /etc/systemd/system/blackbox.service
[Unit]
Description=Black Box Export Service Want=network-online.destination After=network-online.dest
[Service]
Type=simple User=blackbox Group=blackbox ExecStart=/home/centos/blackbox_exporter-0.16.0.linux-amd64/blackbox_exporter –config.file==/home/centos/blackbox_exporter-0.16.0.linux-amd64/blackbox.yml
[Install]
WantedBy=multi-user.target
Don’t forget to change the path to where you extracted it.
Step 4: Launch Blackbox Exporter
Run the following commands to start the Black Box exporter as a service.
[centos@geekflare ~]$ sudo systemctl daemon-reload
[centos@geekflare ~]$ sudo systemctl start blackbox.service
[centos@geekflare ~]$ sudo systemctl status blackbox.service ● blackbox.service – Blackbox Exporter Service Loaded: loaded (/etc/systemd/system/blackbox.service; enabled; default provider: disabled) Active: active (running) as of Saturday 2020-06-13 17:28:40 EDT; 1 second before the main PID: 30427 (blackbox_export) Task: 5 Group c: / └─30427/usr/local/bin/blackbox_exporter –config.file =/etc/blackbox.yml June 13:28:40 geekflare.linuxvmvmimages.com Systemd[1]: Start the Blackbox Exporter service. Jun 13 17:28:40 geekflare.linuxvmimages.com blackbox_exporter[30427]: level=info ts=2020-06-13T21:28:40.283Z caller=main.go:212 msg=”Starting b…b9a9)” Jun 13 17:28:40 geekflare.linuxvmimages.com blackbox_exporter[30427]: level=info ts=2020-06-13T21:28:40.283Z caller=main.go:213 msg=”Build cont…SSING) Jun 13 17:28:40 geekflare.linuxvmimages.com blackbox_exporter[30427]: level=info ts=2020-06-13T21:28:40.283Z caller=main.go:225 msg=”Config file loaded” Jun 13 17:28:40 geekflare.linuxvmimages.com blackbox_exporter[30
Great!
Blackbox exporter has successfully started. At you can find Blackbox Exporter running.
Integrating Blackbox with Prometheus
Let’s integrate Blackbox Exporter with Prometheus to start scraping the metrics.
- Add a blackbox job with below configurations inside the prometheus.yml file. I am going to monitor the performance of .
[centos@geekflare ~]$ sudo gedit /etc/prometheus/prometheus.yml – job_name: ‘blackbox’ metrics_path: /probe params: module: [http_2xx] # Look for HTTP response 200. static_configs: – target: – relabel_configs: – source_labels: [__address__]
destination_label: __target_param – source_labels: [__param_target]
target_label: instance – target_label: __address__ replace: 127.0.0.1:9115 # Blackbox exporter actual hostname: port.
[centos@geekflare ~]$ sudo systemctl restart prometeo.service
- When you take a look at the targets in you will again see a black box job running with the end point I defined.
- Click Chart and run the query: probe_http_duration_seconds.
- A visualization of the data tracked by Prometheus will be created.
Now it’s time to visualize Blackbox’s work in Grafana.
There are many ways to get started, but one of the fastest is to start with the pre-built control panel: Prometheus Blackbox Exporter.
- Go to the Grafana dashboard, click + and click Import.
- Under Import via grafana.com, set the dashboard id 7587 and click Upload.
- Then select the Prometheus data source and click Import.
- The Prometheus Blackbox Exporter console will be imported.
- You will be able to view metrics such as global survey duration, status, HTTP duration, average survey duration, average DNS lookup, SSL expiration, etc.
- These are all separate panels on the dashboard. Let me show the details of the HTTP lifetime table. This table shows a visualization of how long it took to connect, process, resolve, tls, and transfer requests.
There are many options on the console that you can play with. You can change the time interval in which you want the displayed image to appear. You can also change the interval during the data update; Here new data will appear on the dashboard every 5 seconds.
- When you click the HTTP Duration down arrow, you will get the options below. Click edit.
- Below the display table, you’ll see a query editor. The query shown in the following snapshot is currently being viewed: probe_http_duration_seconds.
- There are hundreds of queries that you can easily view and add to your dashboard as needed.
- You also have many options to change the display style. The average poll duration is available on the dashboard in text format. In the panel shown on the right, click extent option for average polling time.
- And this is how the visualization will change.
Conclusion
The above is just to give you an idea of how easy it is to monitor a website using Prometheus Blackbox and Grafana. There are many options and I recommend giving it a try to experiment. If you want to learn Grafana, take a look at their online course.
Let the article source
How to Monitor Website Performance with Blackbox Exporter and Grafana? of website
Categories: How to