5.6. Use a Prometheus Exporter for MariaDB and MySQL databases

Prometheus Exporters are essential tools for monitoring various systems and services, providing valuable insights into their performance and health. Speedgain for Databases comes with a function to gather that performance data, stores it in its own database and offers a dashboard to analyze the values next to the Speedgain native databases.

In this guide, we’ll walk you through the process of setting up a Prometheus Exporter specifically tailored for MariaDB and MySQL databases.

5.6.1. Prerequisites

  • Access to a MariaDB or MySQL database.

  • Basic knowledge of Linux terminal commands.

  • Docker installed on your system (optional but recommended for easy setup).

5.6.2. Step 1: Installation

  1. Navigate to the official GitHub repository for the Prometheus MySQL Exporter by following this link: https://github.com/prometheus/mysqld_exporter.

  2. Follow the installation instructions provided in the repository’s README file.

  3. Ensure you have all the necessary dependencies installed as per the instructions.

5.6.3. Step 2: Configuration

  1. Once the exporter is installed, you’ll need to configure it to connect to your MariaDB or MySQL database.

  2. Edit the mysqld_exporter.cnf configuration file to specify your MariaDB or MySQL database connection details. This file typically resides in the same directory where you installed the exporter.

  3. Update the client section of the configuration file with your MariaDB or MySQL database credentials, such as user, password, host, and port.

Sample mysqld_exporter.cnf file when using the default port

[client]
user=<user>
password=<password>
host=<hostname>

5.6.4. Step 3: Running the Exporter

  1. Start the Prometheus MySQL Exporter by executing the following command in your terminal:

./mysqld_exporter --config.my-cnf=/path/to/mysqld_exporter.cnf

Replace /path/to/mysqld_exporter.cnf with the path to your MariaDB or MySQL configuration file.

Alternatively, if you’re using Docker, you can run the exporter in a container:

docker network create my-mysql-network
docker pull prom/mysqld-exporter
docker run -d -p 9104:9104 -v </path/to/mysqld_exporter.cnf>:/opt/mysqld_exporter.cnf --network my-mysql-network --name mysqld-exporter prom/mysqld-exporter --config.my-cnf=/opt/mysqld_exporter.cnf

5.6.5. Step 4: Verify Exporter Metrics

  1. Once the exporter is running, open a web browser and navigate to http://localhost:9104/metrics.

  2. You should see a page displaying various metrics related to your MariaDB or MySQL database.

  3. Verify that the metrics are being collected correctly.

5.6.6. Step 5: Setting Up a Remote Node in the Speedgain Configuration

  1. Access the Speedgain configuration interface, using your admin credentials, and navigate to the Nodes tab.

  2. Click on the "+" symbol located at the bottom left corner to create a new remote node if necessary.

  3. Provide an appropriate display name and input the hostname or IP address of the server where the Prometheus Exporter is running. Optionally, configure additional fields. For the port meant for OS monitoring, set it to 22. Select the operating system type for the remote system.

  4. Save the configuration.

5.6.7. Step 6: Setting Up a Database in the Speedgain Configuration

  1. In the Speedgain configuration interface, go to the databases tab.

  2. Click on the "+" symbol at the bottom left to create a new database configuration.

  3. Initially, select the DBMS MariaDB to narrow down the configuration options.

  4. Choose the remote node created in Step 5.

  5. Enter "metrics" in the metrics path and the port you configured for the Prometheus Exporter (default is 9104).

  6. No need to input login or SSL information.

  7. Provide an appropriate display name.

  8. Select the monitoring policy "policy_maria_mysql".

  9. If you want to initiate monitoring immediately, check the enabled checkbox.

  10. Save the configuration.

5.6.8. Step 7: Start Analyzing Your Database

  1. Navigate to the Speedgain start page by clicking on the header link "ITGAIN Speedgain for Databases".

  2. Click on "Overview Dashboards" located in the top right corner.

  3. Select "MySQL MariaDB - Overview" from the options.

  4. Begin analyzing your database. Please note that it may take a few minutes until the performance data becomes available.