Last active
August 29, 2015 14:04
-
-
Save jgraglia/186c634bd6a280fe005d to your computer and use it in GitHub Desktop.
Mongo : export collections size to csv
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
// wget .... raw url ... | |
// mongo colstats_to_csv.js > `date +"%Y-%m-%d"`_stats.csv | |
rs.slaveOk(); | |
print("db; col; total; storage; index; unused; unused KB; unused MB"); | |
db._adminCommand("listDatabases").databases.forEach(function (d) {mdb = db.getSiblingDB(d.name); mdb.getCollectionNames().forEach(function(c) {idx = mdb[c].totalIndexSize(); s = mdb[c].storageSize(); t = mdb[c].totalSize(); print(d.name+"; "+c+"; "+t+";"+s+"; "+idx+"; "+(t-s-idx)+"; "+((t-s-idx)/1024)+"; "+((t-s-idx)/1024/1024));})}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment