- Reference >
- Database Commands >
- Replication Commands >
- replSetGetStatus
replSetGetStatus¶
On this page
Definition¶
-
replSetGetStatus¶ The
replSetGetStatuscommand returns the status of the replica set from the point of view of the server that processed the command.replSetGetStatusmust be run against the admin database. The command has the following prototype form:{ replSetGetStatus: 1 }
The value specified does not affect the output of the command. Data provided by this command derives from data included in heartbeats sent to the server by other members of the replica set. Because of the frequency of heartbeats, these data can be several seconds out of date.
You can also access this functionality through the
rs.status()helper in themongoshell.The
mongodinstance must have replication enabled and be a member of a replica set forreplSetGetStatusto return successfully.
Example¶
The following example runs the replSetGetStatus command on the admin database of the replica set primary:
db.adminCommand( { replSetGetStatus : 1 } )
Consider the following example output:
{
"set" : "replset",
"date" : ISODate("2016-11-02T20:02:16.543Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "m1.example.net:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 269,
"optime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-11-02T20:02:14Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1478116933, 1),
"electionDate" : ISODate("2016-11-02T20:02:13Z"),
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "m2.example.net:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 14,
"optime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-11-02T20:02:14Z"),
"optimeDurableDate" : ISODate("2016-11-02T20:02:14Z"),
"lastHeartbeat" : ISODate("2016-11-02T20:02:15.618Z"),
"lastHeartbeatRecv" : ISODate("2016-11-02T20:02:14.866Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "m3.example.net:27017",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "m3.example.net:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 14,
"optime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-11-02T20:02:14Z"),
"optimeDurableDate" : ISODate("2016-11-02T20:02:14Z"),
"lastHeartbeat" : ISODate("2016-11-02T20:02:15.619Z"),
"lastHeartbeatRecv" : ISODate("2016-11-02T20:02:14.787Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "m1.example.net:27018",
"configVersion" : 1
}
],
"ok" : 1
}
Output¶
The replSetGetStatus command returns a document with the following fields:
-
replSetGetStatus.set¶ The
setvalue is the name of the replica set, configured in thereplSetNamesetting. This is the same value as_idinrs.conf().
-
replSetGetStatus.date¶ An ISODate formatted date and time that reflects the current time according to the server that processed the replSetGetStatus command. Compare this to the values of
replSetGetStatus.members[n].lastHeartbeatto find the operational latency between this server and the other members of the replica set.
-
replSetGetStatus.myState¶ An integer between
0and10that represents the replica state of the current member.
-
replSetGetStatus.term¶ New in version 3.2.
The election count for the replica set, as known to this replica set member. The
termis used by the distributed consensus algorithm to ensure correctness.If using
protocolVersion: 0, instead ofprotocolVersion: 1, returns-1.
-
replSetGetStatus.heartbeatIntervalMillis¶ New in version 3.2.
The frequency in milliseconds of the heartbeats.
-
replSetGetStatus.optimes¶ New in version 3.4.
The
optimesfield holds a document that contains optimes used to inspect replication progress.Each optime value is a document that contains:
ts, the Timestamp of the operation.t, thetermin which the operation was originally generated on the primary.If using
protocolVersion: 0,tis equal to-1.
-
replSetGetStatus.optimes.lastCommittedOpTime¶ Information, from the viewpoint of this member, regarding the most recent operation that has been written to a majority of replica set members.
-
replSetGetStatus.optimes.readConcernMajorityOpTime¶ Information, from the viewpoint of this member, regarding the most recent operation that can fulfill read concern
"majority"queries; i.e. the most recentlastCommittedOpTimethat can fulfill"majority"queries.readConcernMajorityOpTimeis either less than or equal tolastCommittedOpTime.
-
replSetGetStatus.optimes.appliedOpTime¶ Information, from the viewpoint of this member, regarding the most recent operation that has been applied to this member of the replica set.
-
replSetGetStatus.optimes.durableOpTime¶ Information,, from the viewpoint of this member, regarding the most recent operation that has been written to the journal of this member of the replica set.
-
replSetGetStatus.members¶ The
membersfield holds an array that contains a document for every member in the replica set.-
replSetGetStatus.members[n].name¶ The
namefield holds the name of the server.
-
replSetGetStatus.members[n].self¶ The
selffield is only included in the document for the currentmongodinstance in the members array. Its value istrue.
-
replSetGetStatus.members[n].health¶ The
healthvalue is only present for the other members of the replica set (i.e. not the member that returnsrs.status). This field conveys if the member is up (i.e.1) or down (i.e.0).
-
replSetGetStatus.members[n].state¶ The value of
stateis an integer between0and10that represents the replica state of the member.
-
replSetGetStatus.members[n].stateStr¶ A string that describes
state.
-
replSetGetStatus.members[n].uptime¶ The
uptimefield holds a value that reflects the number of seconds that this member has been online.This value does not appear for the member that returns the
rs.status()data.
-
replSetGetStatus.members[n].optime¶ Information regarding the last operation from the operation log that this member has applied.
Changed in version 3.2.
If using
protocolVersion: 1,optimereturns a document that contains:ts, the Timestamp of the last operation applied to this member of the replica set from the oplog.t, thetermin which the last applied operation was originally generated on the primary.
If using
protocolVersion: 0,optimereturns the Timestamp of the last operation applied to this member of the replica set from the oplog.
-
replSetGetStatus.members[n].optimeDurable¶ New in version 3.4.
Information regarding the last operation from the operation log that this member has applied to its journal.
If using
protocolVersion: 1,optimereturns a document that contains:ts, the Timestamp of the operation.t, thetermin which this operation was originally generated on the primary.
If using
protocolVersion: 0,optimereturns the Timestamp of the operation.
-
replSetGetStatus.members[n].optimeDate¶ An ISODate formatted date string that reflects the last entry from the oplog that this member applied. If this differs significantly from
lastHeartbeatthis member is either experiencing “replication lag” or there have not been any new operations since the last update. Comparemembers.optimeDatebetween all of the members of the set.
-
replSetGetStatus.members[n].optimeDurableDate¶ New in version 3.4.
An ISODate formatted date string that reflects the last entry from the oplog that this member applied to its journal.
-
replSetGetStatus.members[n].electionTime¶ For the current primary, information regarding the election Timestamp from the operation log. See Replica Set Elections for more information about elections.
-
replSetGetStatus.members[n].electionDate¶ For the current primary, an ISODate formatted date string that reflects the election date. See Replica Set Elections for more information about elections.
-
replSetGetStatus.members[n].self¶ Indicates which replica set member processed the replSetGetStatus command.
-
replSetGetStatus.members[n].lastHeartbeat¶ An ISODate formatted date and time that reflects the last time the server that processed the replSetGetStatus command received a response from a heartbeat that it sent to this member (
members[n]). Compare this value to the values of thedateandlastHeartBeatRecvfields to track latency between these replica set members.This value is only available for replica set members other than the server specified by
replSetGetStatus.members[n].self.
-
replSetGetStatus.members[n].lastHeartbeatRecv¶ An ISODate formatted date and time that reflects the last time the server that processed the replSetGetStatus command received a heartbeat request from this member (
members[n]). Compare this value to the values of thedateandlastHeartBeatfields to track latency between these replica set members.This value is only available for replica set members other than the server specified by
replSetGetStatus.members[n].self.
-
replSetGetStatus.members[n].lastHeartbeatMessage¶ When the last heartbeat included an extra message, the
lastHeartbeatMessagecontains a string representation of that message.
-
replSetGetStatus.members[n].pingMs¶ The
pingMsrepresents the number of milliseconds (ms) that a round-trip packet takes to travel between the remote member and the local instance.This value does not appear for the member that returns the
rs.status()data.
-
replSetGetStatus.members[n].syncingTo¶ The
syncingTofield is only present on the output ofrs.status()on secondary and recovering members, and holds the hostname of the member from which this instance is syncing.
-
replSetGetStatus.members[n].configVersion¶ New in version 3.0.
The
configVersionvalue is thereplica set configuration version.
-