Created
December 23, 2017 00:39
-
-
Save impshum/a125bb5e73142afd44806defade9d471 to your computer and use it in GitHub Desktop.
Get mongodb stats using python with pymongo
This file contains 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
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