From d1ca98563bdba70cc2736d25f5fe2387c1550e4e Mon Sep 17 00:00:00 2001 From: Nicolas Casar Gonzalez Date: Tue, 14 Jun 2016 15:23:56 -0300 Subject: [PATCH 1/3] Fix for pymongo > 3.0 and connection support of MongoClient only https://api.mongodb.com/python/current/changelog.html#mongoclient-changes --- plugins/mongodb/mongo_lag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mongodb/mongo_lag b/plugins/mongodb/mongo_lag index b70837fc..a54c0f50 100755 --- a/plugins/mongodb/mongo_lag +++ b/plugins/mongodb/mongo_lag @@ -25,7 +25,7 @@ import pymongo def _get_members(): host = os.environ.get('host', '127.0.0.1') port = os.environ.get('port', 27017) - conn = pymongo.Connection(host,port) + conn = pymongo.MongoClient(host,port) repl_status = conn.admin.command("replSetGetStatus") members = {} From 887063d53c434cdfd07f516ebcba88477899cae5 Mon Sep 17 00:00:00 2001 From: Nico Casar Gonzalez Date: Wed, 15 Jun 2016 00:28:38 -0300 Subject: [PATCH 2/3] Fix for pymongo > 3.0 and connection support of MongoClient https://api.mongodb.com/python/current/changelog.html#mongoclient-changes --- plugins/mongodb/mongo_collection_ | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/mongodb/mongo_collection_ b/plugins/mongodb/mongo_collection_ index baea31ae..a0b73653 100644 --- a/plugins/mongodb/mongo_collection_ +++ b/plugins/mongodb/mongo_collection_ @@ -1,4 +1,4 @@ -#!/usr/bin/env /usr/local/bin/python2 +#!/usr/bin/env python # -*- coding: utf-8 -*- # vim: set sts=4 sw=4 encoding=utf-8 @@ -33,7 +33,7 @@ #%# capabilities=suggest autoconf -from pymongo import Connection +import pymongo from operator import itemgetter settings_host = '127.0.0.1' @@ -50,6 +50,7 @@ typeIndex['collcount']['title'] = 'per collection document count' typeIndex['collcount']['yaxis'] = 'documents' typeIndex['collcount']['base'] = '1000' typeIndex['collcount']['scale'] = '--logarithmic -l1' +typeIndex['collcount']['category'] = 'MongoDB' typeIndex['collsize'] = {} typeIndex['collsize']['index'] = 'size' @@ -57,6 +58,7 @@ typeIndex['collsize']['title'] = 'per collection data size' typeIndex['collsize']['yaxis'] = 'Byte' typeIndex['collsize']['base'] = '1024' typeIndex['collsize']['scale'] = '--logarithmic -l1 --units=si' +typeIndex['collsize']['category'] = 'MongoDB' typeIndex['avgsize'] = {} typeIndex['avgsize']['index'] = 'avgObjSize' @@ -64,6 +66,7 @@ typeIndex['avgsize']['title'] = 'average object size' typeIndex['avgsize']['yaxis'] = 'Byte' typeIndex['avgsize']['base'] = '1024' typeIndex['avgsize']['scale'] = '--logarithmic --units=si' +typeIndex['avgsize']['category'] = 'MongoDB' typeIndex['storage'] = {} typeIndex['storage']['index'] = 'storageSize' @@ -71,6 +74,7 @@ typeIndex['storage']['title'] = 'per collection storage size' typeIndex['storage']['yaxis'] = 'Byte' typeIndex['storage']['base'] = '1024' typeIndex['storage']['scale'] = '--logarithmic -l1 --units=si' +typeIndex['storage']['category'] = 'MongoDB' typeIndex['indexsize'] = {} typeIndex['indexsize']['index'] = 'totalIndexSize' @@ -78,11 +82,11 @@ typeIndex['indexsize']['title'] = 'per collection index size' typeIndex['indexsize']['yaxis'] = 'Byte' typeIndex['indexsize']['base'] = '1024' typeIndex['indexsize']['scale'] = '--logarithmic -l 1 --units=si' - +typeIndex['indexsize']['category'] = 'MongoDB' def getCollstats(graphtype): - con = Connection(settings_host, int(settings_port), slave_okay=True) + con = pymongo.MongoClient(settings_host, int(settings_port)) if settings_user: db = con['admin'] @@ -106,7 +110,7 @@ def getCollstats(graphtype): stats_tmp[collname]['value'] += long(stats[typeIndex[graphtype]['index']]) - con.disconnect() + con.close() for collname, item in sorted(stats_tmp.items()): yield ("%s" % collname, item['value'], item['dbname']) From 9121b90ee0baff9c88739c68b01bf6c4ed1fa22e Mon Sep 17 00:00:00 2001 From: Nico Casar Gonzalez Date: Thu, 18 Aug 2016 19:27:04 -0300 Subject: [PATCH 3/3] added mongodb URI for configuration defining settings_mongodb_uri will override settings_host and settings_port --- plugins/mongodb/mongo_collection_ | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/mongodb/mongo_collection_ b/plugins/mongodb/mongo_collection_ index a0b73653..67024d19 100644 --- a/plugins/mongodb/mongo_collection_ +++ b/plugins/mongodb/mongo_collection_ @@ -38,6 +38,8 @@ from operator import itemgetter settings_host = '127.0.0.1' settings_port = 27017 +# mongodb_uri will override host and port +settings_mongodb_uri = '' settings_db = 'mydb' settings_user = '' settings_password = '' @@ -86,7 +88,10 @@ typeIndex['indexsize']['category'] = 'MongoDB' def getCollstats(graphtype): - con = pymongo.MongoClient(settings_host, int(settings_port)) + if settings_mongodb_uri: + con = pymongo.MongoClient(settings_mongodb_uri) + else: + con = pymongo.MongoClient(settings_host, int(settings_port)) if settings_user: db = con['admin']