0
0
MongoDBquery~30 mins

Monitoring with Atlas metrics in MongoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
Monitoring with Atlas metrics
📖 Scenario: You are managing a MongoDB database hosted on Atlas. You want to monitor the database's performance by collecting key metrics such as CPU usage, memory usage, and operation counts.This helps you keep your database healthy and respond quickly if something goes wrong.
🎯 Goal: Build a simple Python script to filter and display sample Atlas monitoring metrics for CPU usage, memory usage, and operation counts above a threshold.
📋 What You'll Learn
Create a variable called metrics with sample Atlas metrics data as a list of dictionaries.
Create a variable called threshold set to 70 to represent a usage alert level.
Use a for loop with variables metric to iterate over metrics and select only those metrics where metric['value'] is greater than threshold.
Print the filtered list of high usage metrics.
💡 Why This Matters
🌍 Real World
Monitoring database performance is crucial to avoid downtime and ensure smooth user experience. Atlas metrics help track resource usage and operation counts.
💼 Career
DevOps engineers and database administrators use monitoring scripts like this to maintain healthy cloud databases and respond quickly to issues.
Progress0 / 4 steps
1
Create sample Atlas metrics data
Create a variable called metrics and assign it a list of dictionaries with these exact entries: {'name': 'cpuUsage', 'value': 65}, {'name': 'memoryUsage', 'value': 75}, {'name': 'operationCount', 'value': 50}.
MongoDB
Need a hint?

Think of metrics as a list holding small boxes (dictionaries), each with a name and a value.

2
Set the alert threshold
Create a variable called threshold and set it to the integer 70.
MongoDB
Need a hint?

The threshold is a number that tells us when usage is too high.

3
Filter metrics above the threshold
Create an empty list called high_usage_metrics. Use a for loop with variable metric to iterate over metrics. Inside the loop, use an if statement to check if metric['value'] is greater than threshold. If yes, append metric to high_usage_metrics.
MongoDB
Need a hint?

Think of checking each metric's value and collecting only those that are too high.

4
Display the high usage metrics
Write a print statement to display the variable high_usage_metrics.
MongoDB
Need a hint?

The output should show only the metrics with values above 70.