You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

In this guide, we’ll look at Monitoring MySQL and MongoDB servers with Prometheus and Grafana. This is part of our monitoring series guides. We’ve already covered:

Monitor Linux System with Grafana and Telegraf

Monitoring Ceph Cluster with Prometheus and Grafana

For the setup guides, you can refer to below articles:

Install Grafana and InfluxDB on CentOS 7

Install Prometheus Server on CentOS 7

Grafana behind Nginx and Apache Proxy

This guide is not directly related to above since we’re going to use a readily packaged Prometheus server and exporters for Linux, MySQL and MongoDB metrics (PMM server and PMM client)

What is PMM?

Percona Monitoring and Management (PMM) is an open-source platform developed by Percona for managing and monitoring MySQL and MongoDB performance. You can install PMM server in your Infrastructure and be start collecting metrics from pmm-client and visualize them on Grafana.

PMM provides thorough time-based analysis for MySQL and MongoDB servers to ensure that your data works as efficiently as possible.

PMM system diagram

Below is a PMM system architecture obtained from Percona web site

The PMM server comes with:

  • Prometheus server
  • Grafana server
  • Consul API and Web UI
  • QAN API and App for Analytics

The PMM client  is bundled with:

  • Prometheus  node_exporter
  • Prometheus mysql_exporter
  • Prometheus mongodb_exporter
  • Prometheus proxysql_exporter
  • pmm-mysql and pmm-mongodb queries

Installing PMM Server

There are various ways of running PMM server on your server.

  • Using docker
  • Using ready OVA which can be imported to VMware VirtualBox or VMware Infrastructure
  • On AWS using a ready AMI (Amazon Machine Image).

I prefer installing PMM server using Docker. The process is straightforward and doesn’t require any special environment/prerequisites since you can run it on any Linux Distribution.

Step 1: Install Docker Engine

You need to start by installing Docker Engine on your machine, we have a well-written guide on How to Install Docker on Linux.

Step 2: Download PMM server docker image

Let’s download docker image that we’ll use to create our pmm server container.

#  docker pull percona/pmm-server:latest

This may take a while depending on your internet speed,

Step 3: Create pmm data container

To make our data persistent, we’re going to create a container to use as data store:

# docker create \
 -v /opt/prometheus/data \
 -v /opt/consul-data \
 -v /var/lib/mysql \
 -v /var/lib/grafana \
 --name pmm-data \
 percona/pmm-server:latest /bin/true


Note that this container is not to be started, we just need to make it exist. Do not remove or re-create this container, unless you intend to wipe out all PMM data and start over.

Step 3: Create PMM server container

Once you have pmm data container created, you can create PMM server container. For this, We’re going to create a systemd service unit file, this will make it easy to manage the container. You can use docker-compose if you like.

[pastacode lang=”bash” manual=”%23%20cat%20%2Fetc%2Fsystemd%2Fsystem%2Fpmm-server.service%20%0A%0A%5BService%5D%0ARestart%3Dalways%0ATimeoutStartSec%3D0%0AExecStartPre%3D-%2Fusr%2Fbin%2Fdocker%20kill%20pmm-server%0AExecStartPre%3D-%2Fusr%2Fbin%2Fdocker%20rm%20pmm-server%0A%0AExecStart%3D%2Fusr%2Fbin%2Fdocker%20run%20%5C%0A%20–name%20pmm-server%20%5C%0A%20–volumes-from%20pmm-data%20%5C%0A%20–name%20pmm-server%20%5C%0A%20–restart%20always%20%5C%0A%20-p%3D8080%3A80%20%5C%0A%20percona%2Fpmm-server%0A%0AExecStop%3D-%2Fusr%2Fbin%2Fdocker%20kill%20pmm-server%0AExecStop%3D-%2Fusr%2Fbin%2Fdocker%20rm%20pmm-server%0A” message=”” highlight=”” provider=”manual”/]

This will start container with the name pmm-server whose volume is pmm-data. Make sure the name of volume container matches the one you created. Start the service with systemctl command if you’re running this on a systemd init system.

#  systemctl start pmm-server

You can enable the service to start on boot using:

# systemctl enable pmm-server

Since we have  -p=8080:80, the service will be accessible from port 8080 on the host system. If you have firewall service, ensure the port is open. I have firewalld enabled:

# firewall-cmd --add-port=8080/tcp --permanent
# firewall-cmd --reload

