Install PMM 3 using Docker-compose and connect MySQL, Postgres, MongoDB

Hi, the PMM 3.0 GA release was published today and I immediately decided to try to install and explore it.

Unfortunately, it didn’t work for me to just change the version of the Docker image from 2 to 3.
Below I will explain step by step what I did and provide the docker-compose files

  1. (Optional) WatchTower is required to install PMM Server in Docker. (link)

Several environment variables have been added to the docker configuration for pmm-server, such as:
PMM_WATCHTOWER_HOST
PMM_WATCHTOWER_TOKEN

Anyway, ChatGPT helped me, I just generated a Token and used the watchtower service name as host. (correct me if I’m wrong, but it works)

Token generation command

➜  : openssl rand -base64 32

YdpNf+Oyj8lz3ACRafmcL6ycVWw=
  1. I provide you now with a docker-compose file that contains a working configuration of c watchtower, pmm-server, pmm-client.

This also includes MySQL, Postgres, MongoDB. You can remove it if you don’t need it.

version: '3.8'

networks:
  pmm_default:

services:
  watchtower:
    image: percona/watchtower
    container_name: watchtower
    hostname: watchtower
    environment:
      - WATCHTOWER_HTTP_API_UPDATE=1
      - WATCHTOWER_HTTP_API_TOKEN=YdpNf+Oyj8lz3ACRafmcL6ycVWw=
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - pmm_default

  pmm-server:
    image: percona/pmm-server:3
    platform: "linux/amd64"
    container_name: pmm-server
    restart: always
    ports:
      - 8080:8080
      - "443:8443"
    environment:
      - PMM_WATCHTOWER_HOST=watchtower
      - PMM_WATCHTOWER_TOKEN=YdpNf+Oyj8lz3ACRafmcL6ycVWw=
    volumes:
      - pmm-data:/srv
    networks:
      - pmm_default

  pmm-client:
    image: percona/pmm-client:3
    container_name: pmm-client
    environment:
      PMM_AGENT_SERVER_ADDRESS: pmm-server:8443
      PMM_AGENT_SERVER_USERNAME: admin
      PMM_AGENT_SERVER_PASSWORD: admin
      PMM_AGENT_SERVER_INSECURE_TLS: 1
      PMM_AGENT_CONFIG_FILE: config/pmm-agent.yaml
    volumes:
      - pmm-client-data:/srv
    networks:
      - pmm_default

  postgres:
    image: "percona/percona-distribution-postgresql:17-multi"
    environment:
      POSTGRES_PASSWORD: password
      POSTGRES_USER: postgres
      LANG: en_US.utf8
      PGDATA: /data/db
    volumes:
      - pg-data:/data/db
    ports: 
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - pmm_default

  mongodb:
    image: "percona/percona-server-mongodb:8.0-multi"
    volumes:
      - mongo-data:/data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: databaseAdmin
      MONGO_INITDB_ROOT_PASSWORD: password
    ports:
      - "27017:27017"
    healthcheck:
      test: ["CMD-SHELL", "mongosh --eval 'db.adminCommand(\"ping\")' --quiet"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - pmm_default

  mysql:
    image: "percona/percona-server:8.4.3-3.1-multi"
    volumes:
      - mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot-password"]
      interval: 5s
      timeout: 5s
      retries: 20
    ports:
      - "3306:3306"
    command: >
      --performance-schema --innodb_monitor_enable=all
      --slow_query_log --slow_query_log_file=/mysql/slowlogs/slow.log --long_query_time=0
    networks:
      - pmm_default

volumes:
  pmm-data:
  pmm-client-data:
  mongo-data:
  pg-data:
  mysql-data:
  1. Unfortunately, pmm-client didn’t start for me on the first try, so I connected to the pmm-client container and ran a few commands sequentially.
sh-5.1$ pmm-admin config --server-insecure-tls --server-url=https://admin:admin@pmm-server:8443

Checking local pmm-agent status...
pmm-agent is running.
Registering pmm-agent on PMM Server...
Registered.
Configuration file /usr/local/percona/pmm/config/pmm-agent.yaml updated.
Reloading pmm-agent configuration...
Configuration reloaded.
Checking local pmm-agent status...
pmm-agent is running.

sh-5.1$ pmm-admin add mysql --environment=test --custom-labels='source=slowlog'  --username=root --password=password --query-source=slowlog MySQLSlowLog mysql:3306
MySQL Service added.
Service ID  : b2ebe5bd-8ee7-4bdd-bc38-8efd857d53ab
Service name: MySQLSlowLog

Table statistics collection enabled (the limit is 1000, the actual table count is 346).

sh-5.1$ pmm-admin add postgresql --username=postgres --password=password --host=postgres --port=5432 --query-source=pgstatmonitor
PostgreSQL Service added.
Service ID  : 19d31ab8-6602-4c80-b2ff-ca3afec4b9ee
Service name: d2c5e45462c2-postgresql

Warning: Could not to detect the pg_stat_monitor extension on your system. Falling back to the pg_stat_statements.

sh-5.1$ pmm-admin add mongodb --username=databaseAdmin --password=password --host=mongodb --port=27017 --query-source=profiler
MongoDB Service added.
Service ID  : d4f9c4c3-64c2-4993-9dfb-cd83f029d034
Service name: d2c5e45462c2-mongodb

And it’s running

I then ran a load simulation application on MySQL, Postgres, and MongoDB so that the dashboards would not be empty. This simulated the load to fill the graphs.



1 Like

Small update, WatchTower is not required

PMM 3 will work without this service

A new docker-compose.yaml file that immediately starts PMM and PMM-Client and connects the databases to PMM.

Start:

docker-compose up -d 

Stop:

docker-compose down

docker-compose.yaml

version: '3.8'

networks:
  pmm_default:

services:
  postgres:
    image: "percona/percona-distribution-postgresql:17-multi"
    environment:
      POSTGRES_PASSWORD: password
      POSTGRES_USER: postgres
      LANG: en_US.utf8
      PGDATA: /data/db
    volumes:
      - pg-data:/data/db
    ports: 
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - pmm_default

  mysql:
    image: "percona/percona-server:8.4.3-3.1-multi"
    volumes:
      - mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot-password"]
      interval: 5s
      timeout: 5s
      retries: 20
    ports:
      - "3306:3306"
    command: >
      --performance-schema --innodb_monitor_enable=all
      --slow_query_log --slow_query_log_file=/mysql/slowlogs/slow.log --long_query_time=0
    networks:
      - pmm_default

  mongodb:
    image: "percona/percona-server-mongodb:8.0-multi"
    volumes:
      - mongo-data:/data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: databaseAdmin
      MONGO_INITDB_ROOT_PASSWORD: password
    ports:
      - "27017:27017"
    healthcheck:
      test: ["CMD-SHELL", "mongosh --eval 'db.adminCommand(\"ping\")' --quiet"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - pmm_default

  pmm-server:
    image: percona/pmm-server:3
    platform: "linux/amd64"
    container_name: pmm-server
    restart: always
    ports:
      - 8080:80
      - "443:8443"
    volumes:
      - pmm-data:/srv
    healthcheck:
      test: ["CMD-SHELL", "curl -k -f -L https://pmm-server:8443 > /dev/null 2>&1 || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - pmm_default

  pmm-client:
    image: percona/pmm-client:3
    container_name: pmm-client
    depends_on:
      pmm-server:
        condition: service_healthy
      mysql:
        condition: service_healthy
      postgres:
        condition: service_healthy
      mongodb:
        condition: service_healthy
    environment:
      PMM_AGENT_SERVER_ADDRESS: pmm-server:8443
      PMM_AGENT_SERVER_USERNAME: admin
      PMM_AGENT_SERVER_PASSWORD: admin
      PMM_AGENT_SERVER_INSECURE_TLS: 1
      PMM_AGENT_CONFIG_FILE: config/pmm-agent.yaml
      PMM_AGENT_SETUP: 1
      PMM_AGENT_SETUP_FORCE: 1
      PMM_AGENT_PRERUN_SCRIPT: >
        pmm-admin status --wait=10s &&
        pmm-admin add mysql --query-source=perfschema --username=root --password=password --host=mysql --port=3306 &&
        pmm-admin add postgresql --username=postgres --password=password --host=postgres --port=5432 --query-source=pgstatmonitor &&
        pmm-admin add mongodb --username=databaseAdmin --password=password --host=mongodb --port=27017 --query-source=profiler
    networks:
      - pmm_default

volumes:
  pmm-data:
  mongo-data:
  pg-data:
  mysql-data:


1 Like