# Best Practice for running PMM Client for MongoDB ReplicaSet

**URL:** https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956
**Category:** PMM 2.x
**Created:** [January 27, 2021, 7:54am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956 "2021-01-27T07:54:34Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![rajalokan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/rajalokan/32/2472_2.png) [@rajalokan](https://forums.percona.com/u/rajalokan)
#### Post date: [January 27, 2021, 7:54am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/1 "2021-01-27T07:54:34Z")

</div>

Hi Team. Thanks a lot for this awesome PMM tool. Great Work.

I am trying to monitor a mongodb replicaset. I understand steps to setup a mongo client (on Ubuntu node) is

1. Install `pmm2` repo. (`apt install`).
2. Configure PMM client to talk to PMM server (`pmm-admin config ...`
3. Create role and user in mongodb. (`db.createRole` & `db.createUser`)
4. Create a PMM service for this mongodb. (`pmm-admin add mongodb`).

**My question is reg fourth (4th) step. Do we need to do this for all the nodes of replicaset. Or should this be done only once for one replicaset ?** I understand Step 1 and Step 2 should be done for all the nodes of replicaset to ensure we get OS metrics from those node. Can anyone please clarify reg step 3 and step 4.

---

<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: [January 27, 2021, 8:39am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/2 "2021-01-27T08:39:39Z")

</div>

Hi Alok,

If your replica set is active than user can be created on the primary node.  
All services should be added for monitoring (`pmm-admin add mongodb`)

---

<div class="post-metadata">

### Author: ![ROHIT\_KHURANA](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/rohit_khurana/32/2760_2.png) [@ROHIT\_KHURANA](https://forums.percona.com/u/ROHIT_KHURANA)
#### Post date: [February 1, 2021, 11:52am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/3 "2021-02-01T11:52:51Z")

</div>

Step 3 need to run on primary node only. Rest steps should execute on all nodes separately.

---

<div class="post-metadata">

### Author: ![ROHIT\_KHURANA](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/rohit_khurana/32/2760_2.png) [@ROHIT\_KHURANA](https://forums.percona.com/u/ROHIT_KHURANA)
#### Post date: [February 4, 2021, 9:56am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/4 "2021-02-04T09:56:41Z")

</div>

Yes, step 4, you need to run on each node of replica set

---

<div class="post-metadata">

### Author: ![venkatsv.2020](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@venkatsv.2020](https://forums.percona.com/u/venkatsv.2020)
#### Post date: [February 25, 2021, 7:51am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/5 "2021-02-25T07:51:48Z")

</div>

what is the syntax to add replica nodes for monitoring.

i am able to add cluster and but cannot able to add nodes.

pmm-admin list  
Service type Service name Address and port Service ID  
MongoDB xxxxxxx 127.0.0.1:27017 xxxxxxxxxxxx

Step1: add cluster → pmm-admin add mongodb --username=pmm --password=xxxx --cluster mongodev0 mongodev

on node1:

Step2: add replica cluster → pmm-admin add mongodb:metrics --uri “mongodb://xxxxxx:27017/admin?replicaSet=mongodev0” mongonode1 --cluster mongodev0 mongodev

Error at step2 : pmm-admin: error: expected command but got “mongodb:metrics”, try --help

Please advise

---

<div class="post-metadata">

### Author: ![ROHIT\_KHURANA](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/rohit_khurana/32/2760_2.png) [@ROHIT\_KHURANA](https://forums.percona.com/u/ROHIT_KHURANA)
#### Post date: [February 25, 2021, 8:22am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/6 "2021-02-25T08:22:34Z")

</div>

Can you share out put of

> pmm-admin list.

it’s pmm-admin add **mongodb** not **mongodb:metrics**  
if you have replica set, you need to add mongo as a cluster so that you will find all node under one cluster on dashboard.

> pmm-admin add mongodb --username=pmm --password=xxxx --cluster clustername

if you have standalone node. Then you need to add mongo node.

> pmm-admin add mongodb --username=pmm --password=pmm

---

<div class="post-metadata">

### Author: ![venkatsv.2020](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@venkatsv.2020](https://forums.percona.com/u/venkatsv.2020)
#### Post date: [February 25, 2021, 8:29am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/7 "2021-02-25T08:29:45Z")

</div>

Thank you Rohit.

pmm-admin list  
Service type Service name Address and port Service ID  
MongoDB xxxdb 127.0.0.1:27017 /service\_id/xxxxxx

Agent type Status Metrics Mode Agent ID Service ID  
pmm\_agent Connected /agent\_id/xxxx  
node\_exporter Running push /agent\_id/xxx  
mongodb\_exporter Running push /agent\_id/xxxx /service\_id/xxxxx  
mongodb\_profiler\_agent Running /agent\_id/xxx /service\_id/xxxxx  
vmagent Running push /agent\_id/xxxx

1. i have a replicaset with three nodes, i am able to see cluster in dash board
2. but i do not see other node information ( secondary)

pmm-admin add mongodb --username=pmm --password=xxxx --cluster clustername → this is added

how do i configure all nodes/replicaset ( to monitor replication latency etc…)

---

<div class="post-metadata">

### Author: ![ROHIT\_KHURANA](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/rohit_khurana/32/2760_2.png) [@ROHIT\_KHURANA](https://forums.percona.com/u/ROHIT_KHURANA)
#### Post date: [February 25, 2021, 9:28am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/8 "2021-02-25T09:28:33Z")

</div>

run below on each node

> pmm-admin add mongodb --username=pmm --password=xxxx --cluster clustername

---

<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: [February 25, 2021, 9:34am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/9 "2021-02-25T09:34:30Z")

</div>

> [@venkatsv.2020](#):
>
> i have a replicaset with three nodes, i am able to see cluster in dash board

Could you check labels _set_ and _replication\_set_ on Explore page?  
You may use the next command  
`count by (set, replication_set) (mongodb_mongod_replset_my_state)`

e.g.

 ![Screenshot_20210225_113203](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/1/1b27f3eac87e597c0a3db883709a0ae99006063d.png)

---

<div class="post-metadata">

### Author: ![venkatsv.2020](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@venkatsv.2020](https://forums.percona.com/u/venkatsv.2020)
#### Post date: [February 25, 2021, 12:35pm UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/10 "2021-02-25T12:35:11Z")

</div>

![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/1/1e5480d094b2da81c656f16a06548d05c537cc9c.png)

i have executed below commands on clients to add cluster/nodes

Primary:  
pmm-admin add mongodb --username=pmm --password=xxxx --cluster clustername  
pmm-admin add mongodb --username=pmm --password=xxxxx node1  
Secondary1  
pmm-admin add mongodb --username=pmm --password=xxxxx node2  
Secondary2 :  
pmm-admin add mongodb --username=pmm --password=xxxx node3

---

<div class="post-metadata">

### Author: ![venkatsv.2020](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@venkatsv.2020](https://forums.percona.com/u/venkatsv.2020)
#### Post date: [February 25, 2021, 12:47pm UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/11 "2021-02-25T12:47:04Z")

</div>

i cannot run the same command on all three nodes, only one node is possible , as above command register cluster  
error : Service with name “xxxxx” already exists.

---

<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: [February 25, 2021, 1:39pm UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/12 "2021-02-25T13:39:38Z")

</div>

There is a no reason to add service twice on node1. It’s already monitored after the first command.  
Also please use flag _–cluster clustername_ for all nodes.

---

<div class="post-metadata">

### Author: ![venkatsv.2020](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@venkatsv.2020](https://forums.percona.com/u/venkatsv.2020)
#### Post date: [February 25, 2021, 2:15pm UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/13 "2021-02-25T14:15:40Z")

</div>

Thank you Adivinho.

i tried your suggestion , my problem still the same

1. i do not see replset members ( please refer picture)  
2.just want to know why is the state null

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/5/5c7fe080814f151c878af344321db974294bc4e8.png)

---

<div class="post-metadata">

### Author: ![ROHIT\_KHURANA](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/rohit_khurana/32/2760_2.png) [@ROHIT\_KHURANA](https://forums.percona.com/u/ROHIT_KHURANA)
#### Post date: [February 26, 2021, 10:15am UTC](https://forums.percona.com/t/best-practice-for-running-pmm-client-for-mongodb-replicaset/8956/14 "2021-02-26T10:15:45Z")

</div>

Below worked for me

primary

> pmm-admin add mongodb --username=pmm --password=xxxxx node1 --cluster clustername

Secondary1

> pmm-admin add mongodb --username=pmm --password=xxxxx node2 --cluster clustername

Secondary2 :

> pmm-admin add mongodb --username=pmm --password=xxxx node3 --cluster clustername

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/c/c81ed2b3b773988ba14660384254fe5817cdcda6.png)

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/2/22c8b2ff11bcd11201dec7c3982b7e1afe828b15.png)
