Connecting to MongoDB ReplicaSet

The available documentation for MongoDB here is oddly targeted. I’m looking for information on connecting to a ReplicaSet. This doesn’t seem to be covered here or anywhere. Am I missing something obvious?

Nothing in the /python.d/mongodb file, nor the documentation here, nor any Google search result, tells me how to connect to a ReplicaSet. I cannot imagine anyone is using MongoDB and Netdata together in production, while the Mongo is running on a local instance. Anyone doing these things simultaneously should definitely not be allowed to do either. Unfortunately your provided documentation here is only targeted to these wildly irresponsible individuals.

Could someone please just tell me how to fit a ReplicaSet connection string into the /python.d/mongodb file. The fact that the word “Replica” doesn’t even appear in this file is itself feels like a red flag.

I realize you’re using PyMongo for this, and the way that I connect to my cluster with PyMongo is with a string like this:

client = MongoClient('mongodb://user:pass@set-member1:28018,'
                     'set-member2:28018,set-member3:28018',
                     connectTimeoutMS=30000, socketTimeoutMS=None, socketKeepAlive=True, connect=False,
                     maxPoolsize=1, replicaSet='replicaSetName')

According to Mongo’s official documentation, a correctly formed MongoDB URI for ReplicaSets should look like:

mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl

So my /python.d/mongodb file includes this for the connection:

auth:
	name : 'MongoDB - Gnubesoft'
	uri : 'mongodb://mongodb0.example.com:28017,mongodb1.example.com:28017,mongodb0.example.com:28017/?replicaSet=myReplicaSet'
	authdb : 'admin'
	user : 'netdata'
	pass : 'password_goes_here'

There is a further omission from the documentation discussing where this file is supposed to be placed. I have 9 machines in my NetData. 3 of these are members of a MongoDB ReplicaSet cluster. Do I upload this file to all 9 machines? All 3 of the MongoDB ReplicaSet members? Just 1 random machine out of all 9?

After wasting so much time on this problem I just decided to upload the file to everything and restarted netdata on all 9 machines. I have no idea if it worked. I was expecting to see a MongoDB thing pop up in the side of NetData, like Postfix does. There’s nothing new there, and I can’t see any other places to monitor this from so I guess it failed?

Hey,

Thanks for the lengthy and detailed question. The Mongo collector was written a long time ago, and since then we have been meaning to work on radically improving it.

@ilyam8 is the collector magician so he will be able to tell you more about our work.

Would you be interested to help us develop the collector and become a collector supporter? In essence, you can help us in organizing the metrics into meaningful charts and test the collector in a real scenario.

If you have any question about this, please do tell us!

Oh wow, yes I’d be honored to help!

I’ve been using MongoDB as a major part of my database infrastructure since 2016, so I’d be happy to act as a supporter for @ilyam8!

@Gnubesoft hey :wave:

Correct me if I am wrong - ReplicaSet is a primary/secondary (or secondaries) setup. You have several MongoDB instances running on different servers.

Netdata Agent supposed to be installed on every host and gather data from the system and applications running on the server.

It also possible to collect data from remote applications, our external plugins (python.d, go.d) are able to do it.

That is a very nice article that provides the details on the subject. Consider checking it :slightly_smiling_face:

So if you want to monitor several MongoDB instances:

  • (1) install Netdata on every server and collect metrics for local instances (preferred)
  • (2) or install Netdata on one server and collect metrics from local and remote instances

In case 2 you need to create a separate job for every instance in the python.d/mongodb.conf.


You are correct, we are using pymongo library and it supports connecting via MongoDB URI or separate parameters (host, port, ssl, etc.). Our mongodb collector doesn’t MongoDB URI option, unfortunately (i think we never had a request to implement that).

All the supported configuration options can be found in the configuration file itself.

That is an example of a configuration file with 3 jobs, one local and 2 remote:

local:
    authdb: 'admin'
    host : '127.0.0.1'
    port : 27017
    user : 'netdata'
    pass : 'netdata'

remote1:
    authdb: 'admin'
    host : '192.0.2.1'
    port : 27017
    user : 'netdata'
    pass : 'netdata'

remote2:
    authdb: 'admin'
    host : '192.0.2.2'
    port : 27017
    user : 'netdata'
    pass : 'netdata'