diff options
author | Eliot Horowitz <eliot@10gen.com> | 2014-05-05 23:36:42 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2014-05-06 12:06:58 -0400 |
commit | e404acb525bb23a7f75c54e93f124a5141083503 (patch) | |
tree | a705ba87bb71d8bd77e2ab5a86a823f4db6d3e26 /src/mongo/db | |
parent | aa170e9550ae7b88ae129e90d083d6f9373ce1da (diff) | |
download | mongo-e404acb525bb23a7f75c54e93f124a5141083503.tar.gz |
SERVER-13640: split up ServerStatus into a library
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/catalog/collection.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/clientcursor.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/SConscript | 14 | ||||
-rw-r--r-- | src/mongo/db/commands/server_status.cpp | 76 | ||||
-rw-r--r-- | src/mongo/db/commands/server_status.h | 51 | ||||
-rw-r--r-- | src/mongo/db/commands/server_status_internal.cpp | 82 | ||||
-rw-r--r-- | src/mongo/db/commands/server_status_internal.h | 57 | ||||
-rw-r--r-- | src/mongo/db/commands/server_status_metric.cpp | 56 | ||||
-rw-r--r-- | src/mongo/db/commands/server_status_metric.h | 91 | ||||
-rw-r--r-- | src/mongo/db/curop.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/prefetch.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/bgsync.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/oplogreader.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/structure/record_store_v1_simple.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/ttl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/write_concern.cpp | 2 |
18 files changed, 313 insertions, 134 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index ea56f5792d6..37da5b0714d 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -33,7 +33,7 @@ #include "mongo/base/counter.h" #include "mongo/base/owned_pointer_map.h" #include "mongo/db/clientcursor.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/curop.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/index_create.h" diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp index 362c54917a2..189f89e611a 100644 --- a/src/mongo/db/clientcursor.cpp +++ b/src/mongo/db/clientcursor.cpp @@ -41,6 +41,7 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/commands.h" #include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/db.h" #include "mongo/db/jsobj.h" #include "mongo/db/kill_current_op.h" diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript new file mode 100644 index 00000000000..dc4c943c10f --- /dev/null +++ b/src/mongo/db/commands/SConscript @@ -0,0 +1,14 @@ +# -*- mode: python -*- + +Import("env") + +env.Library( + target='server_status_core', + source=[ + 'server_status_internal.cpp', + 'server_status_metric.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/bson' + ] + ) diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp index f49daa3db31..181d172547a 100644 --- a/src/mongo/db/commands/server_status.cpp +++ b/src/mongo/db/commands/server_status.cpp @@ -38,6 +38,8 @@ #include "mongo/db/client_basic.h" #include "mongo/db/commands.h" #include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_internal.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/stats/counters.h" #include "mongo/platform/process_id.h" #include "mongo/util/net/listen.h" @@ -47,25 +49,6 @@ namespace mongo { - namespace { - class MetricTree { - public: - void add( ServerStatusMetric* metric ); - - void appendTo( BSONObjBuilder& b ) const; - - static MetricTree* theMetricTree; - private: - - void _add( const string& path, ServerStatusMetric* metric ); - - map<string, MetricTree*> _subtrees; - map<string, ServerStatusMetric*> _metrics; - }; - - MetricTree* MetricTree::theMetricTree = NULL; - } - class CmdServerStatus : public Command { public: @@ -206,61 +189,6 @@ namespace mongo { OpCounterServerStatusSection globalOpCounterServerStatusSection( "opcounters", &globalOpCounters ); - void MetricTree::add( ServerStatusMetric* metric ) { - string name = metric->getMetricName(); - if ( name[0] == '.' ) - _add( name.substr(1), metric ); - else - _add( str::stream() << "metrics." << name, metric ); - } - - void MetricTree::_add( const string& path, ServerStatusMetric* metric ) { - size_t idx = path.find( "." ); - if ( idx == string::npos ) { - _metrics[path] = metric; - return; - } - - string myLevel = path.substr( 0, idx ); - if ( _metrics.count( myLevel ) > 0 ) { - cerr << "metric conflict on: " << myLevel << endl; - fassertFailed( 16461 ); - } - - MetricTree*& sub = _subtrees[myLevel]; - if ( ! sub ) - sub = new MetricTree(); - sub->_add( path.substr( idx + 1 ), metric ); - } - - void MetricTree::appendTo( BSONObjBuilder& b ) const { - for ( map<string,ServerStatusMetric*>::const_iterator i = _metrics.begin(); i != _metrics.end(); ++i ) { - i->second->appendAtLeaf( b ); - } - - for ( map<string,MetricTree*>::const_iterator i = _subtrees.begin(); i != _subtrees.end(); ++i ) { - BSONObjBuilder bb( b.subobjStart( i->first ) ); - i->second->appendTo( bb ); - bb.done(); - } - } - - ServerStatusMetric::ServerStatusMetric(const string& nameIn) - : _name( nameIn ), - _leafName( _parseLeafName( nameIn ) ) { - - if ( MetricTree::theMetricTree == 0 ) - MetricTree::theMetricTree = new MetricTree(); - MetricTree::theMetricTree->add( this ); - } - - string ServerStatusMetric::_parseLeafName( const string& name ) { - size_t idx = name.rfind( "." ); - if ( idx == string::npos ) - return name; - - return name.substr( idx + 1 ); - } namespace { diff --git a/src/mongo/db/commands/server_status.h b/src/mongo/db/commands/server_status.h index ade476ec064..b6313f28eba 100644 --- a/src/mongo/db/commands/server_status.h +++ b/src/mongo/db/commands/server_status.h @@ -91,56 +91,5 @@ namespace mongo { const OpCounters* _counters; }; - class ServerStatusMetric { - public: - /** - * @param name is a dotted path of a counter name - * if name starts with . its treated as a path from the serverStatus root - * otherwise it will live under the "counters" namespace - * so foo.bar would be serverStatus().counters.foo.bar - */ - ServerStatusMetric(const string& name); - virtual ~ServerStatusMetric(){} - - string getMetricName() const { return _name; } - - virtual void appendAtLeaf( BSONObjBuilder& b ) const = 0; - - protected: - static string _parseLeafName( const string& name ); - - const string _name; - const string _leafName; - }; - - /** - * usage - * - * declared once - * Counter counter; - * ServerStatusMetricField myAwesomeCounterDisplay( "path.to.counter", &counter ); - * - * call - * counter.hit(); - * - * will show up in db.serverStatus().metrics.path.to.counter - */ - template< typename T > - class ServerStatusMetricField : public ServerStatusMetric { - public: - ServerStatusMetricField( const string& name, const T* t ) - : ServerStatusMetric(name), _t(t) { - } - - const T* get() { return _t; } - - virtual void appendAtLeaf( BSONObjBuilder& b ) const { - b.append( _leafName, *_t ); - } - - private: - const T* _t; - }; - } diff --git a/src/mongo/db/commands/server_status_internal.cpp b/src/mongo/db/commands/server_status_internal.cpp new file mode 100644 index 00000000000..24f8e36dafa --- /dev/null +++ b/src/mongo/db/commands/server_status_internal.cpp @@ -0,0 +1,82 @@ +// server_status_internal.cpp + +/** +* Copyright (C) 2014 MongoDB Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* As a special exception, the copyright holders give permission to link the +* code of portions of this program with the OpenSSL library under certain +* conditions as described in each individual source file and distribute +* linked combinations including the program with the OpenSSL library. You +* must comply with the GNU Affero General Public License in all respects for +* all of the code used other than as permitted herein. If you modify file(s) +* with this exception, you may extend this exception to your version of the +* file(s), but you are not obligated to do so. If you do not wish to do so, +* delete this exception statement from your version. If you delete this +* exception statement from all source files in the program, then also delete +* it in the license file. +*/ + +#include "mongo/db/commands/server_status_internal.h" + +#include "mongo/db/commands/server_status_metric.h" +#include "mongo/util/mongoutils/str.h" + +namespace mongo { + + using namespace mongoutils; + + MetricTree* MetricTree::theMetricTree = NULL; + + void MetricTree::add( ServerStatusMetric* metric ) { + string name = metric->getMetricName(); + if ( name[0] == '.' ) + _add( name.substr(1), metric ); + else + _add( str::stream() << "metrics." << name, metric ); + } + + void MetricTree::_add( const string& path, ServerStatusMetric* metric ) { + size_t idx = path.find( "." ); + if ( idx == string::npos ) { + _metrics[path] = metric; + return; + } + + string myLevel = path.substr( 0, idx ); + if ( _metrics.count( myLevel ) > 0 ) { + cerr << "metric conflict on: " << myLevel << endl; + fassertFailed( 16461 ); + } + + MetricTree*& sub = _subtrees[myLevel]; + if ( ! sub ) + sub = new MetricTree(); + sub->_add( path.substr( idx + 1 ), metric ); + } + + void MetricTree::appendTo( BSONObjBuilder& b ) const { + for ( map<string,ServerStatusMetric*>::const_iterator i = _metrics.begin(); i != _metrics.end(); ++i ) { + i->second->appendAtLeaf( b ); + } + + for ( map<string,MetricTree*>::const_iterator i = _subtrees.begin(); i != _subtrees.end(); ++i ) { + BSONObjBuilder bb( b.subobjStart( i->first ) ); + i->second->appendTo( bb ); + bb.done(); + } + } + +} + diff --git a/src/mongo/db/commands/server_status_internal.h b/src/mongo/db/commands/server_status_internal.h new file mode 100644 index 00000000000..2fbb69dc32b --- /dev/null +++ b/src/mongo/db/commands/server_status_internal.h @@ -0,0 +1,57 @@ +// server_status_internal.h + +/** +* Copyright (C) 2014 MongoDB Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* As a special exception, the copyright holders give permission to link the +* code of portions of this program with the OpenSSL library under certain +* conditions as described in each individual source file and distribute +* linked combinations including the program with the OpenSSL library. You +* must comply with the GNU Affero General Public License in all respects for +* all of the code used other than as permitted herein. If you modify file(s) +* with this exception, you may extend this exception to your version of the +* file(s), but you are not obligated to do so. If you do not wish to do so, +* delete this exception statement from your version. If you delete this +* exception statement from all source files in the program, then also delete +* it in the license file. +*/ + +#pragma once + +#include <map> +#include <string> + +#include "mongo/db/jsobj.h" + +namespace mongo { + + class ServerStatusMetric; + + class MetricTree { + public: + void add( ServerStatusMetric* metric ); + + void appendTo( BSONObjBuilder& b ) const; + + static MetricTree* theMetricTree; + private: + + void _add( const string& path, ServerStatusMetric* metric ); + + std::map<std::string, MetricTree*> _subtrees; + std::map<std::string, ServerStatusMetric*> _metrics; + }; + +} diff --git a/src/mongo/db/commands/server_status_metric.cpp b/src/mongo/db/commands/server_status_metric.cpp new file mode 100644 index 00000000000..285ec813fcf --- /dev/null +++ b/src/mongo/db/commands/server_status_metric.cpp @@ -0,0 +1,56 @@ +// server_status_metric.cpp + +/** +* Copyright (C) 2014 MongoDB Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* As a special exception, the copyright holders give permission to link the +* code of portions of this program with the OpenSSL library under certain +* conditions as described in each individual source file and distribute +* linked combinations including the program with the OpenSSL library. You +* must comply with the GNU Affero General Public License in all respects for +* all of the code used other than as permitted herein. If you modify file(s) +* with this exception, you may extend this exception to your version of the +* file(s), but you are not obligated to do so. If you do not wish to do so, +* delete this exception statement from your version. If you delete this +* exception statement from all source files in the program, then also delete +* it in the license file. +*/ + +#include "mongo/db/commands/server_status_metric.h" + +#include "mongo/db/commands/server_status_internal.h" + +namespace mongo { + + ServerStatusMetric::ServerStatusMetric(const string& nameIn) + : _name( nameIn ), + _leafName( _parseLeafName( nameIn ) ) { + + if ( MetricTree::theMetricTree == 0 ) + MetricTree::theMetricTree = new MetricTree(); + MetricTree::theMetricTree->add( this ); + } + + string ServerStatusMetric::_parseLeafName( const string& name ) { + size_t idx = name.rfind( "." ); + if ( idx == string::npos ) + return name; + + return name.substr( idx + 1 ); + } + + +} + diff --git a/src/mongo/db/commands/server_status_metric.h b/src/mongo/db/commands/server_status_metric.h new file mode 100644 index 00000000000..1f430d3a2c7 --- /dev/null +++ b/src/mongo/db/commands/server_status_metric.h @@ -0,0 +1,91 @@ +// server_status_metric.h + +/** +* Copyright (C) 2014 MongoDB Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* As a special exception, the copyright holders give permission to link the +* code of portions of this program with the OpenSSL library under certain +* conditions as described in each individual source file and distribute +* linked combinations including the program with the OpenSSL library. You +* must comply with the GNU Affero General Public License in all respects for +* all of the code used other than as permitted herein. If you modify file(s) +* with this exception, you may extend this exception to your version of the +* file(s), but you are not obligated to do so. If you do not wish to do so, +* delete this exception statement from your version. If you delete this +* exception statement from all source files in the program, then also delete +* it in the license file. +*/ + +#pragma once + +#include <string> + +#include "mongo/db/jsobj.h" + +namespace mongo { + + class ServerStatusMetric { + public: + /** + * @param name is a dotted path of a counter name + * if name starts with . its treated as a path from the serverStatus root + * otherwise it will live under the "counters" namespace + * so foo.bar would be serverStatus().counters.foo.bar + */ + ServerStatusMetric(const std::string& name); + virtual ~ServerStatusMetric(){} + + std::string getMetricName() const { return _name; } + + virtual void appendAtLeaf( BSONObjBuilder& b ) const = 0; + + protected: + static string _parseLeafName( const std::string& name ); + + const std::string _name; + const std::string _leafName; + }; + + /** + * usage + * + * declared once + * Counter counter; + * ServerStatusMetricField myAwesomeCounterDisplay( "path.to.counter", &counter ); + * + * call + * counter.hit(); + * + * will show up in db.serverStatus().metrics.path.to.counter + */ + template< typename T > + class ServerStatusMetricField : public ServerStatusMetric { + public: + ServerStatusMetricField( const std::string& name, const T* t ) + : ServerStatusMetric(name), _t(t) { + } + + const T* get() { return _t; } + + virtual void appendAtLeaf( BSONObjBuilder& b ) const { + b.append( _leafName, *_t ); + } + + private: + const T* _t; + }; + +} + diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp index a199f313ddf..2ce1bb7326a 100644 --- a/src/mongo/db/curop.cpp +++ b/src/mongo/db/curop.cpp @@ -29,7 +29,7 @@ #include "mongo/pch.h" #include "mongo/base/counter.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/curop.h" #include "mongo/db/catalog/database.h" #include "mongo/db/kill_current_op.h" diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index f4711c161cd..4bd588cc8e1 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -46,6 +46,7 @@ #include "mongo/db/client.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/d_concurrency.h" #include "mongo/db/d_globals.h" #include "mongo/db/db.h" diff --git a/src/mongo/db/prefetch.cpp b/src/mongo/db/prefetch.cpp index fdcd3bc2c75..f478b3d8479 100644 --- a/src/mongo/db/prefetch.cpp +++ b/src/mongo/db/prefetch.cpp @@ -37,7 +37,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/repl/rs.h" #include "mongo/db/stats/timer_stats.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" namespace mongo { diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index 59f010e8928..1707baf5d79 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -30,7 +30,7 @@ #include "mongo/db/client.h" #include "mongo/db/commands/fsync.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/rs_sync.h" diff --git a/src/mongo/db/repl/oplogreader.cpp b/src/mongo/db/repl/oplogreader.cpp index 7290c73685a..6441d59e052 100644 --- a/src/mongo/db/repl/oplogreader.cpp +++ b/src/mongo/db/repl/oplogreader.cpp @@ -36,7 +36,7 @@ #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_manager_global.h" #include "mongo/db/auth/authorization_session.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/auth/security_key.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/jsobj.h" diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index 85c90970129..91eb4b291db 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -34,7 +34,7 @@ #include "mongo/base/counter.h" #include "mongo/db/commands/fsync.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/curop.h" #include "mongo/db/prefetch.h" #include "mongo/db/repl/bgsync.h" diff --git a/src/mongo/db/structure/record_store_v1_simple.cpp b/src/mongo/db/structure/record_store_v1_simple.cpp index bfb021f9f6c..1384b2ddd1c 100644 --- a/src/mongo/db/structure/record_store_v1_simple.cpp +++ b/src/mongo/db/structure/record_store_v1_simple.cpp @@ -33,7 +33,7 @@ #include "mongo/base/counter.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/client.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/curop.h" #include "mongo/db/storage/extent.h" #include "mongo/db/storage/extent_manager.h" diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index d7b73a97fda..affef462400 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -37,7 +37,7 @@ #include "mongo/db/auth/user_name.h" #include "mongo/db/client.h" #include "mongo/db/commands/fsync.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/instance.h" #include "mongo/db/ops/delete.h" diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index 14099f2d020..b5529f6060f 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -27,7 +27,7 @@ */ #include "mongo/base/counter.h" -#include "mongo/db/commands/server_status.h" +#include "mongo/db/commands/server_status_metric.h" #include "mongo/db/kill_current_op.h" #include "mongo/db/repl/is_master.h" #include "mongo/db/repl/repl_settings.h" |