mongodb_exporter icon indicating copy to clipboard operation
mongodb_exporter copied to clipboard

ERRO[0030] Cannot connect to MongoDB

Open juanluishg opened this issue 3 years ago • 12 comments

Describe the bug I'm trying to connect mongo_exporter to a mongodb atlas instance, it's a serverless instance. But when I'm using the mongodb uri I'm getting the following error: ERRO[0030] Cannot connect to MongoDB: cannot connect to MongoDB: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: myproject.gqgr8.mongodb.net:27017, Type: Unknown, Last error: connection() error occured during connection handshake: dial tcp: lookup myprojec.gqgr8.mongodb.net on 127.0.0.53:53: no such host }, ] }

I'm using a Azure VM with Ubuntu 20.04.

I'm executing the following command ./mongodb_exporter --mongodb.uri="mongodb://user:[email protected]:27017/test?authSource=admin&readPreference=primary&ssl=true"

juanluishg avatar Jan 11 '22 18:01 juanluishg

@juanluishg Could you try connect to mongo db from mongo shell?

JiriCtvrtka avatar Jan 12 '22 12:01 JiriCtvrtka

Yes, I try and I can connect with a mongo shell. I can execute comands and get data. But with mongo_exporter not

juanluishg avatar Jan 12 '22 19:01 juanluishg

@juanluishg Please if you can provide us more logs and how you connecting from mongo shell to make debug here easier. Thank you

JiriCtvrtka avatar Jan 19 '22 12:01 JiriCtvrtka

If I connect with mongosh it works fine

administrador@SensorAI:~$ mongosh "mongodb+srv://user:[email protected]/test?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=true"                  
Current Mongosh Log ID: 6207e8becaeb1dca44eac942
Connecting to:          mongodb+srv://<credentials>@myproject.gqgr8.mongodb.net/test?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=true
Using MongoDB:          5.2.0
Using Mongosh:          1.1.8

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

Atlas test>

But when I am trying with mongo_exporter I tried different options:

  1. ./mongodb_exporter --mongodb.uri="mongodb+srv://user:[email protected]/test?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=true"

And it returns

level=info ts=2022-02-12T17:00:27.796Z 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 an SRV URI is used
  1. So I disable the direct connection ./mongodb_exporter --mongodb.uri="mongodb+srv://user:[email protected]/test?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=true" --mongodb.direct-connect=false

And it returns

level=info ts=2022-02-12T17:00:37.656Z caller=tls_config.go:195 msg="TLS is disabled." http2=false
ERRO[0000] Cannot connect to MongoDB: invalid MongoDB options: loadBalanced cannot be set to true if the direct connection option is specified
  1. Also I have tried without srv ./mongodb_exporter --mongodb.uri="mongodb://user:[email protected]/test?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=true" --mongodb.direct-connect=true --mongodb.global-conn-pool

And also I have gotten an error

level=info ts=2022-02-12T17:03:51.472Z caller=tls_config.go:195 msg="TLS is disabled." http2=false
ERRO[0030] Cannot connect to MongoDB: cannot connect to MongoDB: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: myproject.gqgr8.mongodb.net:27017, Type: Unknown, Last error: connection() error occured during connection handshake: dial tcp: lookup myproject.gqgr8.mongodb.net: No address associated with hostname }, ] }

I want to add that the mongodb instance is a serverless atlas deployment

juanluishg avatar Feb 12 '22 17:02 juanluishg

I run into this issue as well and updating the mongo driver seems to solve it (see #633 for details). Do you think it would make sense to update it?

sigilioso avatar Mar 27 '23 07:03 sigilioso

Just got bitten by this, it seems that the exporter does not support use of SRV records to handle the nodes associated with the cluster: $ docker run --rm --publish 9216:9216 percona/mongodb_exporter:latest --mongodb.uri="mongodb+srv://user:[email protected]/test" level=info ts=2023-04-19T18:00:01.235Z caller=tls_config.go:195 msg="TLS is disabled." http2=false time="2023-04-19T18:00:01Z" level=error msg="Cannot connect to MongoDB: invalid MongoDB options: a direct connection cannot be made if multiple hosts are specified" Atlas users can use the supported Prometheus integration instead.

Syavne avatar Apr 19 '23 18:04 Syavne

Just got bitten by this, it seems that the exporter does not support use of SRV records to handle the nodes associated with the cluster: $ docker run --rm --publish 9216:9216 percona/mongodb_exporter:latest --mongodb.uri="mongodb+srv://user:[email protected]/test" level=info ts=2023-04-19T18:00:01.235Z caller=tls_config.go:195 msg="TLS is disabled." http2=false time="2023-04-19T18:00:01Z" level=error msg="Cannot connect to MongoDB: invalid MongoDB options: a direct connection cannot be made if multiple hosts are specified" Atlas users can use the supported Prometheus integration instead.

passing --no-mongodb.direct-connect resolved this issue for me on version 0.39.0

kfalconer avatar Jul 05 '23 15:07 kfalconer

passing --no-mongodb.direct-connect resolved this issue for me on version 0.39.0

Are you getting data, connected now but metrics which was supposed to come is not coming

image

technicalbirdVayuz avatar Jul 13 '23 06:07 technicalbirdVayuz

Atlas users can use the supported Prometheus integration instead.

That integration have too little metrics

tulequ avatar Dec 08 '23 10:12 tulequ

:wave: joining the serverless party too; I am able to connect - but I get:

time="2023-12-12T21:35:20Z" level=error msg="cannot auto discover databases and collections: cannot make the list of databases to list all collections: cannot get the database names list: (AtlasError) Unallowed argument in listDatabases command: filter"

That's using:

        - --discovering-mode
        - --collector.dbstats
        - --collector.collstats
        - --collector.topmetrics
        - --no-mongodb.direct-connect

Assuming the issue is with discovering-mode? It does seem to work if i use colstats-cols. Due to the relatively dynamic nature of our underlying databases, i'd rather no move to a static list! :) Any ideas if it's possible to get this working?

Stono avatar Dec 12 '23 21:12 Stono