Skip to content

Instantly share code, notes, and snippets.

@aaronott
Last active December 14, 2015 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronott/5045018 to your computer and use it in GitHub Desktop.
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()`
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