Effective monitoring is crucial for maintaining MongoDB performance and reliability. This guide covers monitoring tools, key metrics, and best practices for database optimization.
# Server Status
db.serverStatus()
# Current Operations
db.currentOp()
# Database Stats
db.stats()
# Collection Stats
db.collection.stats()
# Explain Query
db.collection.find().explain()
# Enable Profiling
db.setProfilingLevel(1, { slowms: 100 })
# View Profile Data
db.system.profile.find()
# Analyze Query Performance
db.collection.find().explain("executionStats")
# Index Usage
db.collection.aggregate([
{ $indexStats: {} }
])
# Set Up Alerts
db.adminCommand({
setParameter: 1,
slowms: 100,
slowOpSampleRate: 0.5
})
# Configure Notifications
{
"alerts": [
{
"metric": "opcounters",
"threshold": 1000,
"duration": "5m"
},
{
"metric": "connections",
"threshold": 100,
"duration": "1m"
}
]
}
Now that you understand MongoDB monitoring, you can explore: