Last active
October 19, 2020 21:48
-
-
Save fndiaz/72c1bcb7fe2044ab3205bb916efd4e11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import pymongo | |
uri = "mongodb://user:pass@localhost:27017/admin" | |
conn = pymongo.MongoClient(uri) | |
db = conn['admin'] | |
db_stats = db.command({'replSetGetStatus' :1}) | |
server_secondary = 'name_server:27017' | |
primary_optime = 0 | |
secondary_optime = 0 | |
for key in db_stats['members'] : | |
print key | |
print '---------' | |
if (key['stateStr'] == 'SECONDARY' and key['name'] == server_secondary): | |
secondary = key['name'] | |
secondary_optime = key['optimeDate'] | |
if key['stateStr'] == 'PRIMARY' : | |
primary = key['name'] | |
primary_optime =key['optimeDate'] | |
print 'primary_optime : %s - %s ' %(str(primary_optime), str(primary)) | |
print 'secondary_optime : %s - %s ' %(str(secondary_optime), str(secondary)) | |
seconds_lag = (primary_optime - secondary_optime ).total_seconds() | |
#total_seconds() userd to get the lag in seconds rather than datetime object | |
print 'secondary_lag : ' + str(seconds_lag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment