0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

expose ReplicaSetMonitor stats

SERVER-3487
This commit is contained in:
Eliot Horowitz 2011-07-26 18:07:29 -04:00
parent 6683d09c4c
commit 20a0374718
3 changed files with 59 additions and 1 deletions

View File

@ -238,13 +238,16 @@ namespace mongo {
}
void DBConnectionPool::appendInfo( BSONObjBuilder& b ) {
BSONObjBuilder bb( b.subobjStart( "hosts" ) );
int avail = 0;
long long created = 0;
map<ConnectionString::ConnectionType,long long> createdByType;
set<string> replicaSets;
BSONObjBuilder bb( b.subobjStart( "hosts" ) );
{
scoped_lock lk( _mutex );
for ( PoolMap::iterator i=_pools.begin(); i!=_pools.end(); ++i ) {
@ -263,9 +266,33 @@ namespace mongo {
long long& x = createdByType[i->second.type()];
x += i->second.numCreated();
{
string setName = i->first.ident;
if ( setName.find( "/" ) != string::npos ) {
setName = setName.substr( 0 , setName.find( "/" ) );
replicaSets.insert( setName );
}
}
}
}
bb.done();
BSONObjBuilder setBuilder( b.subobjStart( "replicaSets" ) );
for ( set<string>::iterator i=replicaSets.begin(); i!=replicaSets.end(); ++i ) {
string rs = *i;
ReplicaSetMonitorPtr m = ReplicaSetMonitor::get( rs );
if ( ! m ) {
warning() << "no monitor for set: " << rs << endl;
continue;
}
BSONObjBuilder temp( setBuilder.subobjStart( rs ) );
m->appendInfo( temp );
temp.done();
}
setBuilder.done();
{
BSONObjBuilder temp( bb.subobjStart( "createdByType" ) );

View File

@ -125,6 +125,15 @@ namespace mongo {
return m;
}
ReplicaSetMonitorPtr ReplicaSetMonitor::get( const string& name ) {
scoped_lock lk( _setsLock );
map<string,ReplicaSetMonitorPtr>::const_iterator i = _sets.find( name );
if ( i == _sets.end() )
return ReplicaSetMonitorPtr();
return i->second;
}
void ReplicaSetMonitor::checkAll() {
set<string> seen;
@ -420,6 +429,20 @@ namespace mongo {
return -1;
}
void ReplicaSetMonitor::appendInfo( BSONObjBuilder& b ) const {
scoped_lock lk( _lock );
BSONArrayBuilder hosts( b.subarrayStart( "hosts" ) );
for ( unsigned i=0; i<_nodes.size(); i++ ) {
hosts.append( BSON( "addr" << _nodes[i].addr <<
"ok" << _nodes[i].ok ) );
}
hosts.done();
b.append( "master" , _master );
b.append( "nextSlave" , _nextSlave );
}
mongo::mutex ReplicaSetMonitor::_setsLock( "ReplicaSetMonitor" );
map<string,ReplicaSetMonitorPtr> ReplicaSetMonitor::_sets;

View File

@ -42,6 +42,12 @@ namespace mongo {
*/
static ReplicaSetMonitorPtr get( const string& name , const vector<HostAndPort>& servers );
/**
* gets a cached Monitor per name or will return none if it doesn't exist
*/
static ReplicaSetMonitorPtr get( const string& name );
/**
* checks all sets for current master and new secondaries
* usually only called from a BackgroundJob
@ -88,6 +94,8 @@ namespace mongo {
string getServerAddress() const;
bool contains( const string& server ) const;
void appendInfo( BSONObjBuilder& b ) const;
private:
/**