Would you like to learn how to perform a Prometheus monitoring MySQL configuration on Ubuntu Linux? In this tutorial, we are going to show you how to install Prometheus on Ubuntu Linux, how to configure Prometheus to monitor a MySQL server using the mysqld_exporter application and how to access your Prometheus web administration interface.

• Ubuntu version: 18.04
• Prometheus version: 2.8.0
• Prometheus mysqld_exporter version: 0.11.0

In our example, the MySQL server uses the IP address 200.200.200.200.

In our example, the Prometheus  server uses the IP address 34.216.84.149.

Keep in mind that you need to change the commands and configuration files to reflect your environment.

What is Prometheus?

Prometheus is an open-source monitoring platform that is able to collect metrics from monitored targets by scraping metrics.

After saving the collected data, a network administrator is able to query it using its query language and render all the results into graphs.

Prometheus comes with a web server that allows it to be accessed from anywhere.

Prometheus Tutorial:

On this page, we offer quick access to a list of Prometheus tutorials.

Tutorial – Prometheus mysqld_exporter Installation

These tasks should be performed on the computer that is running the MySQL Server.

On the Linux console, create an account to the mysqld_exporter application.

# groupadd –system mysqld_exporter
# useradd -s /bin/false -r -g mysqld_exporter mysqld_exporter

Access the MySQL server console:

# mysql -u root -p

Create a MySQL user account to the mysqld_exporter application.

CREATE USER ‘mysqld_exporter’@’localhost’ IDENTIFIED BY ‘kamisama123’ WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO ‘mysqld_exporter’@’localhost’;
quit;

In our example, we configured the password kamisama123 to the mysqld_export user account.

Perform the download and installation of the Prometheus MySQL exporter application.

# mkdir /downlaods/mysql_exporter -p
# cd /downlaods/mysql_exporter
# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz
# tar -zxvf mysqld_exporter-0.11.0.linux-amd64.tar.gz
# install mysqld_exporter-0.11.0.linux-amd64/mysqld_exporter /usr/local/bin/

Create a file containing the mysqld_exporter credentials for MySQL.

# vi /etc/.my.cnf

Here is the content of the .my.cnf file.

[client]

user=mysqld_exporter
password=kamisama123

Set the correct .my.cnf file permission.

Create an automatic startup script to the Prometheus mysqld_exporter service.

# chown root:mysqld_exporter /etc/.my.cnf
# vim /etc/systemd/system/mysqld_exporter.service

Here is the content of the mysqld_exporter.service file.

Copy

Enable and start the MySQL_Exporterd service.

# systemctl daemon-reload
# systemctl enable mysqld_exporter
# systemctl start mysqld_exporter

Congratulations! You have successfully installed the Prometheus mysqld_exporter service.

Tutorial – Prometheus Install

These tasks should be performed on the computer that will become the Prometheus server.

On the Linux console, create a Prometheus user account.

# groupadd –system prometheus
# useradd -s /bin/false -r -g prometheus prometheus

Create the Prometheus required directories.

# mkdir /etc/prometheus
# mkdir /var/lib/prometheus

Perform the Prometheus download.

# mkdir /downloads/prometheus -p
# cd /downloads/prometheus
# wget https://github.com/prometheus/prometheus/releases/download/v2.8.0/prometheus-2.8.0.linux-amd64.tar.gz

Extract and Install Prometheus monitoring package.

# tar -zxvf prometheus-2.8.0.linux-amd64.tar.gz
# cd prometheus-2.8.0.linux-amd64/
# install prometheus /usr/local/bin/
# install promtool /usr/local/bin/
# mv consoles /etc/prometheus/
# mv console_libraries /etc/prometheus/

Create a Prometheus configuration file.

# cd /etc/prometheus
# vi prometheus.yml

Here is the Prometheus.yml file content.

Copy

In our example, we are assuming that the MySQL server IP address is 200.200.200.200.

Keep in mind that you need to change the MySQL server IP address to reflect your environment.

Set the correct permission on Prometheus installation files.

# chown prometheus:prometheus /usr/local/bin/prometheus
# chown prometheus:prometheus /usr/local/bin/promtool
# chown prometheus:prometheus /var/lib/prometheus -R
# chown prometheus:prometheus /etc/prometheus -R
# chmod -R 775 /etc/prometheus/ /var/lib/prometheus/

Use the following command to start Prometheus manually.

# prometheus –config.file /etc/prometheus/prometheus.yml –storage.tsdb.path /var/lib/prometheus/ –web.console.templates=/etc/prometheus/consoles –web.console.libraries=/etc/prometheus/console_libraries

Prometheus Startup Script.

Create a Prometheus startup script.

# vi /etc/systemd/system/prometheus.service

Here is the content of the prometheus.service file.

Copy

Enable the Prometheus service to start during the computer boot.

# chown prometheus:prometheus /var/lib/prometheus -R
# chmod 775 /var/lib/prometheus -R
# systemctl daemon-reload
# systemctl enable prometheus
# systemctl start prometheus

Prometheus Dashboard Access

Open your browser and enter the IP address of your server plus :9090

In our example, the following URL was entered in the Browser:

• http://34.216.84.149:9090

The Prometheus web interface should be presented.

On the Prometheus query textbox, enter the string mysql to test the communication with mysqld_exporter.

prometheus dashboard

Congratulation! You have successfully performed a Prometheus installation on Ubuntu Linux.