Last active
August 3, 2018 09:41
-
-
Save pulecp/f1a7fbd68593d824d2c1161b037b67c5 to your computer and use it in GitHub Desktop.
MongoDB - show space available to reuse per collection
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
// mongo --quiet 127.0.0.1:27017/admin mongo_space_available_for_reuse.js | |
db.getMongo().setSlaveOk() | |
var dbs = db.runCommand({ "listDatabases": 1 }).databases | |
var total_available_space_to_reuse = 0 | |
print("Space available to reuse per collection:\n") | |
dbs.forEach(function(database) { | |
db = db.getSiblingDB(database.name) | |
print(" " + db + ":") | |
var available_size = 0 | |
db.getCollectionNames().forEach(function(col) { | |
var available_size_in_collection = db[col].stats().wiredTiger['block-manager']['file bytes available for reuse'] | |
if (available_size_in_collection > 0) { | |
print(" " + col + ": " + available_size_in_collection / 1024 / 1024 + " MB") | |
} | |
available_size = available_size + available_size_in_collection | |
}) | |
var available_size_mb = available_size / 1024 / 1024 | |
total_available_space_to_reuse = total_available_space_to_reuse + available_size_mb | |
}) | |
print("\n\ntotal available space to reuse: " + total_available_space_to_reuse + " MB") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment