mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 09:06:21 +01:00
option to have slave lag in serverStatus SERVER-586
This commit is contained in:
parent
e2a8e2f12d
commit
2b96337203
@ -309,6 +309,7 @@ namespace mongo {
|
||||
bool authed = cc().getAuthenticationInfo()->isAuthorizedReads("admin");
|
||||
|
||||
result.append("uptime",(double) (time(0)-started));
|
||||
result.appendDate( "localTime" , jsTime() );
|
||||
|
||||
{
|
||||
BSONObjBuilder t;
|
||||
|
30
db/repl.cpp
30
db/repl.cpp
@ -39,6 +39,7 @@
|
||||
#include "repl.h"
|
||||
#include "../util/message.h"
|
||||
#include "../client/dbclient.h"
|
||||
#include "../client/connpool.h"
|
||||
#include "pdfile.h"
|
||||
#include "query.h"
|
||||
#include "db.h"
|
||||
@ -289,7 +290,34 @@ namespace mongo {
|
||||
auto_ptr<Cursor> c = findTableScan("local.sources", BSONObj());
|
||||
int n = 0;
|
||||
while ( c->ok() ){
|
||||
sources.append( BSONObjBuilder::numStr( n++ ) , c->current() );
|
||||
BSONObj s = c->current();
|
||||
|
||||
BSONObjBuilder bb;
|
||||
bb.append( s["host"] );
|
||||
string sourcename = s["source"].valuestr();
|
||||
if ( sourcename != "main" )
|
||||
bb.append( s["source"] );
|
||||
|
||||
{
|
||||
BSONElement e = s["syncedTo"];
|
||||
BSONObjBuilder t( bb.subobjStart( "syncedTo" ) );
|
||||
t.appendDate( "time" , e.timestampTime() );
|
||||
t.append( "inc" , e.timestampInc() );
|
||||
t.done();
|
||||
}
|
||||
|
||||
if ( level > 1 ){
|
||||
ScopedDbConnection conn( s["host"].valuestr() );
|
||||
BSONObj first = conn->findOne( (string)"local.oplog.$" + sourcename , Query().sort( BSON( "$natural" << 1 ) ) );
|
||||
BSONObj last = conn->findOne( (string)"local.oplog.$" + sourcename , Query().sort( BSON( "$natural" << -1 ) ) );
|
||||
bb.appendDate( "masterFirst" , first["ts"].timestampTime() );
|
||||
bb.appendDate( "masterLast" , last["ts"].timestampTime() );
|
||||
double lag = last["ts"].timestampTime() - s["syncedTo"].timestampTime();
|
||||
bb.append( "lagSeconds" , lag / 1000 );
|
||||
conn.done();
|
||||
}
|
||||
|
||||
sources.append( BSONObjBuilder::numStr( n++ ) , bb.obj() );
|
||||
c->advance();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user