mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Update mongodb plugins
* Update mongodb plugins * fix category * chmod +x * flake8-CI * flake8 adjustments for mongo_collection_ and env python3
This commit is contained in:
parent
52144bc277
commit
276169a6c9
9 changed files with 360 additions and 146 deletions
|
@ -1,6 +1,22 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
=head1 NAME
|
||||||
|
MongoDB btree Plugin
|
||||||
|
|
||||||
## GENERATED FILE - DO NOT EDIT
|
=head1 APPLICABLE SYSTEMS
|
||||||
|
|
||||||
|
Works until MongoDB 2.7. The "indexCounters" field was removed in 2.8 version.
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
[mongo_btree]
|
||||||
|
env.MONGO_DB_URI mongodb://user:password@host:port/dbname
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Original script there : https://github.com/comerford/mongo-munin
|
||||||
|
Doc added by Alban Espie-Guillon <alban.espie@alterway.fr>
|
||||||
|
"""
|
||||||
|
|
||||||
import urllib2
|
import urllib2
|
||||||
import sys
|
import sys
|
||||||
|
@ -50,5 +66,3 @@ if __name__ == "__main__":
|
||||||
doConfig()
|
doConfig()
|
||||||
else:
|
else:
|
||||||
doData()
|
doData()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vim: set sts=4 sw=4 encoding=utf-8
|
# vim: set sts=4 sw=4 encoding=utf-8
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#%# family=auto
|
# #%# family=auto
|
||||||
#%# capabilities=suggest autoconf
|
# #%# capabilities=suggest autoconf
|
||||||
|
|
||||||
|
|
||||||
import pymongo
|
import pymongo
|
||||||
|
@ -40,7 +40,7 @@ settings_host = '127.0.0.1'
|
||||||
settings_port = 27017
|
settings_port = 27017
|
||||||
# mongodb_uri will override host and port
|
# mongodb_uri will override host and port
|
||||||
settings_mongodb_uri = ''
|
settings_mongodb_uri = ''
|
||||||
settings_db = 'mydb'
|
settings_db = 'admin'
|
||||||
settings_user = ''
|
settings_user = ''
|
||||||
settings_password = ''
|
settings_password = ''
|
||||||
settings_ignoredb = {}
|
settings_ignoredb = {}
|
||||||
|
@ -88,98 +88,97 @@ typeIndex['indexsize']['category'] = 'db'
|
||||||
|
|
||||||
|
|
||||||
def getCollstats(graphtype):
|
def getCollstats(graphtype):
|
||||||
if settings_mongodb_uri:
|
if settings_mongodb_uri:
|
||||||
con = pymongo.MongoClient(settings_mongodb_uri)
|
con = pymongo.MongoClient(settings_mongodb_uri)
|
||||||
else:
|
else:
|
||||||
con = pymongo.MongoClient(settings_host, int(settings_port))
|
con = pymongo.MongoClient(settings_host, int(settings_port))
|
||||||
|
|
||||||
if settings_user:
|
if settings_user:
|
||||||
db = con['admin']
|
db = con[settings_db]
|
||||||
db.authenticate(settings_user, settings_password)
|
db.authenticate(settings_user, settings_password)
|
||||||
|
|
||||||
stats_tmp = {}
|
stats_tmp = {}
|
||||||
for dbname in con.database_names():
|
for dbname in con.list_database_names():
|
||||||
if dbname in settings_ignoredb:
|
if dbname in settings_ignoredb:
|
||||||
continue
|
continue
|
||||||
db = con[dbname]
|
db = con[dbname]
|
||||||
for coll in db.collection_names():
|
for coll in db.list_collection_names():
|
||||||
if coll.startswith('system.'):
|
if coll.startswith('system.'):
|
||||||
continue
|
continue
|
||||||
stats = db.command("collstats", coll)
|
stats = db.command("collstats", coll)
|
||||||
collname = dbname + "_" + coll.replace('.', '_')
|
collname = dbname + "_" + coll.replace('.', '_')
|
||||||
if not stats_tmp.has_key(collname):
|
if collname not in stats_tmp:
|
||||||
stats_tmp[collname] = {}
|
stats_tmp[collname] = {}
|
||||||
stats_tmp[collname]['value'] = 0
|
stats_tmp[collname]['value'] = 0
|
||||||
stats_tmp[collname]['dbname'] = dbname
|
stats_tmp[collname]['dbname'] = dbname
|
||||||
if typeIndex[graphtype]['index'] in stats:
|
if typeIndex[graphtype]['index'] in stats:
|
||||||
stats_tmp[collname]['value'] += long(stats[typeIndex[graphtype]['index']])
|
stats_tmp[collname]['value'] += int(stats[typeIndex[graphtype]['index']])
|
||||||
|
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
for collname, item in sorted(stats_tmp.items()):
|
||||||
|
yield ("%s" % collname, item['value'], item['dbname'])
|
||||||
|
|
||||||
|
|
||||||
con.close()
|
def doData(base, graphtype):
|
||||||
|
|
||||||
for collname, item in sorted(stats_tmp.items()):
|
|
||||||
yield ("%s" % collname, item['value'], item['dbname'])
|
|
||||||
|
|
||||||
|
|
||||||
def doData(base,graphtype):
|
|
||||||
lastdb = ""
|
lastdb = ""
|
||||||
for coll, stats, db in sorted(getCollstats(graphtype), key=itemgetter(2)):
|
for coll, stats, db in sorted(getCollstats(graphtype), key=itemgetter(2)):
|
||||||
if lastdb != db:
|
if lastdb != db:
|
||||||
print "multigraph " + base + "_" + graphtype + "_" + db
|
print("multigraph " + base + "_" + graphtype + "_" + db)
|
||||||
lastdb = db
|
lastdb = db
|
||||||
print "%s_%s.value %s" % (graphtype, coll, stats)
|
print("%s_%s.value %s" % (graphtype, coll, stats))
|
||||||
|
|
||||||
|
|
||||||
def doConfig(base,graphtype):
|
def doConfig(base, graphtype):
|
||||||
|
|
||||||
lastdb = ""
|
lastdb = ""
|
||||||
for k,v,d in sorted(getCollstats(graphtype), key=itemgetter(2)):
|
for k, v, d in sorted(getCollstats(graphtype), key=itemgetter(2)):
|
||||||
if lastdb != d:
|
if lastdb != d:
|
||||||
print "multigraph " + base + "_" + graphtype + "_" + d
|
print("multigraph " + base + "_" + graphtype + "_" + d)
|
||||||
lastdb = d
|
lastdb = d
|
||||||
# print "graph_total total"
|
print("graph_title MongoDB " + typeIndex[graphtype]['title'] + " for database " + d)
|
||||||
print "graph_title MongoDB " + typeIndex[graphtype]['title'] + " for database " + d
|
print("graph_args --base " + typeIndex[graphtype]['base'] + " " + typeIndex[graphtype]['scale'])
|
||||||
print "graph_args --base " + typeIndex[graphtype]['base'] + " " + typeIndex[graphtype]['scale']
|
print("graph_vlabel " + typeIndex[graphtype]['yaxis'])
|
||||||
print "graph_vlabel " + typeIndex[graphtype]['yaxis']
|
print("graph_category db")
|
||||||
print "graph_category db"
|
print("%s_%s.label %s" % (graphtype, k, k))
|
||||||
print "%s_%s.label %s" % (graphtype, k, k)
|
print("%s_%s.min 0" % (graphtype, k))
|
||||||
print "%s_%s.min 0" % (graphtype, k)
|
print("%s_%s.draw LINE1" % (graphtype, k))
|
||||||
print "%s_%s.draw LINE1" % (graphtype, k)
|
|
||||||
|
|
||||||
def doSuggest():
|
def doSuggest():
|
||||||
print "keys"
|
print("keys")
|
||||||
for k in typeIndex.keys():
|
for k in typeIndex.keys():
|
||||||
print k
|
print(k)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from sys import argv,exit
|
from sys import argv, exit
|
||||||
from os import environ,path
|
from os import environ, path
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# Could be done by a for loop
|
# Could be done by a for loop
|
||||||
# but i think if's are faster
|
# but i think if's are faster
|
||||||
if 'HOST' in environ:
|
if 'host' in environ:
|
||||||
settings_host = environ['HOST']
|
settings_host = environ['host']
|
||||||
if 'PORT' in environ:
|
if 'port' in environ:
|
||||||
settings_port = environ['PORT']
|
settings_port = environ['port']
|
||||||
if 'DB' in environ:
|
if 'db' in environ:
|
||||||
settings_db = environ['DB']
|
settings_db = environ['db']
|
||||||
if 'MONGO_USER' in environ:
|
if 'username' in environ:
|
||||||
settings_user = environ['MONGO_USER']
|
settings_user = environ['username']
|
||||||
if 'PASSWORD' in environ:
|
if 'password' in environ:
|
||||||
settings_password = environ['PASSWORD']
|
settings_password = environ['password']
|
||||||
if 'IGNOREDB' in environ:
|
if 'ignoredb' in environ:
|
||||||
settings_ignoredb = environ['IGNOREDB'].split(',')
|
settings_ignoredb = environ['ignoredb'].split(',')
|
||||||
m = re.search('^(.*)_([a-zA-Z0-9]*)$', path.basename(argv[0]))
|
m = re.search('^(.*)_([a-zA-Z0-9]*)$', path.basename(argv[0]))
|
||||||
if len(argv) < 2:
|
if len(argv) < 2:
|
||||||
doData(m.group(1),m.group(2))
|
doData(m.group(1), m.group(2))
|
||||||
elif argv[1] == "config":
|
elif argv[1] == "config":
|
||||||
doConfig(m.group(1),m.group(2))
|
doConfig(m.group(1), m.group(2))
|
||||||
elif argv[1] == "autoconf":
|
elif argv[1] == "autoconf":
|
||||||
print "yes"
|
print("yes")
|
||||||
elif argv[1] == "suggest":
|
elif argv[1] == "suggest":
|
||||||
doSuggest()
|
doSuggest()
|
||||||
else:
|
else:
|
||||||
print "invalid argument"
|
print("invalid argument")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
=head1 NAME
|
||||||
|
MongoDB connections Plugin
|
||||||
|
|
||||||
## GENERATED FILE - DO NOT EDIT
|
=head1 APPLICABLE SYSTEMS
|
||||||
|
|
||||||
|
Works until MongoDB 3.6. The httpinterface was later removed.
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
[mongo_lock]
|
||||||
|
env.MONGO_DB_URI mongodb://user:password@host:port/dbname
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Original script there : https://github.com/comerford/mongo-munin
|
||||||
|
Doc added by Alban Espie-Guillon <alban.espie@alterway.fr>
|
||||||
|
"""
|
||||||
|
|
||||||
import urllib2
|
import urllib2
|
||||||
import sys
|
import sys
|
||||||
|
@ -40,5 +56,3 @@ if __name__ == "__main__":
|
||||||
doConfig()
|
doConfig()
|
||||||
else:
|
else:
|
||||||
doData()
|
doData()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,38 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
|
=head1 NAME
|
||||||
MongoDB Replication Lag
|
MongoDB Replication Lag
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Connects to a single mongo instance and retrieve
|
Connects to a single mongo instance and retrieve
|
||||||
replication lag for all connected members.
|
replication lag for all connected members.
|
||||||
|
|
||||||
munin-node.conf:
|
=head1 APPLICABLE SYSTEMS
|
||||||
|
|
||||||
|
MongoDB 3.X and 4.X with pymongo installed.
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
munin-node.conf
|
||||||
|
defauts for host is 127.0.0.1 and port 27017
|
||||||
|
and will work without being defined :
|
||||||
|
|
||||||
[mongo_lag]
|
[mongo_lag]
|
||||||
env.host 127.0.0.1
|
env.host 127.0.0.1
|
||||||
env.port 27017
|
env.port 27017
|
||||||
env.username user
|
env.username user
|
||||||
env.password P@55w0rd
|
env.password P@55w0rd
|
||||||
|
|
||||||
:author: Stefan Andersen <stefan@stefanandersen.dk>
|
=head1 AUTHOR
|
||||||
:license: The Beer Ware License (Revision 42)
|
|
||||||
<stefan@stefanandersen.dk> wrote this file. As long
|
Stefan Andersen <stefan@stefanandersen.dk>
|
||||||
as you retain this notice you can do whatever you want
|
Updated by Alban Espie-Guillon <alban.espie@alterway.fr>
|
||||||
with this stuff. If we meet some day, and you think
|
|
||||||
this stuff is worth it, you can buy me a beer in return.
|
=head1 LICENSE
|
||||||
|
The Beer Ware License (Revision 42)
|
||||||
|
<alban.espie@alterway.fr> wrote this file. As long
|
||||||
|
as you retain this notice you can do whatever you want
|
||||||
|
with this stuff. If we meet some day, and you think
|
||||||
|
this stuff is worth it, you can buy me a beer in return.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -33,7 +47,7 @@ def _get_members():
|
||||||
if username:
|
if username:
|
||||||
connAuth = conn['admin']
|
connAuth = conn['admin']
|
||||||
connAuth.authenticate(username, password)
|
connAuth.authenticate(username, password)
|
||||||
|
|
||||||
repl_status = conn.admin.command("replSetGetStatus")
|
repl_status = conn.admin.command("replSetGetStatus")
|
||||||
|
|
||||||
members = {}
|
members = {}
|
||||||
|
@ -51,17 +65,17 @@ def run():
|
||||||
|
|
||||||
for member in members:
|
for member in members:
|
||||||
lag = (primary_optime - members[member]['optimeDate']).seconds
|
lag = (primary_optime - members[member]['optimeDate']).seconds
|
||||||
print "{0}.value {1}".format(member, lag)
|
print("{0}.value {1}".format(member, lag))
|
||||||
|
|
||||||
def config():
|
def config():
|
||||||
print """graph_title MongoDB replication lag
|
print("""graph_title MongoDB replication lag
|
||||||
graph_args --base 1000
|
graph_args --base 1000
|
||||||
graph_vlabel Replication lag (seconds)
|
graph_vlabel Replication lag (seconds)
|
||||||
graph_category db
|
graph_category db
|
||||||
"""
|
""")
|
||||||
|
|
||||||
for member in _get_members():
|
for member in _get_members():
|
||||||
print "{0}.label {0}".format(member)
|
print("{0}.label {0}".format(member))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
=head1 NAME
|
||||||
|
MongoDB lock Plugin
|
||||||
|
|
||||||
## GENERATED FILE - DO NOT EDIT
|
=head1 APPLICABLE SYSTEMS
|
||||||
|
|
||||||
|
MongoDB 2.X. The "lockTime" field was removed in later versions.
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
[mongo_lock]
|
||||||
|
env.MONGO_DB_URI mongodb://user:password@host:port/dbname
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Original script there : https://github.com/comerford/mongo-munin
|
||||||
|
Doc added by Alban Espie-Guillon <alban.espie@alterway.fr>
|
||||||
|
"""
|
||||||
|
|
||||||
import urllib2
|
import urllib2
|
||||||
import sys
|
import sys
|
||||||
|
@ -47,5 +63,3 @@ if __name__ == "__main__":
|
||||||
doConfig()
|
doConfig()
|
||||||
else:
|
else:
|
||||||
doData()
|
doData()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,49 +1,83 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
=head1 NAME
|
||||||
|
MongoDB mem Plugin
|
||||||
|
|
||||||
## GENERATED FILE - DO NOT EDIT
|
=head1 APPLICABLE SYSTEMS
|
||||||
|
|
||||||
import urllib2
|
MongoDB 3.X and 4.X with pymongo installed.
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
munin-node.conf
|
||||||
|
defauts for host is 127.0.0.1 and port 27017
|
||||||
|
and will work without being defined :
|
||||||
|
|
||||||
|
[mongo_mem]
|
||||||
|
env.host 127.0.0.1
|
||||||
|
env.port 27017
|
||||||
|
env.username user
|
||||||
|
env.password P@55w0rd
|
||||||
|
env.db dbname
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
[mongodb_mem]
|
||||||
|
env.MONGO_DB_URI mongodb://user:password@host:port/dbname
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Original script there : https://github.com/comerford/mongo-munin
|
||||||
|
Updated by Alban Espie-Guillon <alban.espie@alterway.fr>
|
||||||
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
try:
|
import pymongo
|
||||||
import json
|
|
||||||
except ImportError:
|
|
||||||
import simplejson as json
|
|
||||||
|
|
||||||
|
|
||||||
def getServerStatus():
|
def getServerStatus():
|
||||||
raw = urllib2.urlopen( "http://127.0.0.1:28017/_status" ).read()
|
if 'MONGO_DB_URI' in os.environ:
|
||||||
return json.loads( raw )["serverStatus"]
|
c = pymongo.MongoClient(os.environ['MONGO_DB_URI'])
|
||||||
|
|
||||||
|
elif 'username' and 'password' in os.environ:
|
||||||
|
host = os.environ.get('host', '127.0.0.1')
|
||||||
|
port = os.environ.get('port', 27017)
|
||||||
|
username = os.environ.get('username', '')
|
||||||
|
password = os.environ.get('password', '')
|
||||||
|
c = pymongo.MongoClient(host, int(port))
|
||||||
|
if username:
|
||||||
|
cAuth = c['admin']
|
||||||
|
cAuth.authenticate(username, password)
|
||||||
|
|
||||||
|
else:
|
||||||
|
c = pymongo.MongoClient()
|
||||||
|
|
||||||
|
return c.admin.command('serverStatus', workingSet=True)
|
||||||
|
|
||||||
def ok(s):
|
def ok(s):
|
||||||
return s == "resident" or s == "virtual" or s == "mapped"
|
return s == "resident" or s == "virtual" or s == "mapped"
|
||||||
|
|
||||||
def doData():
|
def doData():
|
||||||
for k,v in getServerStatus()["mem"].iteritems():
|
for k,v in getServerStatus()["mem"].items():
|
||||||
if ok(k):
|
if ok(k):
|
||||||
print( str(k) + ".value " + str(v * 1024 * 1024) )
|
print( str(k) + ".value " + str(v * 1024 * 1024) )
|
||||||
|
|
||||||
def doConfig():
|
|
||||||
|
|
||||||
print "graph_title MongoDB memory usage"
|
def doConfig():
|
||||||
print "graph_args --base 1024 -l 0 --vertical-label Bytes"
|
print("""
|
||||||
print "graph_category db"
|
graph_title MongoDB memory usage
|
||||||
|
graph_args --base 1024 -l 0 --vertical-label Bytes
|
||||||
|
graph_category mongodb
|
||||||
|
""")
|
||||||
|
|
||||||
for k in getServerStatus()["mem"]:
|
for k in getServerStatus()["mem"]:
|
||||||
if ok( k ):
|
if ok( k ):
|
||||||
print k + ".label " + k
|
print(k + ".label " + k)
|
||||||
print k + ".draw LINE1"
|
print(k + ".draw LINE1")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
||||||
doConfig()
|
doConfig()
|
||||||
else:
|
else:
|
||||||
doData()
|
doData()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,45 +1,85 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
=head1 NAME
|
||||||
|
MongoDB ops Plugin
|
||||||
|
|
||||||
## GENERATED FILE - DO NOT EDIT
|
=head1 APPLICABLE SYSTEMS
|
||||||
|
|
||||||
import urllib2
|
MongoDB 3.X and 4.X with pymongo installed.
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
munin-node.conf
|
||||||
|
defauts for host is 127.0.0.1 and port 27017
|
||||||
|
and will work without being defined :
|
||||||
|
|
||||||
|
[mongodb_ops]
|
||||||
|
env.host 127.0.0.1
|
||||||
|
env.port 27017
|
||||||
|
env.username user
|
||||||
|
env.password P@55w0rd
|
||||||
|
env.db dbname
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
[mongodb_ops]
|
||||||
|
env.MONGO_DB_URI mongodb://user:password@host:port/dbname
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Original script there : https://github.com/comerford/mongo-munin
|
||||||
|
Updated by Alban Espie-Guillon <alban.espie@alterway.fr>
|
||||||
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
try:
|
import pymongo
|
||||||
import json
|
|
||||||
except ImportError:
|
|
||||||
import simplejson as json
|
|
||||||
|
|
||||||
|
|
||||||
def getServerStatus():
|
def getServerStatus():
|
||||||
raw = urllib2.urlopen( "http://127.0.0.1:28017/_status" ).read()
|
if 'MONGO_DB_URI' in os.environ:
|
||||||
return json.loads( raw )["serverStatus"]
|
c = pymongo.MongoClient(os.environ['MONGO_DB_URI'])
|
||||||
|
|
||||||
|
elif 'username' and 'password' in os.environ:
|
||||||
|
host = os.environ.get('host', '127.0.0.1')
|
||||||
|
port = os.environ.get('port', 27017)
|
||||||
|
username = os.environ.get('username', '')
|
||||||
|
password = os.environ.get('password', '')
|
||||||
|
c = pymongo.MongoClient(host, int(port))
|
||||||
|
if username:
|
||||||
|
cAuth = c['admin']
|
||||||
|
cAuth.authenticate(username, password)
|
||||||
|
|
||||||
|
else:
|
||||||
|
c = pymongo.MongoClient()
|
||||||
|
|
||||||
|
return c.admin.command('serverStatus', workingSet=True)
|
||||||
|
|
||||||
|
|
||||||
def doData():
|
def doData():
|
||||||
ss = getServerStatus()
|
ss = getServerStatus()
|
||||||
for k,v in ss["opcounters"].iteritems():
|
for k,v in ss["opcounters"].items():
|
||||||
print( str(k) + ".value " + str(v) )
|
print( str(k) + ".value " + str(v) )
|
||||||
|
|
||||||
def doConfig():
|
|
||||||
|
|
||||||
print "graph_title MongoDB ops"
|
def doConfig():
|
||||||
print "graph_args --base 1000 -l 0"
|
print("""
|
||||||
print "graph_vlabel ops / ${graph_period}"
|
graph_title MongoDB ops
|
||||||
print "graph_category db"
|
graph_args --base 1000 -l 0
|
||||||
print "graph_total total"
|
graph_vlabel ops / ${graph_period}
|
||||||
|
graph_category db
|
||||||
|
graph_total total
|
||||||
|
""")
|
||||||
|
|
||||||
for k in getServerStatus()["opcounters"]:
|
for k in getServerStatus()["opcounters"]:
|
||||||
print k + ".label " + k
|
print(k + ".label " + k)
|
||||||
print k + ".min 0"
|
print(k + ".min 0")
|
||||||
print k + ".type COUNTER"
|
print(k + ".type COUNTER")
|
||||||
print k + ".max 500000"
|
print(k + ".max 500000")
|
||||||
print k + ".draw LINE1"
|
print(k + ".draw LINE1")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
||||||
doConfig()
|
doConfig()
|
||||||
else:
|
else:
|
||||||
doData()
|
doData()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,8 @@ def _get_connections():
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
connections = _get_connections()
|
connections = _get_connections()
|
||||||
for connection, value in connections.items():
|
for c, v in connections.items():
|
||||||
print(connection + ".value", value)
|
print(str(c) + ".value " + str(v))
|
||||||
|
|
||||||
|
|
||||||
def config():
|
def config():
|
||||||
|
|
85
plugins/mongodb/mongodb_docs
Executable file
85
plugins/mongodb/mongodb_docs
Executable file
|
@ -0,0 +1,85 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
=head1 NAME
|
||||||
|
MongoDB docs Plugin
|
||||||
|
|
||||||
|
=head1 APPLICABLE SYSTEMS
|
||||||
|
|
||||||
|
MongoDB 3.X and 4.X with pymongo installed.
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
munin-node.conf
|
||||||
|
defauts for host is 127.0.0.1 and port 27017
|
||||||
|
and will work without being defined :
|
||||||
|
|
||||||
|
[mongodb_docs]
|
||||||
|
env.host 127.0.0.1
|
||||||
|
env.port 27017
|
||||||
|
env.username user
|
||||||
|
env.password P@55w0rd
|
||||||
|
env.db dbname
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
[mongodb_docs]
|
||||||
|
env.MONGO_DB_URI mongodb://user:password@host:port/dbname
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Original script there : https://github.com/comerford/mongo-munin
|
||||||
|
Updated by Alban Espie-Guillon <alban.espie@alterway.fr>
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import pymongo
|
||||||
|
|
||||||
|
|
||||||
|
def getServerStatus():
|
||||||
|
if 'MONGO_DB_URI' in os.environ:
|
||||||
|
c = pymongo.MongoClient(os.environ['MONGO_DB_URI'])
|
||||||
|
|
||||||
|
elif 'username' and 'password' in os.environ:
|
||||||
|
host = os.environ.get('host', '127.0.0.1')
|
||||||
|
port = os.environ.get('port', 27017)
|
||||||
|
username = os.environ.get('username', '')
|
||||||
|
password = os.environ.get('password', '')
|
||||||
|
c = pymongo.MongoClient(host, int(port))
|
||||||
|
if username:
|
||||||
|
cAuth = c['admin']
|
||||||
|
cAuth.authenticate(username, password)
|
||||||
|
|
||||||
|
else:
|
||||||
|
c = pymongo.MongoClient()
|
||||||
|
|
||||||
|
return c.admin.command('serverStatus', workingSet=True)
|
||||||
|
|
||||||
|
|
||||||
|
def doData():
|
||||||
|
ss = getServerStatus()
|
||||||
|
for k, v in ss["metrics"]["document"].items():
|
||||||
|
print(str(k) + ".value " + str(v))
|
||||||
|
|
||||||
|
|
||||||
|
def doConfig():
|
||||||
|
print("""
|
||||||
|
graph_title MongoDB documents
|
||||||
|
graph_args --base 1000 -l 0
|
||||||
|
graph_vlabel documents
|
||||||
|
graph_category db
|
||||||
|
""")
|
||||||
|
|
||||||
|
for k in getServerStatus()["metrics"]["document"]:
|
||||||
|
print(k + ".label " + k)
|
||||||
|
print(k + ".min 0")
|
||||||
|
print(k + ".type COUNTER")
|
||||||
|
print(k + ".max 500000")
|
||||||
|
print(k + ".draw LINE1")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
||||||
|
doConfig()
|
||||||
|
else:
|
||||||
|
doData()
|
Loading…
Add table
Add a link
Reference in a new issue