0
0
RabbitMQdevops~30 mins

Alerting on queue depth and consumer lag in RabbitMQ - Mini Project: Build & Apply

Choose your learning style9 modes available
Alerting on queue depth and consumer lag
📖 Scenario: You are managing a RabbitMQ message broker in a small company. You want to keep an eye on how many messages are waiting in the queue and how far behind the consumers are in processing those messages. This helps you avoid delays and system overload.
🎯 Goal: Build a simple Python script that checks the queue depth and consumer lag from RabbitMQ's management API and alerts if these values go above a set limit.
📋 What You'll Learn
Create a dictionary with queue names and their current depths
Set a threshold value for maximum allowed queue depth
Write a loop to find queues exceeding the threshold
Print alert messages for queues that are too deep
💡 Why This Matters
🌍 Real World
Monitoring RabbitMQ queues helps keep message processing smooth and prevents delays in applications.
💼 Career
DevOps engineers often set up alerts on message brokers to maintain system health and respond quickly to issues.
Progress0 / 4 steps
1
Create a dictionary with queue depths
Create a dictionary called queue_depths with these exact entries: 'orders': 120, 'payments': 80, 'notifications': 30.
RabbitMQ
Need a hint?

Use curly braces to create a dictionary and separate key-value pairs with commas.

2
Set the alert threshold
Create a variable called max_depth and set it to 100.
RabbitMQ
Need a hint?

Just assign the number 100 to the variable max_depth.

3
Find queues exceeding the threshold
Use a for loop with variables queue and depth to iterate over queue_depths.items(). Inside the loop, create a list called alert_queues before the loop and append queue to it if depth is greater than max_depth.
RabbitMQ
Need a hint?

Remember to create the alert_queues list before the loop. Use an if statement inside the loop to check depth.

4
Print alert messages
Write a for loop to iterate over alert_queues and print the message "Alert: Queue '{queue}' depth is above {max_depth}" for each queue.
RabbitMQ
Need a hint?

Use a for loop to print the alert message for each queue in alert_queues. Use an f-string for formatting.