89 lines
1.8 KiB
Python
Executable File
89 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
=head1 NAME
|
|
|
|
mongo_ops - MongoDB ops Plugin
|
|
|
|
=head1 APPLICABLE SYSTEMS
|
|
|
|
MongoDB 3.X and 4.X with pymongo installed.
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
Default 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>
|
|
|
|
=cut
|
|
"""
|
|
|
|
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["opcounters"].items():
|
|
print( str(k) + ".value " + str(v) )
|
|
|
|
|
|
def doConfig():
|
|
print("""
|
|
graph_title MongoDB ops
|
|
graph_args --base 1000 -l 0
|
|
graph_vlabel ops / ${graph_period}
|
|
graph_category db
|
|
graph_total total
|
|
""")
|
|
|
|
for k in getServerStatus()["opcounters"]:
|
|
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()
|