0
0
Rest APIprogramming~30 mins

API monitoring and alerting in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
API Monitoring and Alerting
📖 Scenario: You work as a DevOps engineer responsible for keeping an important web API running smoothly. Your team wants to monitor the API's response times and get alerts if it becomes slow.Imagine you have a simple script that checks the API response time and alerts if it is too high.
🎯 Goal: Build a simple API monitoring script that stores response times, sets a threshold for slow responses, checks the response times against the threshold, and prints alerts for slow responses.
📋 What You'll Learn
Create a list of API response times in milliseconds
Add a threshold variable for slow response time
Write a loop to find response times above the threshold
Print alerts for each slow response time
💡 Why This Matters
🌍 Real World
Monitoring API response times helps keep web services reliable and fast for users.
💼 Career
DevOps engineers often write scripts like this to automate monitoring and alerting for system health.
Progress0 / 4 steps
1
Create a list of API response times
Create a list called response_times with these exact values: 120, 250, 180, 300, 90
Rest API
Need a hint?

Use square brackets to create a list and separate numbers with commas.

2
Set a threshold for slow response time
Create a variable called threshold and set it to 200 to represent the maximum acceptable response time in milliseconds.
Rest API
Need a hint?

Use a simple assignment statement to create the variable.

3
Find slow response times
Use a for loop with the variable time to iterate over response_times. Inside the loop, use an if statement to check if time is greater than threshold. If yes, add time to a new list called slow_responses.
Rest API
Need a hint?

Remember to create the empty list slow_responses before the loop.

4
Print alerts for slow responses
Use a for loop with the variable slow_time to iterate over slow_responses. Inside the loop, print the message: "Alert: Slow response time detected - X ms" where X is the value of slow_time.
Rest API
Need a hint?

Use an f-string inside the print statement to include the variable value.