Created
February 12, 2024 14:54
-
-
Save AliRn76/e4831448cd52b166aa5f06f01bf99d35 to your computer and use it in GitHub Desktop.
Watch MongoDB Connections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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