Last active
December 14, 2015 06:48
-
-
Save aaronott/5045018 to your computer and use it in GitHub Desktop.
Testing for repl_lag This script will display the difference between the optime of current node and the primary node in a replSet. login to your server `mongo` and run `rs.repl_lag()`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rs.repl_lag = function () { | |
var s = db._adminCommand("replSetGetStatus"); | |
// if this is primary, go no further. | |
if (s.myState == 1) { | |
return 0; | |
} | |
var mytime = 0; | |
var primarytime = 0; | |
for (var i in s.members) { | |
if (s.members[i].self == true) { | |
mytime = s.members[i].optime.t; | |
} | |
if (s.members[i].stateStr == "PRIMARY") { | |
primarytime = s.members[i].optime.t; | |
} | |
if (mytime > 0 && primarytime > 0) { | |
break; | |
} | |
} | |
return (primarytime - mytime) / 1000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment