Skip to content

Document running exporter with --no-mongodb.direct-connect and multiple mongo servers in uri #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bareksml opened this issue Nov 20, 2024 · 4 comments

Comments

@bareksml
Copy link

bareksml commented Nov 20, 2024

Describe the bug

There is no mongodb_exporter deployment pattern for clusters provided in documentation. I can run my exporter on HA platform and i want to get cluster state. For that reason i have tried:

mongodb_exporter --mongodb.uri="mongodb://10.0.3.222:27017,10.0.1.210:27017,10.0.2.101:27017/?replicaSet=rs0"  --collect-all

Result is:

ERRO[0000] Cannot connect to MongoDB: invalid MongoDB options: a direct connection cannot be made if multiple hosts are specified

I can get single exporter process working with my cluster by using --no-mongodb.direct-connect. Some posts from Percona guys suggests we should have one exporter per node. This would complicate scraping and later on i will have metrics tripled (extra dimension being particular exporter). This is kind of dirty so it would be great to have some information about the deployment pattern. Also answer for a qestion:

Can i run with multiple cluster nodes and --no-mongodb.direct-connect without risk of having broken metrics?

To Reproduce
Steps to reproduce the behavior:
Try running exporter against 3 node replicaset cluster.

Expected behavior
Answer provided and documentation updated.

Environment

  • Linux
  • mixed
  • MongoDB 4.x however i feel question is quite generic

Additional context

@dima-sh-papaya
Copy link

were you able to figure this out? I'm looking for a correct approach to monitor a cluster as well

@bareksml
Copy link
Author

@dima-sh-papaya unfortunately no

@dima-sh-papaya
Copy link

@dima-sh-papaya unfortunately no

eventually it worked for me with 'srv' record (also was able to run with mongodb:// only but needed to specify '/?ssl=true' and it only allows to insert this param when using single node and not many with comma, so i ended up using the 'srv' record and the key was flags of the exporter, without the correct flags combination it won't work out of the box, very strange stuff but glad i figured it out, will share below).

here's my current mode:

mongodb:
  uri: 'mongodb+srv://<user>:<password>@mycluster.mongodb.net'
extraArgs:
  - '--no-mongodb.direct-connect'
  - '--collector.replicasetstatus=true'
  - '--collector.dbstatsfreestorage=true'
  - '--collector.shards=true'
  - '--collector.currentopmetrics=true'
  - '--collector.topmetrics=true'
  - '--collector.diagnosticdata=true'
  - '--collector.dbstats=true'
  - '--mongodb.global-conn-pool'

these are values of the helm chart i deployed with. so the '--no-mongodb.direct-connect' is mandatory when using 'srv' record (because that record first need to be resolved into the multiple actual shard addresses) and '--mongodb.global-conn-pool' helps to avoid many separate connections but I don't remember if it worked without it or not, I think can work also without. and the collector flags are optional of course, but unless you specify at least one of them, there will be no mongo metrics in the exporter only golang and process metrics of exporter itself.

@dima-sh-papaya
Copy link

the metrics we get are separated by labels with names of shards so there's good stream of metrics and no duplication or any issue, every shard has separate label value, it also shows things like what's primary and secondary replica in labels etc'

for example

# TYPE mongodb_members_optimeWritten_ts untyped
mongodb_members_optimeWritten_ts{cl_id="xxxx",cl_role="",member_idx="atlas-xxxx-shard-00-00.yyyy.mongodb.net:27017",member_state="SECONDARY",rs_nm="atlas-xxxx-shard-0",rs_state="1"} 1.745759172e+09
mongodb_members_optimeWritten_ts{cl_id="xxxx",cl_role="",member_idx="atlas-xxxx-shard-00-01.yyyy.mongodb.net:27017",member_state="PRIMARY",rs_nm="atlas-xxxxx-shard-0",rs_state="1"} 1.745759172e+09
mongodb_members_optimeWritten_ts{cl_id="xxxx",cl_role="",member_idx="atlas-xxxxx-shard-00-02.yyyyy.mongodb.net:27017",member_state="SECONDARY",rs_nm="atlas-xxxxx-shard-0",rs_state="1"} 1.745759172e+09

it's from atlas cloud mongo though, I think for the local one it might need a different setting 🤔 just sharing this because people will land here from google search and it might help someone :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants