Skip to content

Instantly share code, notes, and snippets.

@vgoklani
Forked from impshum/stats.py
Created February 1, 2019 23:45
Show Gist options
  • Save vgoklani/a61b573973c19f4132ca6ce212c3bedf to your computer and use it in GitHub Desktop.
Save vgoklani/a61b573973c19f4132ca6ce212c3bedf to your computer and use it in GitHub Desktop.
Get mongodb stats using python with pymongo
from pymongo import MongoClient
try:
client = MongoClient('localhost')
db = client.searchfollow
except:
print("Could not connect to MongoDB")
call = db.command("dbstats")
database = call['db']
datasize = call['dataSize'] / 1024
objects = call['objects']
collections = call['collections']
print('\n')
print('Database:', str(database))
print('Objects:', str(objects))
print('Collections:', str(collections))
print('Size:', str(datasize) + 'Mb')
print('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment