In this blog, we will see how to configure Percona Monitoring and Management (PMM) monitoring for a MongoDB cluster. It’s very simple, like adding a replica set or standalone instances to PMM Monitoring. 

For this example, I have used docker to create PMM Server and MongoDB sharded cluster containers. If you want the steps I used to create the MongoDB® cluster environment using docker, I have shared them at the end of this blog. You can refer to this if you would like to create the same set up.

Configuring PMM Clients

For PMM installations, you can check these links for PMM installation and pmm-client setup. The following are the members of the MongoDB cluster:

In this setup, I installed the pmm-client on mongos1 server. Then I added an agent to monitor MongoDB metrics with cluster option as shown in the next code block. I named the cluster “mongoClusterPMM” (Note: you have to be root user or need sudo access to execute the pmm-admin command):

As you can see, I used the  pmm-admin add mongodb [options] command which enables monitoring for system, MongoDB metrics and queries. You need to enable profiler to monitor MongoDB queries. Use the next command to enable it at database level:

Check this blog to know more about QAN setup and details. If you want to enable only MongoDB metrics, rather than queries to be monitored, then you can use the command  pmm-admin add  mongodb:metrics [options] . After this, go to the PMM homepage (in my case localhost:8080) in your browser and select MongoDB Cluster Summary from the drop down list under the MongoDB option. The below screenshot shows the MongoDB Cluster—“mongoClusterPMM” statistics— collected by the agent that we added in mongos1 server. 

Percona Monitoring and Management for a MongoDB cluster

Did we miss something here? And do you see any metrics in the dashboard above except “Balancer Enabled” and “Chunks Balanced”?

No. This is because, PMM doesn’t have enough data to show in the dashboard. The shards are not added to the cluster yet and as you can see it displays 0 under shards. Let’s add two shard replica sets mongors1 and mongors2 in the mongos1 instance, and enable sharding to the database to complete the cluster setup as follows:

Now, I’ll add some data, collection and shard keys, and enable sharding so that we can see some statistics in the dashboard:

At last! Now you can see statistics in the graph for the MongoDB cluster:

PMM Statistics for a MongoDB Cluster 

Full Cluster Monitoring

We are not done yet. We have just added an agent to monitor mongos1 instance, and so only the cluster related statistics and QAN are collected through this node. For monitoring all nodes in the MongoDB cluster, we need to configure all nodes in PMM under “mongoClusterPMM” cluster. This will tell PMM that the configured nodes are part of the same cluster. We could also monitor the replica set related metrics for the members in config DBs and shards. Let’s add the monitoring agents in mongos1 server to monitor all MongoDB instances remotely. We’ll use these commands:

Once you have added them, you can check the agent’s (mongodb-exporter) status as follows:

So now you can monitor every member of the MongoDB cluster including their replica set and shard statistics. The next screenshot shows one of the members from the replica set under MongoDB replica set dashboard. You can select this from dashboard in this way: Cluster: mongoClusterPMM → Replica Set: mongors1 → Instance: mongors1replSetn2]:

 PMM MongoDB Replica Set Dashboard

MongoDB cluster docker setup

As I said in the beginning of this blog, I’ve provided the steps for the MongoDB cluster setup. Since this is for testing, I have used very simple configuration to setup the cluster environment using docker-compose. Before creating the MongoDB cluster, create the network in docker for the cluster nodes and PMM to connect each other like this:

I used the docker-compose.yaml file to create the docker environment here:

Hint:
In the docker compose file, above, if you are using docker-compose version >=3.x, then you can use the option for “networks” in the yaml file like this:

Now start the containers and configure the cluster quickly as follows:

ConfigDB replica set setup

Shard1 replica set setup

Shard2 replica set setup:

I hope that this blog helps you to setup a MongoDB cluster and also to configure PMM to monitor it! Have a great day!

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Lalit Sapra

I am unable to understand how to configure PMM dashboard for an existing replicaset without any shards . I tried adding them using uri but on the dashboard they show up as individual servers and I am unable to see any instances in the mongo replicaset dashboard.

Hi Lalit, can I get you to post this question to the Forum and I will follow up with it there? Only it’s easier to collect the detailed information that we might need to help you out, and also the responses there are more easily found by users with the same problem. Here is the link https://www.percona.com/forums/ please be sure to add environment and version information plus any other info that might help track your answer down. Thank you!

Lalit Sapra

Hi Lorraine, I have raised the question in the forums as suggested. But it is not showing up on the forum I believe it takes some time to be visible.

I’ve pushed that through the Forum for you now

Pawan

Hi Vinodh,

I am trying to setup PMM for my staging ENV. But when we run the following command on client node
pmm-admin add mongodb –uri mongodb://user:passwrd@localhost:27017/admin –cluster mongoClusterPMM

We get the following error in the log file /var/log/pmm-mongodb-metrics-42003.log
time=”2018-09-14T19:31:25+05:30″ level=error msg=”Failed to execute find query on ‘config.locks’: not found.” source=”sharding_status.go:106″
time=”2018-09-14T19:31:25+05:30″ level=info msg=”Starting HTTPS server for https://172.17.0.1:42003/metrics …” source=”server.go:106″

Can you please help me on this.
We are using Mongodb 3.6.2 version