Skip to content

Instantly share code, notes, and snippets.

@linuxmalaysia
Last active December 19, 2023 04:23
Show Gist options
  • Save linuxmalaysia/9cc7a8762e6161b976853c28cc72cab1 to your computer and use it in GitHub Desktop.
Save linuxmalaysia/9cc7a8762e6161b976853c28cc72cab1 to your computer and use it in GitHub Desktop.
Percona Monitoring and Management (PMM) is an open-source database monitoring, management, and observability solution for MySQL, PostgreSQL, and MongoDB in podman

Percona Monitoring and Management (PMM) is an open-source database monitoring, management, and observability solution for MySQL, PostgreSQL, and MongoDB.

1) MariaDB enable Performance Schema

Performance Schema Overview

Add the following to my.cnf all MariaDB nodes:

performance_schema=ON
query_response_time_stats=ON
userstat=ON
# Uncomment the following lines if needed
# performance-schema-instrument='stage/%=ON'
# performance-schema-consumer-events-stages-current=ON
# performance-schema-consumer-events-stages-history=ON
# performance-schema-consumer-events-stages-history-long=ON

Restart MariaDB:

systemctl restart mariadb

Percona Monitoring and Management - MySQL Client

Install the plugins using the MySQL/MariaDB prompt:

-- For MariaDB 10.3:
INSTALL PLUGIN QUERY_RESPONSE_TIME_AUDIT SONAME 'query_response_time.so';
INSTALL PLUGIN QUERY_RESPONSE_TIME SONAME 'query_response_time.so';
SET GLOBAL query_response_time_stats = ON;

2) Install Podman For AlmaLinux / Ubuntu

Podman Installation Guide

Update and install necessary packages for AlmaLinux:

dnf update
dnf -y install epel-release
dnf -y install podman buildah

Verify the installation:

podman --version
buildah --version

Configure Red Hat's registry:

vi /etc/containers/registries.conf

Uncomment the following lines:

[registries.insecure]
registries = ['docker.io']
insecure = true

For Ubuntu:

apt update
apt install podman buildah

3) Rootless Podman

Rootless Podman Tutorial

Install slirp4netns:

apt install slirp4netns

Set up non-root user:

usermod --add-subuids 100000-165535 --add-subgids 100000-165535 your-username
grep your-username /etc/subuid /etc/subgid
podman system migrate

4) Running PMM with Podman (Using Docker tutorial)

PMM Docker Setup

podman pull percona/pmm-server:latest
podman run --detach --privileged --restart always \
--publish 5443:443 \
-v pmm-data:/srv \
--name pmm-server \
-v /etc/localtime:/etc/localtime:ro \
percona/pmm-server:latest

Change password:

podman exec -t pmm-server change-admin-password ChangeYour0wnP455word

Percona Monitoring and Management - Client

Web access https://192.168.0.148:5443

5) For the host to be monitored (MariaDB Nodes)

AlmaLinux

dnf install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm
dnf install -y pmm2-client
pmm-admin --version

Debian/Ubuntu

wget https://repo.percona.com/apt/percona-release_latest.generic_all.deb
dpkg -i percona-release_latest.generic_all.deb
apt update
apt install -y pmm2-client
pmm-admin --version

6) Register the MariaDB nodes to PMM server

(IP 192.168.0.148 with the name pmm-server as an example, and request to open the port in the firewall)

PMM_SERVER=192.168.0.148:5443
pmm-admin config --server-insecure-tls --server-url=https://admin:ChangeYour0wnP455word@$PMM_SERVER
systemctl enable pmm-agent --now

7) Create user.

Ensure all nodes, PMM, and MariaDB nodes in /etc/hosts have the IP and names of all servers, PMM, and MariaDB nodes.

-- Replace 'ChangeYour0wnP566word' with the desired password
CREATE USER 'pmm'@'127.0.0.1' IDENTIFIED BY 'ChangeYour0wnP566word' WITH MAX_USER_CONNECTIONS 10;
GRANT SELECT, PROCESS, REPLICATION CLIENT, RELOAD ON *.* TO 'pmm'@'127.0.0.1';

CREATE USER 'pmm'@'pmm-server' IDENTIFIED BY 'ChangeYour0wnP566word' WITH MAX_USER_CONNECTIONS 10;
GRANT SELECT, PROCESS, REPLICATION CLIENT, RELOAD ON *.* TO 'pmm'@'pmm-server';

CREATE USER 'pmm'@'192.68.0.148' IDENTIFIED BY 'ChangeYour0wnP566word' WITH MAX_USER_CONNECTIONS 10;
GRANT SELECT, PROCESS, REPLICATION CLIENT, RELOAD ON *.* TO 'pmm'@'192.168.0.148';

8) Register the MariaDB nodes to PMM to get MariaDB Performance information

pmm-admin add mysql --username=pmm --password=pass --query-source=perfschema

9) Check the service

Web access https://192.168.0.148:5443

PMM web interface

  • Select Configuration
  • Inventory.
    • In the Services tab, verify the Service name, Addresses, and any other relevant information in the form.
    • In the Options column, expand the Details section and check that the Agents are using the desired data source.

Command line

Look for your service in the output of this command:

pmm-admin inventory list services --service-type=mysql

Check data

  • Open the MySQL Instance Summary dashboard.
  • Set the Service Name to the newly-added service.

Percona Server for MySQL, MariaDB

If the query response time plugin was installed, check for data in the MySQL Query Response Time Details dashboard or select a query in PMM Query Analytics to see the Query time distribution bar.

WhatsApp Image 2023-12-08 at 07 18 39_c6577862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment