Hello, dev.to community! ?
In this post, I’ll walk you through the steps I took to set up the MariaDB/MySQL Exporter on Galera Cluster nodes for monitoring with Prometheus. In my case, I’m running a MariaDB Galera Cluster on my cloud server provider with three nodes and using Prometheus Grafana to monitor my setup. The Galera Cluster setup and monitoring tools have been incredibly useful, but getting the right metrics from MariaDB wasn’t straightforward, so I decided to document my solution.
To monitor MariaDB and Galera Cluster metrics such as the number of queries per second, connections, replication status, etc., you need to use a MySQL Exporter in combination with Prometheus. This exporter will expose database-specific metrics, including Galera and MariaDB statistics.
Steps to Set Up MariaDB/MySQL Exporter on Galera Cluster Nodes:
Note: You can use already Prometheus Grafana's machins on marketplace of your cloud server provider. Hetzner, Digitalocean
On each Galera node, we need to install the MySQL Exporter, which collects metrics and exposes them for Prometheus. Here’s how you can do that:
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
tar xvfz mysqld_exporter-0.15.1.linux-amd64.tar.gz
sudo cp mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter /usr/local/bin/
sudo useradd -rs /bin/false mysqld_exporter
The exporter needs access to the MariaDB metrics. Create a .my.cnf file in the exporter’s home directory to store the connection credentials:
sudo mkdir /etc/.mysqld_exporter
sudo nano /etc/.mysqld_exporter/.my.cnf
Add the following to the file:
[client] user=exporter password=yourpassword
Make sure the user has the proper permissions to access the necessary metrics:
to access use mysql -u root or mariadb -u root
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
FLUSH PRIVILEGES;
To ensure the MySQL Exporter starts on boot, let’s configure it as a systemd service:
sudo nano /etc/systemd/system/mysqld_exporter.service
Add the following content to the file:
[Unit] Description=Prometheus MySQL Exporter Wants=network-online.target After=network-online.target [Service] User=mysqld_exporter Group=mysqld_exporter ExecStart=/usr/local/bin/mysqld_exporter \ --config.my-cnf=/etc/.mysqld_exporter/.my.cnf [Install] WantedBy=multi-user.target
Save the file and reload systemd:
sudo systemctl daemon-reload
sudo systemctl start mysqld_exporter
sudo systemctl enable mysqld_exporter
Next, update your Prometheus configuration to scrape the metrics from the nodes. Add the following to your prometheus.yml file:
Before that you can check if MySQL Exporter is running by visiting:
curl http://
to access this file for example prometheus.yml use:
sudo nano /opt/containers/prometheus-grafana/prometheus/prometheus.yml
Add inside scrape_configs::
- job_name: 'mariadb-galera' static_configs: - targets: ['node1-ip:9104', 'node2-ip:9104', 'node3-ip:9104']
replease you ip of your database nodes
Then, reload Prometheus:
sudo systemctl reload prometheus
If you’re using Grafana, you can import pre-built dashboards for MySQL/MariaDB monitoring. One popular dashboard ID for MySQL/MariaDB metrics is 7362.
To import:
You should now see detailed metrics from your MariaDB Galera Cluster nodes in your Grafana dashboards!
With the MariaDB Exporter set up on each Galera Cluster node, Prometheus can now scrape and monitor key database metrics. This setup provides better insight into your cluster’s health and performance, making it easier to troubleshoot and optimize as needed.
Feel free to leave any questions or comments below if you're setting up something similar or have any suggestions. Thanks for reading!
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3