NAME MongoDB Connection Count Plugin


    MongoDB 3.X and 4.X with pymongo installed.


    defaults for host is and port 27017
    and will work without being defined :

    env.port 27017
    env.username user
    env.password P@55w0rd


    Alban Espie-Guillon <>
    based on Stefan Andersen <> work.

LICENSE The Beer Ware License (Revision 42) <> 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 sys import pymongo

def _get_connections(): host = os.environ.get('host', '') port = os.environ.get('port', 27017) username = os.environ.get('username', '') password = os.environ.get('password', '') conn = pymongo.MongoClient(host, int(port)) if username: connAuth = conn['admin'] connAuth.authenticate(username, password)

    """ cli : db.serverStatus().connections """
    conn_status = conn.admin.command("serverStatus")['connections']
    return conn_status

def run(): connections = _get_connections() for c, v in connections.items(): print(str(c) + ".value " + str(v))

def config(): print(""" graph_title MongoDB Connections Count graph_vlabel Connections count graph_category db graph_args --base 1000 -l 0 current.label current current.draw AREASTACK available.label available available.draw AREASTACK active.label active active.draw AREASTACK """)

if __name__ == "__main__": if len(sys.argv) > 1 and sys.argv[1] == "config": config() else: run()