mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51: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
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