<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ali Ghaemi</title>
    <description>The latest articles on DEV Community by Ali Ghaemi (@alighaemia).</description>
    <link>https://dev.to/alighaemia</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2172882%2Fec565089-6348-423f-9882-c8e17b890824.jpg</url>
      <title>DEV Community: Ali Ghaemi</title>
      <link>https://dev.to/alighaemia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alighaemia"/>
    <language>en</language>
    <item>
      <title>How to Set Up MariaDB/MySQL Exporter on Galera Cluster Nodes for Prometheus Monitoring</title>
      <dc:creator>Ali Ghaemi</dc:creator>
      <pubDate>Sun, 06 Oct 2024 08:25:51 +0000</pubDate>
      <link>https://dev.to/alighaemia/how-to-set-up-mariadbmysql-exporter-on-galera-cluster-nodes-for-prometheus-monitoring-4b3l</link>
      <guid>https://dev.to/alighaemia/how-to-set-up-mariadbmysql-exporter-on-galera-cluster-nodes-for-prometheus-monitoring-4b3l</guid>
      <description>&lt;p&gt;Hello, dev.to community! 👋&lt;/p&gt;

&lt;p&gt;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 &lt;strong&gt;MariaDB Galera Cluster&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;To monitor MariaDB and Galera Cluster metrics such as the number of queries per second, connections, replication status, etc., you need to use a &lt;a href="https://github.com/prometheus/mysqld_exporter" rel="noopener noreferrer"&gt;MySQL Exporter&lt;/a&gt; in combination with Prometheus. This exporter will expose database-specific metrics, including Galera and MariaDB statistics.&lt;/p&gt;

&lt;p&gt;Steps to Set Up MariaDB/MySQL Exporter on Galera Cluster Nodes:&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;MariaDB Galera Cluster&lt;/strong&gt; with multiple nodes.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;Prometheus&lt;/strong&gt; server up and running.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grafana&lt;/strong&gt; for visualizing metrics (optional but recommended).&lt;/li&gt;
&lt;li&gt;Access to the nodes to install the exporter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: You can use already Prometheus Grafana's machins on marketplace of your cloud server provider. &lt;a href="https://docs.hetzner.com/cloud/apps/list/prometheus-grafana/" rel="noopener noreferrer"&gt;Hetzner&lt;/a&gt;, &lt;a href="https://marketplace.digitalocean.com/apps/prometheus" rel="noopener noreferrer"&gt;Digitalocean &lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install MySQL/MariaDB Exporter
&lt;/h3&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;h1&gt;
  
  
  Download and install the exporter from the official source
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Extract the files
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;tar xvfz mysqld_exporter-0.15.1.linux-amd64.tar.gz&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Move the binary to a system path
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;sudo cp mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter /usr/local/bin/&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Add a system user for the exporter
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;sudo useradd -rs /bin/false exporter&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Configure Exporter with MySQL/MariaDB Credentials
&lt;/h3&gt;

&lt;p&gt;The exporter needs access to the MariaDB metrics. Create a &lt;code&gt;.my.cnf&lt;/code&gt; file in the exporter’s home directory to store the connection credentials:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo mkdir /etc/.mysqld_exporter&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo nano /etc/.mysqld_exporter/.my.cnf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following to the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[client]
user=exporter
password=yourpassword
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure the user has the proper permissions to access the necessary metrics:&lt;/p&gt;

&lt;p&gt;to access use &lt;code&gt;mysql -u root&lt;/code&gt; or &lt;code&gt;mariadb -u root&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'yourpassword';&lt;/code&gt;&lt;br&gt;
&lt;code&gt;GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';&lt;/code&gt;&lt;br&gt;
&lt;code&gt;FLUSH PRIVILEGES;&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: Set Up the Exporter as a Service
&lt;/h3&gt;

&lt;p&gt;To ensure the MySQL Exporter starts on boot, let’s configure it as a systemd service:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo nano /etc/systemd/system/mysqld_exporter.service&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following content to the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the file and reload systemd:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo systemctl daemon-reload&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo systemctl start mysqld_exporter&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo systemctl enable mysqld_exporter&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 4: Add Exporter Targets to Prometheus
&lt;/h3&gt;

&lt;p&gt;Next, update your Prometheus configuration to scrape the metrics from the nodes. Add the following to your &lt;code&gt;prometheus.yml&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;Before that you can check if MySQL Exporter is running by visiting:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl http://&amp;lt;MariaDB-nodes-ip&amp;gt;:9104/metrics&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;to access this file for example &lt;code&gt;prometheus.yml&lt;/code&gt; use:&lt;br&gt;
&lt;code&gt;sudo nano /opt/containers/prometheus-grafana/prometheus/prometheus.yml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add inside &lt;code&gt;scrape_configs:&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- job_name: 'mariadb-galera'
  static_configs:
    - targets: ['node1-ip:9104', 'node2-ip:9104', 'node3-ip:9104']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replease you ip of your database nodes&lt;/p&gt;

&lt;p&gt;Then, reload Prometheus:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo systemctl reload prometheus&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Visualize in Grafana
&lt;/h3&gt;

&lt;p&gt;If you’re using Grafana, you can import pre-built dashboards for MySQL/MariaDB monitoring. One popular dashboard ID for &lt;a href="https://grafana.com/grafana/dashboards/7362-mysql-overview/" rel="noopener noreferrer"&gt;MySQL/MariaDB metrics is &lt;strong&gt;7362&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To import:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Grafana.&lt;/li&gt;
&lt;li&gt;Navigate to Dashboards &amp;gt; Import.&lt;/li&gt;
&lt;li&gt;Enter &lt;strong&gt;7362&lt;/strong&gt; in the "Grafana.com Dashboard" field, then click &lt;strong&gt;Load&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You should now see detailed metrics from your MariaDB Galera Cluster nodes in your Grafana dashboards!&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Feel free to leave any questions or comments below if you're setting up something similar or have any suggestions. Thanks for reading!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>mysql</category>
      <category>prometheus</category>
      <category>galera</category>
    </item>
    <item>
      <title>Hello World</title>
      <dc:creator>Ali Ghaemi</dc:creator>
      <pubDate>Sun, 06 Oct 2024 06:51:32 +0000</pubDate>
      <link>https://dev.to/alighaemia/hello-world-416o</link>
      <guid>https://dev.to/alighaemia/hello-world-416o</guid>
      <description>&lt;p&gt;Hello! 👋&lt;/p&gt;

&lt;p&gt;This is my very first post here, and I'm excited to start sharing my journey. I plan to document the technical challenges I encounter and the solutions I come up with. These challenges might have already been solved by others, or they might be very specific and even seem simple to some, but my goal is to create a public record of them for myself and for anyone else who might benefit.&lt;/p&gt;

&lt;p&gt;By sharing, I hope to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep track of my own learning and problem-solving.&lt;/li&gt;
&lt;li&gt;Help others who might be facing similar challenges.&lt;/li&gt;
&lt;li&gt;Get feedback and learn new approaches from the dev community.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’ll be posting about a variety of technical topics as they come up, whether it’s related to development, server setup, databases, or anything else I’m working on. Stay tuned for more updates!&lt;/p&gt;

&lt;p&gt;Thanks for reading, and I’m looking forward to being a part of this amazing community!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