You can  check if PMM Server is available requesting the /ping URL as in the following example:

$ curl
{'version': '1.8.0'}

Access Grafana dashboard using: http://serverip:8080 . You should get an interface like this:

Step 4: Install PMM client on MySQL server.

Percona provides PMM Client packages through software repositories of popular Linux distributions. The client collects metrics from the server to be used by Prometheus for monitoring. Add Percona repositories:

For Ubuntu/Debian:

$ wget$(lsb_release -sc)_all.deb
$ sudo dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb
$ sudo apt-get update
$ sudo apt-get install pmm-client

For CentOS/RedHat

$ sudo yum install
$ sudo yum -y install pmm-client

Step 5: Connecting PMM Clients to the PMM Server

With your server and clients set up, you need to establish connection from clients to the server by specifying the IP address of the server as a parameter to the pmm-admin config –server command.

[pastacode lang=”bash” manual=”%23%20pmm-admin%20config%20–server%20192.168.18.10%3A8080%0AOK%2C%20PMM%20server%20is%20alive.%0A%0APMM%20Server%20%20%20%20%20%20%7C%20192.168.18.10%3A8080%20%0AClient%20Name%20%20%20%20%20%7C%20ubuntu1604.localdomain%0AClient%20Address%20%20%7C%20192.168.18.12%20%0A” message=”” highlight=”” provider=”manual”/]

Replace with your PMM server IP address. To enable general system metrics, MySQL metrics, as well as MySQL query analytics, run pmm-admin add as follows.

[pastacode lang=”bash” manual=”%23%20pmm-admin%20add%20mysql%20–user%20root%20–password%20password%20%20%20%20%20%0A%5Blinux%3Ametrics%5D%20OK%2C%20now%20monitoring%20this%20system.%0A%5Bmysql%3Ametrics%5D%20OK%2C%20now%20monitoring%20MySQL%20metrics%20using%20DSN%20root%3A***%40unix(%2Fvar%2Frun%2Fmysqld%2Fmysqld.sock)%0A%5Bmysql%3Aqueries%5D%20OK%2C%20now%20monitoring%20MySQL%20queries%20from%20slowlog%20using%20DSN%20root%3A***%40unix(%2Fvar%2Frun%2Fmysqld%2Fmysqld.sock)” message=”” highlight=”” provider=”manual”/]

To enable general system metrics, MongoDB metrics, and MongoDB query analytics, run:

$ sudo pmm-admin add mongodb

To enable ProxySQL performance metrics, run:

$ sudo pmm-admin add proxysql:metrics

To see what is being monitored, run:

[pastacode lang=”bash” manual=”%23%20sudo%20pmm-admin%20list%0Apmm-admin%201.10.0%0A%0APMM%20Server%20%20%20%20%20%20%7C%20192.168.18.10%3A8080%20%0AClient%20Name%20%20%20%20%20%7C%20ubuntu1604.localdomain%0AClient%20Address%20%20%7C%20192.168.18.12%20%0AService%20Manager%20%7C%20linux-systemd%0A%0A————–%20———————–%20———–%20——–%20——————————————-%20——————————————%0ASERVICE%20TYPE%20%20%20NAME%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20LOCAL%20PORT%20%20RUNNING%20%20DATA%20SOURCE%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20OPTIONS%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A————–%20———————–%20———–%20——–%20——————————————-%20——————————————%0Amysql%3Aqueries%20%20ubuntu1604.localdomain%20%20-%20%20%20%20%20%20%20%20%20%20%20YES%20%20%20%20%20%20root%3A***%40unix(%2Fvar%2Frun%2Fmysqld%2Fmysqld.sock)%20%20query_source%3Dslowlog%2C%20query_examples%3Dtrue%20%0Alinux%3Ametrics%20%20ubuntu1604.localdomain%20%2042000%20%20%20%20%20%20%20YES%20%20%20%20%20%20-%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0Amysql%3Ametrics%20%20ubuntu1604.localdomain%20%2042002%20%20%20%20%20%20%20YES%20%20%20%20%20%20root%3A***%40unix(%2Fvar%2Frun%2Fmysqld%2Fmysqld.sock)%20%20″ message=”” highlight=”” provider=”manual”/]

For more information about the available commands of pmm-admin add, run:

# pmm-admin add --help

Visit your grafana UI to view various MySQL stats, for example, the overview looks like below:

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF