Monitoring with Atlas metrics helps you keep an eye on your MongoDB database health and performance. It shows you important numbers so you can fix problems early.
0
0
Monitoring with Atlas metrics in MongoDB
Introduction
You want to check if your database is running smoothly.
You need to find out why your app is slow by looking at database stats.
You want to get alerts when something unusual happens in your database.
You want to track usage trends over time to plan for growth.
You want to share database performance reports with your team.
Syntax
MongoDB
Use MongoDB Atlas UI or API to view metrics like: - CPU Usage - Memory Usage - Disk I/O - Connections - Operation Counts Example API call: curl -u "<publicKey>:<privateKey>" \ --digest \ "https://cloud.mongodb.com/api/atlas/v1.0/groups/<GROUP-ID>/processes/<HOST>:<PORT>/measurements?granularity=PT1M&metrics=CPU_USER,CONNECTIONS_CURRENT"
Atlas metrics are available in the Atlas web interface under the 'Metrics' tab.
You can use the Atlas API to get metrics programmatically for automation or alerts.
Examples
This command fetches CPU and memory usage every 5 minutes for the specified host.
MongoDB
curl -u "publicKey:privateKey" --digest "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345/processes/myhost:27017/measurements?granularity=PT5M&metrics=CPU_USER,MEMORY_RESIDENT"
This shows a live graph of how many clients are connected to your database.
MongoDB
In Atlas UI, go to your cluster > Metrics tab > Select 'Connections' to see current connections graph.Sample Program
This command requests the number of insert and query operations per minute from the MongoDB Atlas API for the given host.
MongoDB
curl -u "myPublicKey:myPrivateKey" --digest "https://cloud.mongodb.com/api/atlas/v1.0/groups/abc123/processes/mydbhost:27017/measurements?granularity=PT1M&metrics=OPCOUNTS_INSERT,OPCOUNTS_QUERY"
OutputSuccess
Important Notes
Always keep your API keys secure and never share them publicly.
Use the Atlas UI for quick checks and the API for automation or detailed analysis.
Metrics granularity options include 1 minute (PT1M), 5 minutes (PT5M), and 1 hour (PT1H).
Summary
Atlas metrics help you watch your MongoDB database health easily.
You can use the Atlas UI or API to get these metrics.
Monitoring helps catch problems early and keep your app fast.