Skip to content

Instantly share code, notes, and snippets.

@AliRn76
Created February 12, 2024 14:54
Show Gist options
  • Save AliRn76/e4831448cd52b166aa5f06f01bf99d35 to your computer and use it in GitHub Desktop.
Save AliRn76/e4831448cd52b166aa5f06f01bf99d35 to your computer and use it in GitHub Desktop.
Watch MongoDB Connections
import time
from pymongo import MongoClient
db = MongoClient().get_database('panther')
prev_connections = None
while True:
status = db.command("serverStatus")
current_connections = status.get('connections', {}).get('current', 0)
if current_connections != prev_connections:
print(f"Current connections: {current_connections}")
prev_connections = current_connections
time.sleep(.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment