From 9cbe37897cd91346e82fda4176d2a52c9989177f Mon Sep 17 00:00:00 2001 From: Christian Ferbar <5595808+ferbar@users.noreply.github.com> Date: Wed, 3 Jul 2019 08:01:19 +0200 Subject: [PATCH 1/3] add: auto detect databases --- mongodb.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mongodb.py b/mongodb.py index 7ef82de..24f4c08 100644 --- a/mongodb.py +++ b/mongodb.py @@ -14,7 +14,7 @@ def __init__(self): self.plugin_name = "mongo" self.mongo_host = "127.0.0.1" self.mongo_port = 27017 - self.mongo_db = ["admin", ] + self.mongo_db = ["admin", "*"] self.mongo_user = None self.mongo_password = None @@ -141,6 +141,19 @@ def config(self, obj): else: collectd.warning("mongodb plugin: Unkown configuration key %s" % node.key) + if '*' in self.mongo_db: + collectd.warning("auto detecting databases.....") + con = MongoClient(host=self.mongo_host, port=self.mongo_port, read_preference=ReadPreference.SECONDARY) + db = con[self.mongo_db[0]] + if self.mongo_user and self.mongo_password: + db.authenticate(self.mongo_user, self.mongo_password) + db_list=db.command("listDatabases") + database_list=[] + for d in db_list["databases"]: + collectd.warning("db: %s" % str(d['name'])) + database_list.append(d['name']) + self.mongo_db=database_list + mongodb = MongoDB() collectd.register_read(mongodb.get_db_and_collection_stats) collectd.register_config(mongodb.config) From ecd09e6778271a65dcc03830046c7efb122bd198 Mon Sep 17 00:00:00 2001 From: Christian Ferbar <5595808+ferbar@users.noreply.github.com> Date: Wed, 3 Jul 2019 08:02:24 +0200 Subject: [PATCH 2/3] add: url --- mongodb.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mongodb.py b/mongodb.py index 24f4c08..8049595 100644 --- a/mongodb.py +++ b/mongodb.py @@ -1,6 +1,8 @@ # # Plugin to collectd statistics from MongoDB # +# source: https://github.com/sebest/collectd-mongodb +# import collectd from pymongo import MongoClient From 0e8282abdb366e099a4d175a322c4b750fb00a5a Mon Sep 17 00:00:00 2001 From: Christian Ferbar <5595808+ferbar@users.noreply.github.com> Date: Wed, 3 Jul 2019 08:06:16 +0200 Subject: [PATCH 3/3] Update README.md add: auto detect databases docu --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 425ce21..b98272c 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The plugin has some configuration options even though none are mandatory. This i * Host - hostname or IP address of the mongodb server defaults to 127.0.0.1 * Port - the port of the mongodb server defaults to 27017 * Database - the databases you want to monitor defaults to "admin". You can provide more than one database. Note that the first database _must_ be "admin", as it is used to perform a serverStatus() + "admin" "*" will monitor all databases The following is an example Collectd configuration for this plugin: