Skip to content

These scripts were developed to collection and process a "lighter" subset of stats #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions getMongoData/getMongoDataLite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Launch like:
// mongo --quiet < getMongoDataLite.js > out.json
//

print("{");
db.getMongo().getDBNames().forEach(function (name, idx, array) {
var mdb = db.getSiblingDB(name);
print("\"" + name + "\": { \n\t\t\"stats\":");
printjson(mdb.stats());
print("\n\t, \"collections\": [")
mdb.getCollectionNames().forEach(function(coll, idx2, array2) {
printjson(mdb.getCollection(coll).stats());
if (idx2 < array2.length - 1) print(",");
});
print("\t]\n}")
if (idx < array.length - 1) print(",");
});
print("\n}");
81 changes: 81 additions & 0 deletions getMongoData/processLite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Launch with `node processLite.js` or `node processList.js <MYFILE.json>`
*/

var markdown = true; // include markdown summary table
var args = process.argv.slice(2);
var filename = args.length > 0 ? args[0] : 'out.json';

console.log(`Reading data from ${filename}`);

var fs = require('fs');
var content = fs.readFileSync(filename, 'utf8');

content = content.replace(/Timestamp\(.*\)/g, '1');
content = content.replace(/NumberLong\((.*)\)/g, '$1');
content = content.replace(/ObjectId\((.*)\)/g, '$1');

var json = JSON.parse(content);

dbs = [];
collections = []; // collection names
// collection via DB and collection (and assert they are the same)
objectsViaDb = 0;
bytesViaDb = 0; // data size
indexSizeTotal = 0;
storageSizeTotal = 0;

objectsViaColls = 0; // total objects in ALL databases/collections
bytesViaColls = 0;

if (markdown) {
console.log(`| Database | dataSize | storageSize | indexSize |`);
console.log(`| ---- | ---: | ---: | ----: |`);
}
Object.keys(json).forEach(function(key) {
if (key != 'admin' && key != 'config') {
dbs.push(key);
var elem = json[key];
// collection via db.stats()
objectsViaDb += elem.stats.objects;
bytesViaDb += elem.stats.dataSize;
// console.log(`dataSize ${key}: ${(elem.stats.dataSize/1024/1024/1024).toFixed(1)}GB`)
indexSizeTotal += elem.stats.indexSize;
// console.log(`indexSize ${key}: ${(elem.stats.indexSize/1024/1024/1024).toFixed(1)}GB`)
storageSizeTotal += elem.stats.storageSize;
// console.log(`storageSize ${key}: ${(elem.stats.storageSize/1024/1024/1024).toFixed(1)}GB`)
if (markdown)
console.log(`| ${key} | ${(elem.stats.dataSize/1024/1024/1024).toFixed(1)} | ${(elem.stats.storageSize/1024/1024/1024).toFixed(1)} | ${(elem.stats.indexSize/1024/1024/1024).toFixed(1)} | `)
// same for getCollectionNames
elem.collections.forEach(function(coll) {
collections.push(coll.ns);
objectsViaColls += coll.count;
bytesViaColls += coll.size;
});
}
});

console.log(`{\n` +
`\tdbs: ${JSON.stringify(dbs)},\n`+
`\tdbCount: ${dbs.length},\n`+
`\tcolls: ${JSON.stringify(collections)},\n`+
`\tcollCount: ${collections.length},\n`+
`\tobjectsViaDb: ${objectsViaDb},\n`+
`\tobjectsViaColls: ${objectsViaColls},\n`+
`\tbytesViaDb: {\n`+
`\t\traw: ${bytesViaDb},\n`+
`\t\tgb: ${bytesViaDb/1024/1024/1024}\n`+
`\t},\n` +
`\tbytesViaColls: {\n`+
`\t\traw: ${bytesViaColls},\n`+
`\t\tgb: ${(bytesViaColls/1024/1024).toFixed(0)}\n`+
`\t},\n` +
`\tindexSizeTotal: {\n`+
`\t\traw: ${indexSizeTotal},\n`+
`\t\tgb: ${(bytesViaColls/1024/1024).toFixed(0)},\n`+
`\t},\n` +
`\tstorageSizeTotal: {\n`+
`\t\traw: ${storageSizeTotal},\n`+
`\t\tgb: ${(storageSizeTotal/1024/1024).toFixed(0)},\n`+
`\t},\n` +
`}`);