Monitoring a MariaDB server using Prometheus and Grafana

Sameer Naik
Jun 22, 2017 · 4 min read

Prometheus is a systems and services monitoring system originally developed at SoundCloud and now a Cloud Native Computing Foundation project.

In this post we’ll outline the process of adding a Prometheus metrics endpoint to an existing chart, MariaDB chart in our case, and use Grafana to monitor the charts performance. We will do this by adding a Prometheus exporter to our Kubernetes Pods defined in the Helm chart template.

Lets begin by installing the prerequisites…

Installing the prerequisites

We’ll quickly walk through the steps of installing and configuring Prometheus and Grafana on a Kubernetes cluster using Helm charts.

Install a Ingress controller

$ helm install --name ingress stable/nginx-ingress

Note: minikube users can enable the ingress addon using the command

Install Prometheus

$ helm install --name prometheus stable/prometheus

Install Grafana

$ helm install --name grafana stable/grafana \
--set server.adminPassword=password,server.ingress.enabled=true,server.ingress.hosts={grafana.example.com}

The above command configures as the ingress hostname, so add the line to your operating systems file, where is the external IP address of the ingress controller. Get the IP address using the command:

$ kubectl get services \
-l release=ingress,component=controller \
-o jsonpath="{ .items[0].status.loadBalancer.ingress[0].ip }"

Note: minikube users should use the IP address of the minikube VM. Get the IP address of the minikube VM using the command

Login to http://grafana.example.com using the credentials and add Prometheus as a data source by navigating to the Add data source dialog in Grafana and specifing the data source Name as , Type as and the Url as as shown in the screenshot below.

In the Dashboards tab of the dialog you can import the Prometheus Stats dashboard to view the statistics of the Prometheus server.

Adding Prometheus metrics endpoint to MariaDB

We’ll use the MariaDB chart from the official charts repository to install MariaDB to our cluster. At the time of writing, the chart does not expose a metrics endpoint for Prometheus.

Note: Pull request #1330 has been merged, The changes described below are not required for MariaDB chart versions ≥ . You can simply enable the metrics endpoint by specifying while deploying the chart.

We’ll use the docker image which creates a Prometheus exporter for MariaDB server metrics and launch it as a sidecar container in the MariaDB pod deployment. We’ll define port as a container port since creates the metrics endpoint on this port.

Edit the file of the chart and add the following definition to launch the metrics container.

- name: metrics
image: "prom/mysqld-exporter:v0.10.0"
imagePullPolicy: "IfNotPresent"
env:
- name: DATA_SOURCE_NAME
value: "root:{{ .Values.mariadbRootPassword }}@(localhost:3306)/"
ports:
- name: metrics
containerPort: 9104

For Prometheus to discover the endpoint exposed by the MariaDB deployment, edit the and add the following annotations to the resource.

annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9104"

With these changes in place, deploy the MariaDB Chart using the command:

$ helm install --name mariadb stable/mariadb/

The MariaDB chart will be deployed and you should notice that the pod now consists of two containers.

# kubectl  get pods -l app=mariadb-mariadb
NAME READY STATUS RESTARTS AGE
mariadb-mariadb-4198203111-rg9w8 2/2 Running 0 10m

Note: A , created against chart version , is available in the GitHub Gist ede014d7a36912b4ac57050a64509ff2

Adding a dashboard

We’ll install a Grafana dashboard to visualize and monitor the MariaDB server metrics. The percona/grafana-dashboards repository on GitHub contains a collection of Grafana dashboards for MySQL/MariaDB monitoring using Prometheus.

For an overview of the MariaDB server metrics, we’ll use the MySQL Overview dashboard. Download the dashboard JSON and import it into Grafana from the Dashboards > Import menu option.

Finally, load the MySQL Overview dashboard to monitor the MariaDB server metrics.

Tip: To view the statistics of each node in the cluster add the Node Exporter Full dashboard and specify as the data source in the Import dialog

Conclusion

We can easily add Prometheus metrics endpoints to Helm charts and with Prometheus and Grafana we can just as easily monitor the performance of the charts deployed in the cluster.

Visit the Exporter and Integrations page to check if a metrics exporter exists for your favourite application.

Bitnami Perspectives

Loved by devs, Trusted by ops: Bitnami makes easy to use…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store