Are you tired of manually monitoring your local databases? Do you want an easy and quick solution to monitor your Dockerized databases? In this article, we will guide you through the process of setting up Percona Monitoring and Management (PMM) with Docker to monitor your local Dockerized databases.
First things first, we need to create a Docker network for monitoring:
docker network create monitorization_pmm_local
Next, we will define a minimal Docker Compose file to start the PMM service:
version: '3.7'
services:
pmm-server:
image: percona/pmm-server:2
hostname: pmm-server
container_name: pmm-server
restart: always
logging:
driver: json-file
options:
max-size: "10m"
max-file: "5"
ports:
- "443:443"
Start the PMM service with the following command:
docker-compose up -d
Once the PMM container is up and running, we can access the PMM web-admin interface by visiting https://localhost:443/graph. The initial credentials are admin
/admin
, and you will be prompted to change the password upon the first login. For this example, we will keep the password unchanged.
Connect the PMM container to the monitorization_pmm_local
network:
docker network connect monitorization_pmm_local pmm-server
Now it's time to set up monitoring for our Dockerized databases. Let's try with MySQL:
version: "3.7"
services:
mysql:
container_name: mysql-playground
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
ports:
- 3306:3306
environment:
MYSQL_DATABASE: playground
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: test
MYSQL_PASSWORD: test
Connect the MySQL container to the monitorization_pmm_local
network:
docker network connect monitorization_pmm_local mysql-playground
Identify the IP address of the MySQL container within the Docker network:
docker network inspect monitorization_pmm_local
In this example, we will assume that the IP address of the MySQL container is 192.168.240.3
and the IP address of the PMM container is 192.168.240.2
.
Create a user for PMM to use to monitor the MySQL container:
docker exec -it mysql-playground mysql -uroot -proot
mysql> CREATE USER 'pmm'@'192.168.240.2' IDENTIFIED BY 'pmmpassword' WITH MAX_USER_CONNECTIONS 10;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'pmm'@'192.168.240.2' WITH GRANT OPTION;
Note that we are creating a user with the name pmm
and granting it all privileges on all databases. You can check the user's privileges with the following command:
mysql> show grants for 'pmm'@'192.168.240.2';
+-----------------------------------------------------------------------------------+
| Grants for [email protected] |
+-----------------------------------------------------------------------------------+
| GRANT SELECT, RELOAD, PROCESS, REPLICATION CLIENT ON *.* TO `pmm`@`192.168.240.2` |
| GRANT BACKUP_ADMIN ON *.* TO `pmm`@`192.168.240.2` |
+-----------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Finally, register the MySQL container with PMM using the following command:
docker exec -i pmm-server pmm-admin add mysql --username=pmm --password=pmmpassword --query-source=perfschema --server-url=https://admin:[email protected]:443 --server-insecure-tls --host 192.168.240.3 --port 3306 --service-name mysql-playground-pmm
And that's it! You can now monitor your Dockerized MySQL container using PMM, and adapt this process for any other Dockerized databases you want to monitor like PostgreSQL or MongoDB.
In conclusion, with just a few commands, we were able to set up PMM with Docker to monitor our local databases.
This is a quick and easy solution for anyone who wants to monitor their Dockerized databases.