Skip to content

Instantly share code, notes, and snippets.

@impshum
Created December 23, 2017 00:39
Show Gist options
  • Save impshum/a125bb5e73142afd44806defade9d471 to your computer and use it in GitHub Desktop.
Save impshum/a125bb5e73142afd44806defade9d471 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