# PMM2 - configuring mongodb\_exporter for MongoDB Atlas

**URL:** https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671
**Category:** PMM 2.x
**Created:** [July 21, 2022, 11:29am UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671 "2022-07-21T11:29:06Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Markus\_Koppenberger](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/markus_koppenberger/32/7020_2.png) [@Markus\_Koppenberger](https://forums.percona.com/u/Markus_Koppenberger)
#### Post date: [July 21, 2022, 11:29am UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/1 "2022-07-21T11:29:06Z")

</div>

We are trying to monitor one of our clusters on MongoDB Atlas using PMM (pmm2-client 2.29.0-6.focal on Ubuntu 20.04.2 LTS) but we are not able to configure the connection.

As far as we can see, the connection protocol / process used for MongoDB Atlas (“mongodb+srv://”) seems not to be supported by the mongodb\_exporter.

In the documentation there is mentioned to use the ‘–direct-connection=false’ option for Mongo Atlas ([MongoDB - Percona Monitoring and Management](https://docs.percona.com/percona-monitoring-and-management/setting-up/client/mongodb.html#on-the-command-line)), but it seems that this option does not exist (anymore/yet?) in the version 2.29 of ppm2-admin.

Has anyone run in the same problem and can give us maybe some insight on how to configure MongoDB on a ppm client for MongoDB Atlas?

Thanks in advance,  
koppi

---

<div class="post-metadata">

### Author: ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)
#### Post date: [July 21, 2022, 2:37pm UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/2 "2022-07-21T14:37:01Z")

</div>

Hello, looks like the doc is not right. There is an option called `--mongodb.direct-connect` for mongodb\_exporter but that is not currently exposed by the pmm-admin command. The default is true as far as I can tell so it should still connect to Atlas. You can check [[PMM-7128] Can not connect to Mongo Atlas - Percona JIRA](https://jira.percona.com/browse/PMM-7128) for more info on this

---

<div class="post-metadata">

### Author: ![Markus\_Koppenberger](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/markus_koppenberger/32/7020_2.png) [@Markus\_Koppenberger](https://forums.percona.com/u/Markus_Koppenberger)
#### Post date: [July 21, 2022, 3:00pm UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/3 "2022-07-21T15:00:29Z")

</div>

Thanks for your quick reply, it seems that adding `--no-mongodb.direct-connect` could do the trick, at least I don’t get a connection error anymore:

```auto
root@ip-10-20-1-226:/usr/local/percona/pmm2/exporters# ./mongodb_exporter --mongodb.uri=mongodb+srv://user:pass@xxxx.xxxx.mongodb.net/admin --no-mongodb.direct-connect
level=info ts=2022-07-21T14:56:22.861Z caller=tls_config.go:195 msg="TLS is disabled." http2=false

```

But how can I configure PMM to use these options (mongodb URI and --no-mongodb.direct-connect) correctly?

---

<div class="post-metadata">

### Author: ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)
#### Post date: [July 21, 2022, 3:25pm UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/4 "2022-07-21T15:25:06Z")

</div>

Have you tried feeding the URI directly to --host argument of pmm-admin? as I mentioned direct seems to be the default so it should work as far as I can tell.

---

<div class="post-metadata">

### Author: ![Markus\_Koppenberger](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/markus_koppenberger/32/7020_2.png) [@Markus\_Koppenberger](https://forums.percona.com/u/Markus_Koppenberger)
#### Post date: [July 21, 2022, 3:37pm UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/5 "2022-07-21T15:37:45Z")

</div>

It seems that the default for direct connection is “true”, if I don’t specify the `--no-mongo.direct-connect` option explicitely I get an connection error

```auto
root@ip-10-20-1-226:/usr/local/percona/pmm2/exporters# ./mongodb_exporter --mongodb.uri=mongodb+srv://user:pass@xxxxx.mongodb.net/admin
level=info ts=2022-07-21T15:27:25.946Z caller=tls_config.go:195 msg="TLS is disabled." http2=false
ERRO[0000] Cannot connect to MongoDB: invalid MongoDB options: a direct connection cannot be made if multiple hosts are specified

```

With ppm-admin, using the cluster entry point (as in the example above) results in a “no such host” error, as this is only the service URI which should than point to the different nodes of the cluster:

```auto
root@ip-10-20-1-226:~# pmm-admin add mongodb --username=user --password=pass --host=xxxxx.mongodb.net --enable-all-collectors 
Connection check failed: server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: xxxx.xxxx.mongodb.net:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup xxxx.xxxx.mongodb.net on 127.0.0.53:53: no such host },] }.

```

And using the hostname of the primary node, I get an error on handshake:

```auto
root@ip-10-20-1-226:~# pmm-admin add mongodb --username=user --password=pass --host=xxxx-shard-00-01.xxxx.mongodb.net --enable-all-collectors 
Connection check failed: server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: xxxx-shard-00-01xxxx.mongodb.net:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: connection(xxxx-shard-00-01.xxxx.mongodb.net:27017[-150]) socket was unexpectedly closed: EOF }, ] }.

```

---

<div class="post-metadata">

### Author: ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)
#### Post date: [July 21, 2022, 3:53pm UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/6 "2022-07-21T15:53:27Z")

</div>

Ok, for now the workaround would be running the exporter yourself and adding it to PMM as an external exporter. See [External Services - Percona Monitoring and Management](https://docs.percona.com/percona-monitoring-and-management/setting-up/client/external.html) for details. I have opened [[PMM-10357] Add flag --direct-connection to pmm-admin - Percona JIRA](https://jira.percona.com/browse/PMM-10357) based on your feedback.  
Thanks

---

<div class="post-metadata">

### Author: ![Markus\_Koppenberger](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/markus_koppenberger/32/7020_2.png) [@Markus\_Koppenberger](https://forums.percona.com/u/Markus_Koppenberger)
#### Post date: [July 21, 2022, 4:33pm UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/7 "2022-07-21T16:33:15Z")

</div>

Thanks for your help @Ivan_Groenewold , I’ll try the work-around with an external exporter when I’m back from my vacations, and let you know how it goes.

---

<div class="post-metadata">

### Author: ![bkumar11](https://avatars.discourse-cdn.com/v4/letter/b/cdc98d/32.png) [@bkumar11](https://forums.percona.com/u/bkumar11)
#### Post date: [June 7, 2023, 12:27pm UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/8 "2023-06-07T12:27:46Z")

</div>

@Markus_Koppenberger ,  
Were you able to get this worked, if so can you please share the details here?

---

<div class="post-metadata">

### Author: ![Markus\_Koppenberger](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/markus_koppenberger/32/7020_2.png) [@Markus\_Koppenberger](https://forums.percona.com/u/Markus_Koppenberger)
#### Post date: [June 7, 2023, 1:25pm UTC](https://forums.percona.com/t/pmm2-configuring-mongodb-exporter-for-mongodb-atlas/16671/9 "2023-06-07T13:25:18Z")

</div>

Hi @bkumar11 ,

no, we finally didn’t follow this path, we made some custom script to integrate monitoring of MongoDB Atlas in our existing solution. Anyway, we don’t use MongoDB Atlas anymore but are now a happy customer of Percona Managed Services for MongoDB on our own AWS infrastructure, which obviously includes a PMM 😉
