📖 Scenario: You are managing a Kafka message system that processes orders for an online store. To keep the system healthy, you want to monitor the number of messages waiting in the queue. If the queue grows too large, it might mean the system is slow or stuck, which can cause outages.
🎯 Goal: Build a simple monitoring script that tracks the number of messages in a Kafka topic and alerts if the count exceeds a safe limit. This helps prevent outages by catching problems early.
📋 What You'll Learn
Create a dictionary called kafka_queues with these exact entries: 'orders': 120, 'payments': 80, 'shipments': 50
Create a variable called threshold and set it to 100
Use a for loop with variables topic and count to iterate over kafka_queues.items() and create a list alerts of topics where count is greater than threshold
Print the alerts list to show which topics need attention
💡 Why This Matters
🌍 Real World
Monitoring Kafka queues helps catch problems early, like slow consumers or stuck messages, preventing system outages.
💼 Career
DevOps engineers use monitoring scripts like this to keep message systems healthy and ensure smooth data flow in production.
Progress0 / 4 steps
1
Create Kafka queue message counts
Create a dictionary called kafka_queues with these exact entries: 'orders': 120, 'payments': 80, 'shipments': 50
Kafka
Hint
Use curly braces to create a dictionary with keys and values exactly as shown.
2
Set the alert threshold
Create a variable called threshold and set it to 100
Kafka
Hint
Just assign the number 100 to the variable named threshold.
3
Find topics exceeding the threshold
Use a for loop with variables topic and count to iterate over kafka_queues.items() and create a list alerts of topics where count is greater than threshold
Kafka
Hint
Use a list comprehension to filter topics where count is greater than threshold.
4
Display the alert topics
Print the alerts list to show which topics need attention
Kafka
Hint
Use print(alerts) to show the list of topics exceeding the threshold.
Practice
(1/5)
1. Why is monitoring Kafka important to prevent outages?
easy
A. It helps detect problems early before they cause failures.
B. It automatically fixes all Kafka bugs without human help.
C. It slows down Kafka to reduce load on the system.
D. It deletes old data to free up disk space.
Solution
Step 1: Understand the role of monitoring
Monitoring tracks Kafka's health and performance to spot issues early.
Step 2: Connect monitoring to outage prevention
Early detection allows quick fixes, preventing outages from happening.
Final Answer:
It helps detect problems early before they cause failures. -> Option A
Quick Check:
Monitoring = Early problem detection [OK]
Hint: Monitoring alerts you before outages happen [OK]
Common Mistakes:
Thinking monitoring fixes problems automatically
Believing monitoring slows down Kafka
Confusing monitoring with data deletion
2. Which Kafka command helps check the status of brokers to monitor their health?
easy
A. kafka-topics.sh --list
B. kafka-consumer-groups.sh --describe
C. kafka-broker-api-versions.sh --bootstrap-server localhost:9092
D. kafka-console-producer.sh --broker-list localhost:9092
Solution
Step 1: Identify commands related to broker status
kafka-broker-api-versions.sh shows broker API versions and connectivity, useful for health checks.
Step 2: Compare other commands
Other commands list topics, produce messages, or describe consumer groups, not broker health.
Final Answer:
kafka-broker-api-versions.sh --bootstrap-server localhost:9092 -> Option C
Quick Check:
Broker status command = kafka-broker-api-versions.sh [OK]
Hint: Broker health check uses kafka-broker-api-versions.sh [OK]
Common Mistakes:
Using kafka-topics.sh which lists topics, not brokers
Confusing producer or consumer commands with monitoring
Missing the --bootstrap-server option
3. Given this command output snippet from Kafka monitoring, what does it indicate?