mongodb_exporter
mongodb_exporter copied to clipboard
ERRO[0030] Cannot connect to MongoDB
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 Could you try connect to mongo db from mongo shell?
Yes, I try and I can connect with a mongo shell. I can execute comands and get data. But with mongo_exporter not
@juanluishg Please if you can provide us more logs and how you connecting from mongo shell to make debug here easier. Thank you
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:
./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
- 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
- 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
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?
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.
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
passing
--no-mongodb.direct-connectresolved this issue for me on version0.39.0
Are you getting data, connected now but metrics which was supposed to come is not coming
Atlas users can use the supported Prometheus integration instead.
That integration have too little metrics
: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?