diff options
Diffstat (limited to 'src/mongo/db/clientlistplugin.cpp')
-rw-r--r-- | src/mongo/db/clientlistplugin.cpp | 281 |
1 files changed, 137 insertions, 144 deletions
diff --git a/src/mongo/db/clientlistplugin.cpp b/src/mongo/db/clientlistplugin.cpp index aaffdd83492..62676395328 100644 --- a/src/mongo/db/clientlistplugin.cpp +++ b/src/mongo/db/clientlistplugin.cpp @@ -46,205 +46,198 @@ namespace mongo { - using std::unique_ptr; - using std::string; +using std::unique_ptr; +using std::string; namespace { - class ClientListPlugin : public WebStatusPlugin { - public: - ClientListPlugin() : WebStatusPlugin( "clients" , 20 ) {} - virtual void init() {} - - virtual void run(OperationContext* txn, std::stringstream& ss ) { - using namespace html; - - ss << "\n<table border=1 cellpadding=2 cellspacing=0>"; - ss << "<tr align='left'>" - << th( a("", "Connections to the database, both internal and external.", "Client") ) - << th( a("http://dochub.mongodb.org/core/viewingandterminatingcurrentoperation", "", "OpId") ) - << "<th>Locking</th>" - << "<th>Waiting</th>" - << "<th>SecsRunning</th>" - << "<th>Op</th>" - << th( a("http://dochub.mongodb.org/core/whatisanamespace", "", "Namespace") ) - << "<th>Query</th>" - << "<th>client</th>" - << "<th>msg</th>" - << "<th>progress</th>" - - << "</tr>\n"; - - _processAllClients(txn->getClient()->getServiceContext(), ss); - - ss << "</table>\n"; - } +class ClientListPlugin : public WebStatusPlugin { +public: + ClientListPlugin() : WebStatusPlugin("clients", 20) {} + virtual void init() {} - private: + virtual void run(OperationContext* txn, std::stringstream& ss) { + using namespace html; - static void _processAllClients(ServiceContext* service, std::stringstream& ss) { - using namespace html; + ss << "\n<table border=1 cellpadding=2 cellspacing=0>"; + ss << "<tr align='left'>" + << th(a("", "Connections to the database, both internal and external.", "Client")) + << th(a("http://dochub.mongodb.org/core/viewingandterminatingcurrentoperation", + "", + "OpId")) << "<th>Locking</th>" + << "<th>Waiting</th>" + << "<th>SecsRunning</th>" + << "<th>Op</th>" + << th(a("http://dochub.mongodb.org/core/whatisanamespace", "", "Namespace")) + << "<th>Query</th>" + << "<th>client</th>" + << "<th>msg</th>" + << "<th>progress</th>" - for (ServiceContext::LockedClientsCursor cursor(service); - Client* client = cursor.next();) { + << "</tr>\n"; - invariant(client); + _processAllClients(txn->getClient()->getServiceContext(), ss); - // Make the client stable - stdx::lock_guard<Client> lk(*client); - const OperationContext* txn = client->getOperationContext(); - if (!txn) continue; + ss << "</table>\n"; + } - CurOp* curOp = CurOp::get(txn); - if (!curOp) continue; +private: + static void _processAllClients(ServiceContext* service, std::stringstream& ss) { + using namespace html; - ss << "<tr><td>" << client->desc() << "</td>"; + for (ServiceContext::LockedClientsCursor cursor(service); Client* client = cursor.next();) { + invariant(client); - tablecell(ss, txn->getOpID()); - tablecell(ss, true); + // Make the client stable + stdx::lock_guard<Client> lk(*client); + const OperationContext* txn = client->getOperationContext(); + if (!txn) + continue; - // LockState - { - Locker::LockerInfo lockerInfo; - txn->lockState()->getLockerInfo(&lockerInfo); + CurOp* curOp = CurOp::get(txn); + if (!curOp) + continue; - BSONObjBuilder lockerInfoBuilder; - fillLockerInfo(lockerInfo, lockerInfoBuilder); + ss << "<tr><td>" << client->desc() << "</td>"; - tablecell(ss, lockerInfoBuilder.obj()); - } + tablecell(ss, txn->getOpID()); + tablecell(ss, true); - tablecell(ss, curOp->elapsedSeconds()); + // LockState + { + Locker::LockerInfo lockerInfo; + txn->lockState()->getLockerInfo(&lockerInfo); - tablecell(ss, curOp->getOp()); - tablecell(ss, html::escape(curOp->getNS())); + BSONObjBuilder lockerInfoBuilder; + fillLockerInfo(lockerInfo, lockerInfoBuilder); - if (curOp->haveQuery()) { - tablecell(ss, html::escape(curOp->query().toString())); - } - else { - tablecell(ss, ""); - } + tablecell(ss, lockerInfoBuilder.obj()); + } - tablecell(ss, client->clientAddress(true /*includePort*/)); + tablecell(ss, curOp->elapsedSeconds()); - tablecell(ss, curOp->getMessage()); - tablecell(ss, curOp->getProgressMeter().toString()); + tablecell(ss, curOp->getOp()); + tablecell(ss, html::escape(curOp->getNS())); - ss << "</tr>\n"; + if (curOp->haveQuery()) { + tablecell(ss, html::escape(curOp->query().toString())); + } else { + tablecell(ss, ""); } - } - } clientListPlugin; + tablecell(ss, client->clientAddress(true /*includePort*/)); + tablecell(ss, curOp->getMessage()); + tablecell(ss, curOp->getProgressMeter().toString()); - class CurrentOpContexts : public Command { - public: - CurrentOpContexts() - : Command( "currentOpCtx" ) { + ss << "</tr>\n"; } + } - virtual bool isWriteCommandForConfigServer() const { return false; } +} clientListPlugin; - virtual bool slaveOk() const { return true; } - virtual Status checkAuthForCommand(ClientBasic* client, - const std::string& dbname, - const BSONObj& cmdObj) { - if ( AuthorizationSession::get(client) - ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(), - ActionType::inprog) ) { - return Status::OK(); - } +class CurrentOpContexts : public Command { +public: + CurrentOpContexts() : Command("currentOpCtx") {} + + virtual bool isWriteCommandForConfigServer() const { + return false; + } - return Status(ErrorCodes::Unauthorized, "unauthorized"); + virtual bool slaveOk() const { + return true; + } + virtual Status checkAuthForCommand(ClientBasic* client, + const std::string& dbname, + const BSONObj& cmdObj) { + if (AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( + ResourcePattern::forClusterResource(), ActionType::inprog)) { + return Status::OK(); } - bool run( OperationContext* txn, - const string& dbname, - BSONObj& cmdObj, - int, - string& errmsg, - BSONObjBuilder& result) { - - unique_ptr<MatchExpression> filter; - if ( cmdObj["filter"].isABSONObj() ) { - StatusWithMatchExpression res = - MatchExpressionParser::parse( cmdObj["filter"].Obj() ); - if ( !res.isOK() ) { - return appendCommandStatus( result, res.getStatus() ); - } - filter.reset( res.getValue() ); + return Status(ErrorCodes::Unauthorized, "unauthorized"); + } + + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { + unique_ptr<MatchExpression> filter; + if (cmdObj["filter"].isABSONObj()) { + StatusWithMatchExpression res = MatchExpressionParser::parse(cmdObj["filter"].Obj()); + if (!res.isOK()) { + return appendCommandStatus(result, res.getStatus()); } - - result.appendArray( - "operations", - _processAllClients(txn->getClient()->getServiceContext(), filter.get())); - - return true; + filter.reset(res.getValue()); } + result.appendArray("operations", + _processAllClients(txn->getClient()->getServiceContext(), filter.get())); - private: + return true; + } - static BSONArray _processAllClients(ServiceContext* service, MatchExpression* matcher) { - BSONArrayBuilder array; - for (ServiceContext::LockedClientsCursor cursor(service); - Client* client = cursor.next();) { +private: + static BSONArray _processAllClients(ServiceContext* service, MatchExpression* matcher) { + BSONArrayBuilder array; - invariant(client); + for (ServiceContext::LockedClientsCursor cursor(service); Client* client = cursor.next();) { + invariant(client); - BSONObjBuilder b; + BSONObjBuilder b; - // Make the client stable - stdx::lock_guard<Client> lk(*client); + // Make the client stable + stdx::lock_guard<Client> lk(*client); - client->reportState(b); + client->reportState(b); - const OperationContext* txn = client->getOperationContext(); - b.appendBool("active", static_cast<bool>(txn)); - if (txn) { - b.append("opid", txn->getOpID()); - if (txn->isKillPending()) { - b.append("killPending", true); - } - - CurOp::get(txn)->reportState(&b); + const OperationContext* txn = client->getOperationContext(); + b.appendBool("active", static_cast<bool>(txn)); + if (txn) { + b.append("opid", txn->getOpID()); + if (txn->isKillPending()) { + b.append("killPending", true); + } - // LockState - if (txn->lockState()) { - StringBuilder ss; - ss << txn->lockState(); - b.append("lockStatePointer", ss.str()); + CurOp::get(txn)->reportState(&b); - Locker::LockerInfo lockerInfo; - txn->lockState()->getLockerInfo(&lockerInfo); + // LockState + if (txn->lockState()) { + StringBuilder ss; + ss << txn->lockState(); + b.append("lockStatePointer", ss.str()); - BSONObjBuilder lockerInfoBuilder; - fillLockerInfo(lockerInfo, lockerInfoBuilder); + Locker::LockerInfo lockerInfo; + txn->lockState()->getLockerInfo(&lockerInfo); - b.append("lockState", lockerInfoBuilder.obj()); - } + BSONObjBuilder lockerInfoBuilder; + fillLockerInfo(lockerInfo, lockerInfoBuilder); - // RecoveryUnit - if (txn->recoveryUnit()) { - txn->recoveryUnit()->reportState(&b); - } + b.append("lockState", lockerInfoBuilder.obj()); } - const BSONObj obj = b.obj(); - - if (!matcher || matcher->matchesBSON(obj)) { - array.append(obj); + // RecoveryUnit + if (txn->recoveryUnit()) { + txn->recoveryUnit()->reportState(&b); } } - return array.arr(); + const BSONObj obj = b.obj(); + + if (!matcher || matcher->matchesBSON(obj)) { + array.append(obj); + } } - } currentOpContexts; + return array.arr(); + } + +} currentOpContexts; } // namespace } // namespace mongo |