beats icon indicating copy to clipboard operation
beats copied to clipboard

Metricbeats cannot connect to mongodb 5.x

Open simllll opened this issue 3 years ago • 22 comments

I've checkd on https://discuss.elastic.co/c/beats, where some posts have been automatically closed already without a solution.

Please include configurations and logs if available.

For confirmed bugs, please report:

  • Version: metricbeat-7.16.1; Elasticsearch version 7.12.0
  • Operating System: Linux
  • Discuss Forum URL: e.g. https://discuss.elastic.co/t/metricbeat-mongo-5/288037
  • Steps to Reproduce: install mongodb5 and metricbeats -> results into errors: 2021-12-18T18:47:17.436Z ERROR mongodb/mongodb.go:98 Error establishing direct connection to mongo node at [mongo-s1r1.network.hokify.com:27017]. Error output: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field. 2021-12-18T18:47:17.437Z ERROR module/wrapper.go:259 Error fetching data for metricset mongodb.status: error creating new Session: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field. 2021-12-18T18:47:17.459Z ERROR mongodb/mongodb.go:98 Error establishing direct connection to mongo node at [mongo-s1r1.network.hokify.com:27017]. Error output: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field. 2021-12-18T18:47:17.459Z ERROR module/wrapper.go:259 Error fetching data for metricset mongodb.metrics: error creating new Session: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field. 2021-12-18T18:47:17.461Z ERROR mongodb/mongodb.go:98 Error establishing direct connection to mongo node at [mongo-s1r1.network.hokify.com:27017]. Error output: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field. 2021-12-18T18:47:17.461Z ERROR module/wrapper.go:259 Error fetching data for metricset mongodb.collstats: error creating new Session: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field. 2021-12-18T18:47:17.462Z ERROR mongodb/mongodb.go:98 Error establishing direct connection to mongo node at [mongo-s1r1.network.hokify.com:27017]. Error output: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field. 2021-12-18T18:47:17.462Z ERROR module/wrapper.go:259 Error fetching data for metricset mongodb.dbstats: error creating new Session: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.

simllll avatar Dec 18 '21 18:12 simllll

