diff options
author | daveh86 <howsdav@gmail.com> | 2014-08-07 14:53:10 +1000 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2014-09-24 22:51:58 -0400 |
commit | b2ea63e14f6e382c42409c8bf6326115fca94888 (patch) | |
tree | 711855b889ac5994495ac78597e77c5f2275e8c6 /src | |
parent | 09fd21a206f959f6742e92d38b783a3e04e1948b (diff) | |
download | mongo-b2ea63e14f6e382c42409c8bf6326115fca94888.tar.gz |
SERVER-7382 command counters
Closes #794
Signed-off-by: Benety Goh <benety@mongodb.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/commands.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/commands.h | 14 | ||||
-rw-r--r-- | src/mongo/db/dbcommands.cpp | 7 | ||||
-rw-r--r-- | src/mongo/s/commands_public.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/s_only.cpp | 6 |
5 files changed, 36 insertions, 1 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index 2ef8db5085a..72508f89de5 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -62,6 +62,10 @@ namespace mongo { int Command::testCommandsEnabled = 0; + Counter64 Command::unknownCommands; + static ServerStatusMetricField<Counter64> displayUnknownCommands( "commands.<UNKNOWN>", + &Command::unknownCommands ); + namespace { ExportedServerParameter<int> testCommandsParameter(ServerParameterSet::getGlobal(), "enableTestCommands", @@ -176,7 +180,10 @@ namespace mongo { ss << "</tr>\n"; } - Command::Command(StringData _name, bool web, StringData oldName) : name(_name.toString()) { + Command::Command(StringData _name, bool web, StringData oldName) : + name(_name.toString()), + _commandsExecutedMetric("commands."+ _name.toString()+".total", &_commandsExecuted), + _commandsFailedMetric("commands."+ _name.toString()+".failed", &_commandsFailed) { // register ourself. if ( _commands == 0 ) _commands = new map<string,Command*>; diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index ac56a808d01..73952e547ad 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -32,10 +32,12 @@ #include <string> #include <vector> +#include "mongo/base/counter.h" #include "mongo/base/status.h" #include "mongo/db/auth/privilege.h" #include "mongo/db/auth/resource_pattern.h" #include "mongo/db/client_basic.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/jsobj.h" #include "mongo/db/query/explain.h" @@ -217,6 +219,14 @@ namespace mutablebson { static std::map<std::string,Command*> * _commandsByBestName; static std::map<std::string,Command*> * _webCommands; + // Counters for how many times this command has been executed and failed + Counter64 _commandsExecuted; + Counter64 _commandsFailed; + + // Pointers to hold the metrics tree references + ServerStatusMetricField<Counter64> _commandsExecutedMetric; + ServerStatusMetricField<Counter64> _commandsFailedMetric; + public: // Stops all index builds required to run this command and returns index builds killed. virtual std::vector<BSONObj> stopIndexBuilds(OperationContext* opCtx, @@ -225,6 +235,10 @@ namespace mutablebson { static const std::map<std::string,Command*>* commandsByBestName() { return _commandsByBestName; } static const std::map<std::string,Command*>* webCommands() { return _webCommands; } + + // Counter for unknown commands + static Counter64 unknownCommands; + /** @return if command was found */ static void runAgainstRegistered(const char *ns, BSONObj& jsobj, diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index a2cce53daba..2cd9cc893f5 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -1378,8 +1378,14 @@ namespace mongo { txn->getCurOp()->ensureStarted(); + c->_commandsExecuted.increment(); + retval = _execCommand(txn, c, dbname, cmdObj, queryOptions, errmsg, result, fromRepl); + if ( !retval ){ + c->_commandsFailed.increment(); + } + appendCommandStatus(result, retval, errmsg); // For commands from mongos, append some info to help getLastError(w) work. @@ -1458,6 +1464,7 @@ namespace mongo { str::stream() << "no such cmd: " << e.fieldName()); anObjBuilder.append("code", ErrorCodes::CommandNotFound); anObjBuilder.append("bad cmd" , _cmdobj ); + Command::unknownCommands.increment(); } BSONObj x = anObjBuilder.done(); diff --git a/src/mongo/s/commands_public.cpp b/src/mongo/s/commands_public.cpp index bb45370eb4c..2b8aadab8d2 100644 --- a/src/mongo/s/commands_public.cpp +++ b/src/mongo/s/commands_public.cpp @@ -2588,6 +2588,7 @@ namespace mongo { false, str::stream() << "no such cmd: " << commandName); anObjBuilder.append("code", ErrorCodes::CommandNotFound); + Command::unknownCommands.increment(); return; } ClientInfo *client = ClientInfo::get(); diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp index 3db331d2dbf..9c17e2d2d8c 100644 --- a/src/mongo/s/s_only.cpp +++ b/src/mongo/s/s_only.cpp @@ -137,6 +137,8 @@ namespace mongo { return; } + c->_commandsExecuted.increment(); + std::string errmsg; bool ok; try { @@ -155,6 +157,10 @@ namespace mongo { result.append( "code" , code ); } + if ( !ok ) { + c->_commandsFailed.increment(); + } + appendCommandStatus(result, ok, errmsg); } } |