# pmm2 client setup in Sharded MongoDB

**URL:** https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659
**Category:** PMM 2.x
**Created:** [June 2, 2020, 7:04am UTC](https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659 "2020-06-02T07:04:28Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![eugeneb](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@eugeneb](https://forums.percona.com/u/eugeneb)
#### Post date: [June 2, 2020, 7:04am UTC](https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659/1 "2020-06-02T07:04:28Z")

</div>

It’s not really clear how to set up mongodb\_exporter user in case of Sharded MongoDB cluster. There are Sharded Cluster Users and Shard Local Users -&nbsp;[https://docs.mongodb.com/ma…](https://disq.us/url?url=https%3A%2F%2Fdocs.mongodb.com%2Fmanual%2Fcore%2Fsecurity-users%3A3wNNS0CSSxIokGPyRfNqEcB6PpA&cuid=4563557 "Link: https://disq.us/url?url=https%3A%2F%2Fdocs.mongodb.com%2Fmanual%2Fcore%2Fsecurity-users%3A3wNNS0CSSxIokGPyRfNqEcB6PpA&cuid=4563557"). Where a user for&nbsp;mongodb\_exporter &nbsp; should&nbsp; be created?&nbsp; Should it be created as a “_sharded cluster user_” on mongos and not&nbsp;as a&nbsp;_shard local&nbsp;_directly on mongod node?  
If so, should the QAN agent be running on mongos and not on mongod nodes in this case?  
Thank you in advance for your help!

---

<div class="post-metadata">

### Author: ![Vadim\_Yalovets](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vadim_yalovets/32/43_2.png) [@Vadim\_Yalovets](https://forums.percona.com/u/Vadim_Yalovets)
#### Post date: [June 3, 2020, 3:12am UTC](https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659/2 "2020-06-03T03:12:08Z")

</div>

Hi Eugene,  
It’s required to use exporter on mongos in order to collect sharding&nbsp;metrics (mongodb\_mongos\_sharding\_\*).

---

<div class="post-metadata">

### Author: ![eugeneb](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@eugeneb](https://forums.percona.com/u/eugeneb)
#### Post date: [June 18, 2020, 6:51am UTC](https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659/3 "2020-06-18T06:51:53Z")

</div>

Hi,  
Thanks for answer. It’s still not really clear to me.   
Let’s say I have two Replica Sets in Sharded cluster setup. I have 3 servers in replica set rs0, let’s name them mongod-rs0-1, mongod-rs0-2, mongod-rs0-3.&nbsp; And another 3 server in replica set rs1 - mongod-rs1-1, mongod-rs1-2, mongod-rs1-3. And yet another 3 server in configuration replica set mongod-cfg-1, mongod-cfg-2, mongod-cfg-3. And there are 2 server running mongoses - mongos-1, mongos-2.  
So, there are a total of 11 nodes in the cluster.  
  
Now, how do I configure PMM2 clients for that sharded cluster?  
1. At first, install pmm2-client on all 11 nodes and run “pmm-admin config&nbsp;–server-insecure-tls --server-url=\<pmm-server\>”. At this point we have&nbsp;node\_exporter running on every node.  
2. Then I should add mongodb monitoring:  
&nbsp; a) According to the docs, “MongoDB should be&nbsp;[prepared for the monitoring](https://www.percona.com/doc/percona-monitoring-and-management/2.x/conf-mongodb.html)”, i.e. profiling should be enabled and&nbsp;mongodb\_exporter&nbsp;user has to be setup. What I understood from your answer is that&nbsp;mongodb\_exporter&nbsp;user needs to be set up once on mongos instance as&nbsp;Sharded Cluster User. It should&nbsp;not be created on every mongod node which is part of replica sets. Is that right?  
&nbsp; b) After that, where should I add mongodb service “pmm-admin add mongodb”? On mongos nodes only? Or still on every other node in the cluster? Here comes the confusion. It does not seem right that mongodb monitoring is added on mongos nodes only and not on all other nodes of the cluster. Yet, mongod replica set nodes do not have mongodb permissions setup and it’s not clear if running&nbsp;mongodb\_exporter and&nbsp;mongodb\_profiler\_agent on these nodes makes sense.  
  
Please clarify the proper setup of PMM2 on sharded clusters. I see that the PMM documentation is lacking on this matters.  
Thank you.&nbsp;

---

<div class="post-metadata">

### Author: ![eugeneb](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@eugeneb](https://forums.percona.com/u/eugeneb)
#### Post date: [July 1, 2020, 2:36am UTC](https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659/4 "2020-07-01T02:36:14Z")

</div>

@adivinho Could you please reply to the above? Thank you for your help

---

<div class="post-metadata">

### Author: ![Vadim\_Yalovets](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vadim_yalovets/32/43_2.png) [@Vadim\_Yalovets](https://forums.percona.com/u/Vadim_Yalovets)
#### Post date: [July 1, 2020, 4:59am UTC](https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659/5 "2020-07-01T04:59:44Z")

</div>

Hi Eugen,  
MongoDB service monitoring should be added on all nodes. So please create&nbsp;mongodb\_exporter&nbsp;user on each PRIMARY node and use it for connecting nodes in replica sets.  
  
Here are commands of enabling monitoring for nodes in the same replica set “rs1”.  
# pmm-admin add mongodb --username=mongodb\_exporter --password=mongo --replication-set=rs1 --environment=mongodb\_rs\_node mongodb\_rs1\_1 127.0.0.1:27018# pmm-admin add mongodb --username=mongodb\_exporter --password=mongo --replication-set=rs1 --environment=mongodb\_rs\_node mongodb\_rs1\_2 127.0.0.1:27019# pmm-admin add mongodb --username=mongodb\_exporter --password=mongo --replication-set=rs1 --environment=mongodb\_rs\_node mongodb\_rs1\_3 127.0.0.1:27020

---

<div class="post-metadata">

### Author: ![eugeneb](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@eugeneb](https://forums.percona.com/u/eugeneb)
#### Post date: [July 1, 2020, 6:42am UTC](https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659/6 "2020-07-01T06:42:08Z")

</div>

So, it means to create mongodb\_exporter user as&nbsp;Sharded Cluster User on mongos nodes to collect&nbsp;sharding&nbsp;metrics (mongodb\_mongos\_sharding\_\*) and to create mongodb\_exporter user as Shard Local User on primary nodes to monitor mongod replica set member nodes. Is this correct?

---

<div class="post-metadata">

### Author: ![Vadim\_Yalovets](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vadim_yalovets/32/43_2.png) [@Vadim\_Yalovets](https://forums.percona.com/u/Vadim_Yalovets)
#### Post date: [July 1, 2020, 6:51am UTC](https://forums.percona.com/t/pmm2-client-setup-in-sharded-mongodb/7659/7 "2020-07-01T06:51:21Z")

</div>

Yes. It’s correct.
