mongodbHow to perform a health check for MongoDB?
A health check for MongoDB can be performed using the db.serverStatus()
command. This command will return a document containing a variety of metrics about the current state of the server.
> db.serverStatus()
{
"host" : "localhost:27017",
"version" : "4.2.3",
"process" : "mongod",
"pid" : NumberLong(12345),
"uptime" : NumberLong(12345),
"uptimeMillis" : NumberLong(12345),
"uptimeEstimate" : NumberLong(12345),
"localTime" : ISODate("2020-01-01T00:00:00.000Z"),
"asserts" : {
"regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 0,
"rollovers" : 0
},
"connections" : {
"current" : 5,
"available" : 2095,
"totalCreated" : NumberLong(12345)
},
"extra_info" : {
"note" : "fields vary by platform",
"heap_usage_bytes" : NumberLong(12345),
"page_faults" : NumberLong(12345)
},
"ok" : 1
}
The output of the command will provide information about the server's host, version, process, uptime, local time, asserts, connections, and extra info. This information can be used to assess the health of the MongoDB server.
Code explanation
db.serverStatus()
: command to perform a health check for MongoDBhost
: hostname of the MongoDB serverversion
: version of the MongoDB serverprocess
: process name of the MongoDB serverpid
: process ID of the MongoDB serveruptime
: uptime of the MongoDB server in secondsuptimeMillis
: uptime of the MongoDB server in millisecondsuptimeEstimate
: estimated uptime of the MongoDB serverlocalTime
: local time of the MongoDB serverasserts
: number of assertions made by the MongoDB serverconnections
: number of current, available, and total connections to the MongoDB serverextra_info
: additional information about the MongoDB serverok
: status of the MongoDB server (1 for success, 0 for failure)
Helpful links
More of Mongodb
- How to work with time series data in MongoDB?
- How to use MongoDB queue?
- How to use watch in MongoDB?
- How to check the version of MongoDB?
- How to use triggers in MongoDB?
- How to use unwind in MongoDB?
- How to list MongoDB users?
- What is MongoDB default port?
- How to remove a field from MongoDB?
- How to convert MongoDB ObjectId to string?
See more codes...