Skip to content

Instantly share code, notes, and snippets.

@Stephenitis
Created February 24, 2016 18:00
Show Gist options
  • Save Stephenitis/95dfcee6e6eda4cf5f0e to your computer and use it in GitHub Desktop.
Save Stephenitis/95dfcee6e6eda4cf5f0e to your computer and use it in GitHub Desktop.
This script polls the rs.status() to check for the state of the various replica sets.
MAXSCRIPT_RUN_ITERATIONS = 1800 // approximately 30 minutes
for (var i = 0; i < MAXSCRIPT_RUN_ITERATIONS; i++) {
sleep(1000);
var currentdate = new Date();
var datetime = new Date().toLocaleString();
var rsStatus = rs.status()
var members = rsStatus.members
// Change this index depending on the # of members in your set
var resyncmember = members[0]
var resyncMemberState = resyncmember.stateStr
print("--------------")
print("Member Count: " + members.length + " " + datetime)
for (var n = 0; n < members.length; n++){
var member = members[n]
print("HOST: " + member.name + " State: " + member.stateStr)
}
if (resyncMemberState == "SECONDARY"){
print("########################")
var currentdate = new Date();
print("resyncMember finished: " + datetime)
print("########################")
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment