Skip to content

Instantly share code, notes, and snippets.

Last active Sep 13, 2022
What would you like to do?
How to set up the Percona Monitoring and Management (PMM) v2 with docker-compose

Set up PMM Server v2

Let's start by creating entry for server in docker-compose.yaml:

version: '2'
# version 2 of docker-compose is not "old" version, it's the actual version,
# see below for explanation:
    # Percona Monitoring and Management server
        image: percona/pmm-server:2
        container_name: pmm-data
        hostname: pmm-data
            - /srv
        entrypoint: /bin/true

        image: percona/pmm-server:2
        hostname: pmm-server
        container_name: pmm-server
        restart: always

        # logging settings limit used disk space
            driver: json-file
                max-size: "10m"
                max-file: "5"

            - "443:443"
        # uncomment expose section in order to proxy requests through another container instead of
        # accessing the container directly
        # expose:
        #     - "443"

            - pmm-data

After that, you could do docker compose up -d pmm-server and access it on with login credentials admin:admin

Change the password and create new user reporter with Admin rights to use it for client setup on the next step.

Set up PMM Client v2

Set up a connection to a server

No instructions for docker installation of client v2 are available at the moment, so deb install guide was used as a starting point for that guide.

First, create file pmm-agent.yaml with mode 0666 so container user will be able to write to it: touch pmm-agent.yaml && chmod 0666 pmm-agent.yaml

Then make sure your docker-compose.yaml has the following content:

version: '2'
    # Percona Monitoring and Management client
        image: perconalab/pmm-client:2
        # select unique hostname, as it will be used for reporting
        hostname: pmm-client-my-cool-mysql-for-blog
        container_name: pmm-client
        # depends_on section is needed if you're monitoring DB that is running in the docker-compose
            - mysql-server
        # pmm-agent.yaml will contain credentials and should not be added to git or shared with anyone
            - ./pmm-agent.yaml:/etc/pmm-agent.yaml

        # uncomment the ports section in case your pmm-server is on another host,
        # to see full list of ports you need to expose please see `docker-compose logs pmm-client`
        # after start of the container for lines like that:
        # > Sending status: RUNNING (port 42000). <...>
        # > Sending status: RUNNING (port 42001). <...>
        # ports:
        #     - "42000:42000"
        #     - "42001:42001"

            driver: json-file
                max-size: "10m"
                max-file: "5"

        restart: always
            - PMM_AGENT_CONFIG_FILE=/etc/pmm-agent.yaml

Before starting the container we need to generate a configuration for it by connecting to the server for the first time. For that temporary add entrypoint section with the following text in it, replacing pass with the password of the reporter user you created on the previous step.

        # important, if pmm-server is on different host you have to access it directly,
        # accessing it trough proxy like nginx wouldn't work
        entrypoint: pmm-agent setup --server-insecure-tls --server-address=pmm-server:443 --server-username=reporter --server-password='pass'

After that run docker-compose up pmm-client once, check that output doesn't contain errors, and then erase the entrypoint section you just added. Expected output:

Registering pmm-agent on PMM Server...
Configuration file /etc/pmm-agent.yaml updated.
Please start pmm-agent: `pmm-agent --config-file=/etc/pmm-agent.yaml`.

Here the initial setup is done, docker-compose up -d pmm-client will start the client with the new settings and it should start reporting itself in the PMM Server interface. It won't send any DB data yet, for that to work you need to set up each DB you want to monitor from this machine (with that client) once.

Sidenote, in case you are running pmm-client on another host than pmm-server, after the configuration file is created to make it work via external IP run docker exec pmm-client /usr/local/percona/pmm2/bin/pmm-admin config external_ip container pmm-client-my-cool-mysql-for-blog with pmm-client name different than one used above to make server use IP you provide instead of an internal one, and remove the old instance from pmm-server GUI afterwards.

Set up connection to MySQL

First, we need to prepare the DB. Requirements section in the official documentation has the details, here is what you need to do:

The second step is creating a MySQL user. For that in the MySQL run following, replacing pass with randomly generated password (for example by running docker exec -it mysql-server mysql -u root -p):

-- @'%' and not @'localhost' because in docker client would be connecting not from the localhost
-- if you want, use '' ( to restrict logging to the docker network
-- if you don't use docker, just stick to 'localhost'

The last step is to register the DB from the client on the server: execute docker exec -it pmm-client /bin/bash to get a shell in the client container, and then run the following command inside:

pmm-admin add mysql --username=pmm --password 'pass' --host mysql-server  --query-source=perfschema
# in case you're monitoring local DB and want to connect by socket, use that instead:
# pmm-admin add mysql --username=pmm --password 'pass' --socket=/var/path/to/mysql/socket --query-source=perfschema


This work is distributed by CC-BY-4.0 license, feel free to alter it in a fork and ping me to update it with your changes.

Copy link

spartan commented Dec 1, 2021

With this setup after a docker-compose down followed by docker-compose up -d I cannot login into pmm-server anymore using the previous user/pass credentials.
I removed the entrypoint on pmm-data after the first docker-compose up -d but for some reason after restart everything is still lost.
There is no info online on how to setup pmm correctly using docker-compose. Yours was the closest I could get. Any thoughts on fixing this issue ?

Copy link

fotrimzi commented Dec 2, 2021

Try asking on

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