def get_slave_delay(name):
 metrics = get_metrics()[0]
 if (('rs_status_myState' not in metrics['data']) or (metrics['data']['rs_status_myState'] != 2)):
  result = 0
 else:
  master = {}
  slave = {}
  try:
   for member in metrics['data']['rs_status_members']:
    if (member['state'] == 1):
     master = member
    if (member['name'].split(':')[0] == socket.getfqdn()):
     slave = member
   result = (max(0, (master['optime']['t'] - slave['optime']['t'])) / 1000)
  except KeyError:
   result = 0
 return result

def get_slave_delay ( name ) : metrics = get_metrics ( ) [ 0 ] if ( ( 'rs_status_myState' not in metrics [ 'data' ] ) or ( metrics [ 'data' ] [ 'rs_status_myState' ] != 2 ) ) : result = 0 else : master = { } slave = { } try : for member in metrics [ 'data' ] [ 'rs_status_members' ] : if ( member [ 'state' ] == 1 ) : master = member if ( member [ 'name' ] . split ( ':' ) [ 0 ] == socket . getfqdn ( ) ) : slave = member result = ( max ( 0 , ( master [ 'optime' ] [ 't' ] - slave [ 'optime' ] [ 't' ] ) ) / 1000 ) except KeyError : result = 0 return result
return the replica set slave delay .