소스 저장후 python test.py 실행하면 admin, local, config 를 제외한 모든
데이터베이스에 대한 컬력션 용량 정보가 출력 됩니다.
#!/usr/bin/python
#!-*- coding: utf-8 -*-
import time
import pymongo
from pymongo import MongoClient
USER='아이디'
PASS='패스워드'
client = MongoClient("mongodb://192.168.0.1",30011)
db = client['admin']
db.authenticate(USER,PASS, mechanism='SCRAM-SHA-1')
lotime = time.strftime('%Y/%m/%d %H:%M:%S',time.localtime(time.time()))
for db_list in client.database_names():
if ( db_list not in ['admin','local','config']):
db = client[db_list]
db_size = db.command("dbstats")
data_size=db_size["storageSize"]
index_size=db_size["indexSize"]
for collection_list in db.collection_names():
collection_size = db.command("collstats",collection_list)
print "%s \t %s \t %s \t %s \t %s \t %s \t %s " %(lotime,db_list,data_size,index_size,collection_list,collection_size['count'],collection_size['size']).
|
'SOURCE' 카테고리의 다른 글
[Python] Redis INFO 정보 출력하기 (0) | 2017.02.18 |
---|---|
[Python] MySQL CRUD 샘플 스크립트 (0) | 2017.02.18 |
Comments