2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Fix for pymongo > 3.0 and connection support of MongoClient

https://api.mongodb.com/python/current/changelog.html#mongoclient-changes
This commit is contained in:
Nico Casar Gonzalez 2016-06-15 00:28:38 -03:00
parent d1ca98563b
commit 887063d53c

View File

@ -1,4 +1,4 @@
#!/usr/bin/env /usr/local/bin/python2 #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: set sts=4 sw=4 encoding=utf-8 # vim: set sts=4 sw=4 encoding=utf-8
@ -33,7 +33,7 @@
#%# capabilities=suggest autoconf #%# capabilities=suggest autoconf
from pymongo import Connection import pymongo
from operator import itemgetter from operator import itemgetter
settings_host = '127.0.0.1' settings_host = '127.0.0.1'
@ -50,6 +50,7 @@ typeIndex['collcount']['title'] = 'per collection document count'
typeIndex['collcount']['yaxis'] = 'documents' typeIndex['collcount']['yaxis'] = 'documents'
typeIndex['collcount']['base'] = '1000' typeIndex['collcount']['base'] = '1000'
typeIndex['collcount']['scale'] = '--logarithmic -l1' typeIndex['collcount']['scale'] = '--logarithmic -l1'
typeIndex['collcount']['category'] = 'MongoDB'
typeIndex['collsize'] = {} typeIndex['collsize'] = {}
typeIndex['collsize']['index'] = 'size' typeIndex['collsize']['index'] = 'size'
@ -57,6 +58,7 @@ typeIndex['collsize']['title'] = 'per collection data size'
typeIndex['collsize']['yaxis'] = 'Byte' typeIndex['collsize']['yaxis'] = 'Byte'
typeIndex['collsize']['base'] = '1024' typeIndex['collsize']['base'] = '1024'
typeIndex['collsize']['scale'] = '--logarithmic -l1 --units=si' typeIndex['collsize']['scale'] = '--logarithmic -l1 --units=si'
typeIndex['collsize']['category'] = 'MongoDB'
typeIndex['avgsize'] = {} typeIndex['avgsize'] = {}
typeIndex['avgsize']['index'] = 'avgObjSize' typeIndex['avgsize']['index'] = 'avgObjSize'
@ -64,6 +66,7 @@ typeIndex['avgsize']['title'] = 'average object size'
typeIndex['avgsize']['yaxis'] = 'Byte' typeIndex['avgsize']['yaxis'] = 'Byte'
typeIndex['avgsize']['base'] = '1024' typeIndex['avgsize']['base'] = '1024'
typeIndex['avgsize']['scale'] = '--logarithmic --units=si' typeIndex['avgsize']['scale'] = '--logarithmic --units=si'
typeIndex['avgsize']['category'] = 'MongoDB'
typeIndex['storage'] = {} typeIndex['storage'] = {}
typeIndex['storage']['index'] = 'storageSize' typeIndex['storage']['index'] = 'storageSize'
@ -71,6 +74,7 @@ typeIndex['storage']['title'] = 'per collection storage size'
typeIndex['storage']['yaxis'] = 'Byte' typeIndex['storage']['yaxis'] = 'Byte'
typeIndex['storage']['base'] = '1024' typeIndex['storage']['base'] = '1024'
typeIndex['storage']['scale'] = '--logarithmic -l1 --units=si' typeIndex['storage']['scale'] = '--logarithmic -l1 --units=si'
typeIndex['storage']['category'] = 'MongoDB'
typeIndex['indexsize'] = {} typeIndex['indexsize'] = {}
typeIndex['indexsize']['index'] = 'totalIndexSize' typeIndex['indexsize']['index'] = 'totalIndexSize'
@ -78,11 +82,11 @@ typeIndex['indexsize']['title'] = 'per collection index size'
typeIndex['indexsize']['yaxis'] = 'Byte' typeIndex['indexsize']['yaxis'] = 'Byte'
typeIndex['indexsize']['base'] = '1024' typeIndex['indexsize']['base'] = '1024'
typeIndex['indexsize']['scale'] = '--logarithmic -l 1 --units=si' typeIndex['indexsize']['scale'] = '--logarithmic -l 1 --units=si'
typeIndex['indexsize']['category'] = 'MongoDB'
def getCollstats(graphtype): def getCollstats(graphtype):
con = Connection(settings_host, int(settings_port), slave_okay=True) con = pymongo.MongoClient(settings_host, int(settings_port))
if settings_user: if settings_user:
db = con['admin'] db = con['admin']
@ -106,7 +110,7 @@ def getCollstats(graphtype):
stats_tmp[collname]['value'] += long(stats[typeIndex[graphtype]['index']]) stats_tmp[collname]['value'] += long(stats[typeIndex[graphtype]['index']])
con.disconnect() con.close()
for collname, item in sorted(stats_tmp.items()): for collname, item in sorted(stats_tmp.items()):
yield ("%s" % collname, item['value'], item['dbname']) yield ("%s" % collname, item['value'], item['dbname'])