ivinco
How To Set Up MongoDB Monitoring With PMM

How To Set Up MongoDB Monitoring With PMM

Stanislav LevchenkoStanislav Levchenko··Updated

Prepare your environment

Before you get started setting up MongoDB to connect to PMM monitoring, you need to have a PMM Client and register it on the PMM Server. Let's do it. You may set up the PMM Client in different ways. It can be either running in a Docker container or installed by a package manager or from sources. In this article, we will use the easiest way — we will install it from the repository using a package manager. Make sure you have curl, gnupb, wget, and sudo installed on your server. First of all, you need to add the Percona repo to your repositories list.

For Debian-based OS

a. Configure repositories:

wgethttps://repo.percona.com/apt/percona-release_latest.generic_all.debdpkg -i percona-release_latest.generic_all.deb

b. Install the pmm2-client package:

apt updateapt install -y pmm2-client

c. Check if it was installed correctly:

pmm-admin --version

For RedHat-based OS

a. Configure repositories:

yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm

b. Install the pmm2-client package:

yum install -y pmm2-client

c. Check if it was installed correctly:

pmm-admin --version

After you have installed the PMM Client, you should register it on your server. You need the PMM Server hostname or IP-address and credentials for your connection.

To register the PMM client on the server, just type:

pmm-admin config --server-insecure-tls --server-url=https://admin:<password>@XXX.XXX.XXX.XXX:443 YYY.YYY.YYY.YYY generic mynode

where XXX.XXX.XXX.XXX — IP address or hostname of PMM server, YYY.YYY.YYY.YYY — IP address or hostname of PMM client, generic — client type and mynode — mane of client.

Configure MongoDB

After MongoDB and the PMM client are installed, you need to have a user with proper privileges. You may add a user in the Mongo session:

db.getSiblingDB("admin").createRole({    role: "explainRole",    privileges: [{        resource: {            db: "",            collection: ""            },        actions: [            "listIndexes",            "listCollections",            "dbStats",            "dbHash",            "collStats",            "find"            ]        }],    roles:[]})db.getSiblingDB("admin").createUser({   user: "pmm_mongodb",   pwd: "password",   roles: [      { role: "explainRole", db: "admin" },      { role: "clusterMonitor", db: "admin" },      { role: "read", db: "local" }   ]})

If you want to use PMM Query Analytics, you should turn on the profiling feature. To make this setting permanent, edit /etc/mongod.conf adding operationProfiling section:

operationProfiling:  mode: all  slowOpThresholdMs: 200 rateLimit: 100 # (Only available with Percona Server for MongoDB.)

Restart mongod service

systemctl restart mongod

After that, you are ready to connect your MongoDB to PMM monitoring. To do that run:


pmm-admin add mongodb \
--username=pmm_mongodb --password=password \
--query-source=profiler --cluster=mycluster

You may add –environment and -custom-label options to set tags for the service to help identify them.

After successful adding, you may find your service on the PMM Server in Configuration -> PMM Inventory -> Inventory list or check on the client using the command:

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

And now you should see your MongoDB on your monitoring panel.


Need help with database monitoring and performance? Our DevOps consulting team sets up monitoring for MySQL, PostgreSQL and MongoDB. The first conversation is free.

Frequently Asked Questions

How do I set up MongoDB monitoring with PMM?

Install the PMM Client via your package manager (Debian: apt install -y pmm2-client, RedHat: yum install -y pmm2-client), register it with pmm-admin config pointing to your PMM Server, create a dedicated MongoDB user with explainRole and clusterMonitor roles, then run pmm-admin add mongodb --username=pmm_mongodb --query-source=profiler to connect the instance.

What MongoDB user privileges does PMM require?

PMM requires a MongoDB user with three roles: explainRole (custom role with listIndexes, listCollections, dbStats, dbHash, collStats, find), clusterMonitor on the admin database, and read on the local database. Do not use a superuser account — create a dedicated pmm_mongodb user with only these specific privileges.

How do I enable Query Analytics for MongoDB in PMM?

Enable MongoDB profiling by adding an operationProfiling section to /etc/mongod.conf with mode: all and slowOpThresholdMs: 200. Restart mongod, then add the service to PMM with --query-source=profiler. Query Analytics will then capture slow queries and display execution statistics in the PMM dashboard.

How do I verify that MongoDB is connected to PMM?

After running pmm-admin add mongodb, verify the connection by running pmm-admin inventory list services --service-type=mongodb. The registered MongoDB instance should appear in the output. You can also confirm in the PMM Server web UI under Configuration → PMM Inventory → Inventory list.