Skip to content
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

Monitor all available databases #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
17 changes: 16 additions & 1 deletion mongodb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#
# Plugin to collectd statistics from MongoDB
#
# source: https://github.com/sebest/collectd-mongodb
#

import collectd
from pymongo import MongoClient
Expand All @@ -14,7 +16,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

Expand Down Expand Up @@ -141,6 +143,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)