I guess it could be related to an "outed" / "old" mongodb driver? But I couldn't find a way to update it locally; i guess it is bundled with Metricbeats? I couldn't find anything related to this issue on the bugs page of the go driver though.. (https://jira.mongodb.org/browse/GODRIVER-1826?jql=project%20%3D%20GODRIVER%20AND%20resolution%20%3D%20Unresolved%20ORDER%20BY%20priority%20DESC%2C%20updated%20DESC)

simllll avatar Dec 18 '21 18:12 simllll

Pinging @elastic/integrations (Team:Integrations)

elasticmachine avatar Jan 10 '22 09:01 elasticmachine

Yes, I think that the driver must be updated.

sayden avatar Feb 04 '22 12:02 sayden

Any news on this? Thanks

simllll avatar Feb 16 '22 22:02 simllll

any update on this ?

rajsolanki73 avatar Mar 01 '22 19:03 rajsolanki73

Try to use package from mongo website. https://www.mongodb.com/try/download/database-tools

It helped for me.

Little bit details of my case. output from package installed by apt

# mongodump --version
mongodump version: built-without-version-string
git version: built-without-git-spec
Go version: go1.10.1
   os: linux
   arch: amd64
   compiler: gc
OpenSSL version: OpenSSL 1.1.0g  2 Nov 2017

and mongodump fails all the time with the following output

Failed: error connecting to db server: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.

After I installed the version from mongo website it run with success and mongodump version is looks right now.

# mongodump --version
mongodump version: 100.5.2
git version: e2842eb549308c16e070fb2e197d4631cfd085cb
Go version: go1.16.3
   os: linux
   arch: amd64
   compiler: gc

Thanks to: https://stackoverflow.com/questions/68526162/mongodb-connection-error-sasl-with-docker-windows-10 it it made me think.

gad26032 avatar Mar 16 '22 16:03 gad26032

hi @gad26032, thanks for commeting, but the issue is not the with mongodb toolset (mongodump), but with the metricbeats client which has a mongodb client built in. mongodump and other mongo tools are working on my side

simllll avatar Mar 16 '22 16:03 simllll

hi @gad26032, thanks for commeting, but the issue is not the with mongodb toolset (mongodump), but with the metricbeats client which has a mongodb client built in. mongodump and other mongo tools are working on my side

Maybe it is something that has the same cause. Maybe metcbeats use mongo-tools binaries, and it leads to the same error that I had. Have you tried to reinstall mongo-tools? from the official mongo site?

gad26032 avatar Mar 16 '22 17:03 gad26032

Beats still uses the old https://github.com/go-mgo/mgo library to connect to MongoDB, which is currently unmaintained.

Beats must switch the library to the official https://github.com/mongodb/mongo-go-driver which AFAIK wasn't available when the module was incorporated into the codebase.

The structure of the events that Beats generates must be maintained, of course or do the minimum possible amount of changes. So, for example, mongodb.dbstats.avg_obj_size.bytes must still be written in the same JSON path after switching libraries.

@rameshelastic FYI

sayden avatar Mar 24 '22 12:03 sayden

Just curious if we have an update on this issue. Some users are impacted by this.

JohnKnoepfle avatar Apr 14 '22 22:04 JohnKnoepfle

We are impacted by this issue since we migrate our database from 4.x to 5.x Any estimate please ?

cyberjeff-u8t avatar Apr 19 '22 08:04 cyberjeff-u8t

We have not received any external contributions to fix the issue and the capacity of the team at Elastic is limited, but it's in the radar of the team.

sayden avatar Apr 19 '22 10:04 sayden

@sayden Any update / ETA? Some users are planning to upgrade MongoDB and this bug is a blocker.

EdCSM avatar Apr 28 '22 17:04 EdCSM

Right now, there's a plan to release this in some minor version ASAP. It's inconvenient, I feel your pain, but the fix is coming :wink:

sayden avatar Apr 28 '22 18:04 sayden

any update on this ?

rajsolanki73 avatar May 13 '22 13:05 rajsolanki73

There's a PR ongoing already :slightly_smiling_face: https://github.com/elastic/beats/pull/31185/

sayden avatar May 13 '22 20:05 sayden

sorry if i m asking elementary question.

  1. when will this be available via metricbeat release or upgrade ?
  2. can I try this PR ? if yes then how ?

rajsolanki73 avatar May 23 '22 20:05 rajsolanki73

Hi, Same question as @rajsolanki73. Could someone answer?

cyberjeff-u8t avatar Jun 20 '22 10:06 cyberjeff-u8t

any update on this ?

rajsolanki73 avatar Jul 12 '22 15:07 rajsolanki73

any update on this ?

it is now available and working with metricbeat 8.3.1 !

cyberjeff-u8t avatar Jul 13 '22 06:07 cyberjeff-u8t

well for me if i add single server ( i have 3 server cluster with replica set in following template it works.

hosts: ["mymongoserver1:27017"] username: myuser password: mypassword

but if add multiple hosts

hosts: ["mymongoserver1:27017",” mymongoserver2:27017”,” mymongoserver3:27017”] username: myuser password: mypassword

I get following error.

{"log.level":"error","@timestamp":"2022-07-18T08:21:47.507-0500","log.origin":{"file.name":"module/wrapper.go","file.line":256},"message":"Error fetching data for metricset mongodb.status: could not create mongodb client: could not create mongodb client: a direct connection cannot be made if multiple hosts are specified","service.name":"metricbeat","ecs.version":"1.6.0"}

So then i tried following template

hosts: ["mongodb://myuser:mypass@mymongoserver1:27017", " mongodb://myuser:mypass@mymongoserver2:27017", mongodb://myuser:mypass@mymongoserver3:27017"]

{"log.level":"error","@timestamp":"2022-07-18T08:33:34.818-0500","log.origin":{"file.name":"module/wrapper.go","file.line":256},"message":"Error fetching data for metricset mongodb.status: failed to retrieve 'serverStatus': server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: myuser:mypass@mymongoserver1:27017, Type: Unknown, Average RTT: 0, Last error: connection() error occured during connection handshake: dial tcp: address mongodb:// myuser:mypass@mymongoserver1:27017: too many colons in address }, ] }","service.name":"metricbeat","ecs.version":"1.6.0"}

rajsolanki73 avatar Jul 18 '22 13:07 rajsolanki73

Hi Looks like the new mongodb 6 has problems too. I just installed elastic, kibana and fleetserver with mongodb, and it didn't work.

Log:

[elastic_agent.metricbeat][debug] Publish event: { "@timestamp": "2022-08-12T16:59:27.899Z", "@metadata": { "beat": "metricbeat", "type": "_doc", "version": "8.3.3", "raw_index": "metrics-docker.cpu-default" }, "event": { "module": "docker", "duration": 36638100, "dataset": "docker.cpu" }, "elastic_agent": { "id": "4ef4f2f6-1d45-42b8-b2df-d3532ae1c12a", "snapshot": false, "version": "8.3.3" }, "metricset": { "period": 10000, "name": "cpu" }, "service": { "address": "tcp://mongodb1.ae.com.br:27017", "type": "docker" }, "error": { "message": "failed to get docker stats: invalid character 'I' looking for beginning of value" }, "data_stream": { "dataset": "docker.cpu", "namespace": "default", "type": "metrics" }, "agent": { "ephemeral_id": "aa242974-6f97-4c5a-b4cc-75e3da7d5f3b", "name": "docker-desktop-fleetserver", "type": "metricbeat", "version": "8.3.3", "id": "4ef4f2f6-1d45-42b8-b2df-d3532ae1c12a" }, "ecs": { "version": "8.0.0" }, "host": { "hostname": "docker-desktop-fleetserver", "architecture": "x86_64", "os": { "name": "Ubuntu", "kernel": "5.10.16.3-microsoft-standard-WSL2", "codename": "focal", "type": "linux", "platform": "ubuntu", "version": "20.04.4 LTS (Focal Fossa)", "family": "debian" }, "containerized": true, "name": "docker-desktop-fleetserver", "ip": [ "10.0.0.133", "172.21.0.5", "10.0.2.16" ], "mac": [ "02:42:0a:00:00:85", "02:42:0a:00:02:10", "02:42:ac:15:00:05" ] } }

agencia-estado avatar Aug 12 '22 19:08 agencia-estado

I am facing the same issue with Mongo 6

asher-lab avatar Aug 31 '22 20:08 asher-lab

While setting up Metricbeats to monitor MongoDB, I too faced the error too many colons in address. I followed the standard MongoDB url format (which the mongodb.yml alluded to as well) but it failed to work.

I was able to setup the connection by changing the config like so

  hosts: ["<your_host>:<port>"]
  username: <your_username>
  password: <your_password>

ssingh13-rms avatar May 03 '23 07:05 ssingh13-rms

I also faced the same and my environment is below.

  • elasticsearch 8.8.1
  • metricbeat 8.8.1
  • MongoDB 6.0.6 as well as 3.6.23

It looks like metricbeat 8.8.1 is having an error on connecting to even older versions such as above.

TomonoriSoejima avatar Jun 29 '23 01:06 TomonoriSoejima

any idea when this will be fixed?

andrei-gutierrez avatar Aug 17 '23 13:08 andrei-gutierrez

any updates?

algo7 avatar Oct 07 '23 00:10 algo7

I had too many colons in address error while connecting to MongoDB 7. Then in Metricbeat config I changed hosts: ["mongodb://localhost:27017"] to hosts: ["localhost:27017"] and it worked.

Amaimersion avatar Jan 27 '24 10:01 Amaimersion