Cluster Reliability / Video: Assessing Cluster Health

Code Recap: Assessing Cluster Health

Assessing Cluster Health and opCounters with db.serverStatus()

Below is the code used to run the db.serverStatus(), rs.printReplicationInfo(), and rs.printSecondaryReplication() methods with mongosh.

db.serverStatus() Method

Use the db.serverStatus() method to return an overview of the database’s state and various metrics, including opcounters, in mongosh.

db.serverStatus()

Use db.serverStatus().opcounters to return a document that reports on database operations by type since the mongod instance last started.

These numbers will grow over time until the next restart. Analyze these values over time to track database utilization.

db.serverStatus().opcounters

Example Output:

{
  insert: Long('0'),
  query: Long('84'),
  update: Long('0'),
  delete: Long('0'),
  getmore: Long('0'),
  command: Long('3694757')
}

Checking oplog and replication status with rs.printReplicationInfo() and rs.printSecondaryReplicationInfo()

rs.printReplicationInfo() Method

Use the rs.printReplicationInfo() method to return a formatted report of the replica set member's oplog. The displayed report formats the data returned by db.getReplicationInfo().

rs.printReplicationInfo()

Example Output:

configured oplog size:   990MB
log length start to end: 65422secs (18.17hrs)
oplog first event time:  Mon Jun 23 2014 17:47:18 GMT-0400 (EDT)
oplog last event time:   Tue Jun 24 2014 11:57:40 GMT-0400 (EDT)
now:                     Thu Jun 26 2014 14:24:39 GMT-0400 (EDT)

rs.printSecondaryReplicationInfo() Method

Use rs.printSecondaryReplicationInfo() to return a formatted report of the replica set status from the perspective of the secondary member of the set. The output is identical to db.printSecondaryReplicationInfo().

rs.printSecondaryReplicationInfo()

Example Output:

source: m1.example.net:27002
    syncedTo: Mon Mar 01 2021 16:30:50 GMT-0800 (PST)
    0 secs (0 hrs) behind the primary
source: m2.example.net:27003
    syncedTo: Mon Mar 01 2021 16:30:50 GMT-0800 (PST)
    0 secs (0 hrs) behind the primary