Running Percona Server for MongoDB with PMM monitoring and QAN query analytics in Docker Compose

Hi, I want to share a docker-compose configuration to run Percona Server for MongoDB in combination with PMM monitoring and QAN query analytics.

This is very handy in developing locally on a laptop. You can connect the application to the database and immediately see the results in PMM.

The docker-compose configuration will launch with a single command:

  1. Percona Server for MongoDB with profiling enabled.
  2. PMM Server to open PMM in a browser via localhost
  3. PMM Client to send metrics from MongoDB to PMM.

It may need to be adjusted for your OS. I will be glad to receive suggestions and feedback.

  1. Create a mongod.conf file to enable profiling.
    mongod.conf
operationProfiling:
  mode: all
  slowOpThresholdMs: 200
  rateLimit: 100
  1. Create docker-compose.yaml . Replace the image for your OS, I use macOS c ARM. Specify the path to mongod.conf
version: '3.7'
services:

  mongodb:
    image: "percona/percona-server-mongodb:7.0-arm64" // Replace the image to match your OS.
    volumes:
      - mongodata:/data/db
      - ./mongod.conf:/etc/mongod.conf:ro
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: password
      MONGO_INITDB_DATABASE: database
    ports: 
      - "27017:27017"
    command: ["mongod", "--config", "/etc/mongod.conf"]
  
  pmm-server:
      image: percona/pmm-server:2
      platform: "linux/amd64"
      container_name: pmm-server
      restart: always
      ports:
        - 8081:80
        - 443:443
      volumes:
        - pmm-data:/srv
      environment:
        - DISABLE_TELEMETRY=0
      healthcheck:
        test: ["CMD", "curl", "-f", "http://localhost"]
        interval: 30s
        timeout: 10s
        retries: 5

  pmm-client-mongodb:
    image: percona/pmm-client:2
    platform: "linux/amd64"
    container_name: pmm-client-mongodb
    depends_on:
      pmm-server:
        condition: service_healthy
    environment:
      PMM_AGENT_SERVER_ADDRESS: pmm-server
      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 mongodb --username=root --password=password --host=mongodb --port=27017 --query-source=profiler"
  
volumes:
  mongodata:
  pmm-data:
  1. Run the command docker-compose up -d.
  2. Connect your application to the database via localhost. Open PMM in a browser via localhost.

Dashboard example

1 Like

Hell @daniil.bazhenov !

Thanks for sharing. Just a quick note. To make it more compatible, I don’t think you have to indicate the specific platform that you want to use, in your docker-compose file.

Your Docker client will automatically use/choose the corresponding image given your architecture, if it is available, or it will emulate your platform if there is no image available for your Platform.

Best regards.
Ernesto.

Thanks for your comment, maybe the problem is with my Docker Desktop, but when I don’t specify a platform, the launch fails ending in an error.

I’ll try to test again and will improve this.

I use this thing every day as I develop my self-study project.