PMM2 - configuring mongodb_exporter for MongoDB Atlas

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), 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

1 Like

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 for more info on this

1 Like

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:

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?

1 Like

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.

1 Like

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

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:

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:

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 }, ] }.
1 Like

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 for details. I have opened [PMM-10357] Add flag --direct-connection to pmm-admin - Percona JIRA based on your feedback.
Thanks

1 Like

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.

1 Like