From fa7fbbb1f66ec5e189f6deba58564b72c2e4cbef Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Mon, 4 Apr 2011 18:31:23 -0400 Subject: [PATCH] support scale option to dbstats command SERVER-2174 --- db/dbcommands.cpp | 24 ++++++++++++++++++------ shell/db.js | 4 ++-- shell/mongo_vstudio.cpp | 4 ++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 1a003a047fc..f0d71ae32ac 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -1201,7 +1201,6 @@ namespace mongo { errmsg = "scale has to be > 0"; return false; } - } else if ( jsobj["scale"].trueValue() ) { errmsg = "scale has to be a number > 0"; @@ -1250,9 +1249,22 @@ namespace mongo { virtual void help( stringstream &help ) const { help << "Get stats on a database. Not instantaneous. Slower for databases with large .ns files.\n" << - "Example: { dbStats:1 }"; + "Example: { dbStats:1, scale:1 }"; } bool run(const string& dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + int scale = 1; + if ( jsobj["scale"].isNumber() ) { + scale = jsobj["scale"].numberInt(); + if ( scale <= 0 ) { + errmsg = "scale has to be > 0"; + return false; + } + } + else if ( jsobj["scale"].trueValue() ) { + errmsg = "scale has to be a number > 0"; + return false; + } + list collections; Database* d = cc().database(); if ( d ) @@ -1292,12 +1304,12 @@ namespace mongo { result.appendNumber( "collections" , ncollections ); result.appendNumber( "objects" , objects ); result.append ( "avgObjSize" , objects == 0 ? 0 : double(size) / double(objects) ); - result.appendNumber( "dataSize" , size ); - result.appendNumber( "storageSize" , storageSize); + result.appendNumber( "dataSize" , size / scale ); + result.appendNumber( "storageSize" , storageSize / scale); result.appendNumber( "numExtents" , numExtents ); result.appendNumber( "indexes" , indexes ); - result.appendNumber( "indexSize" , indexSize ); - result.appendNumber( "fileSize" , d->fileSize() ); + result.appendNumber( "indexSize" , indexSize / scale ); + result.appendNumber( "fileSize" , d->fileSize() / scale ); if( d ) result.appendNumber( "nsSizeMB", (int) d->namespaceIndex.fileLength() / 1024 / 1024 ); diff --git a/shell/db.js b/shell/db.js index 49a7606fd4b..ff88f988053 100644 --- a/shell/db.js +++ b/shell/db.js @@ -22,8 +22,8 @@ DB.prototype.getName = function(){ return this._name; } -DB.prototype.stats = function(){ - return this.runCommand( { dbstats : 1 } ); +DB.prototype.stats = function(scale){ + return this.runCommand( { dbstats : 1 , scale : scale } ); } DB.prototype.getCollection = function( name ){ diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp index f455eeffa0f..d61ec3e2e07 100644 --- a/shell/mongo_vstudio.cpp +++ b/shell/mongo_vstudio.cpp @@ -1516,8 +1516,8 @@ const StringData _jscode_raw_db = "return this._name;\n" "}\n" "\n" -"DB.prototype.stats = function(){\n" -"return this.runCommand( { dbstats : 1 } );\n" +"DB.prototype.stats = function(scale){\n" +"return this.runCommand( { dbstats : 1 , scale : scale } );\n" "}\n" "\n" "DB.prototype.getCollection = function( name ){\n"