0
0
Kafkadevops~30 mins

JMX metrics in Kafka - Mini Project: Build & Apply

Choose your learning style9 modes available
Collecting Kafka JMX Metrics
📖 Scenario: You are managing a Kafka server and want to monitor its performance. Kafka exposes many metrics through JMX (Java Management Extensions). You will write a simple setup to collect some key JMX metrics from Kafka.
🎯 Goal: Build a small program that connects to Kafka's JMX interface, selects specific metrics, and prints their values.
📋 What You'll Learn
Create a dictionary with Kafka JMX metric names and their object names
Add a variable to specify the JMX port number
Write a loop to simulate fetching metric values from JMX
Print the collected metrics in a readable format
💡 Why This Matters
🌍 Real World
Kafka administrators monitor JMX metrics to keep track of message rates, data throughput, and broker health.
💼 Career
Understanding how to collect and process Kafka JMX metrics is useful for roles in DevOps, Site Reliability Engineering, and backend system monitoring.
Progress0 / 4 steps
1
Setup Kafka JMX metrics dictionary
Create a dictionary called kafka_metrics with these exact entries: 'MessagesInPerSec': 'kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec', 'BytesInPerSec': 'kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec', and 'BytesOutPerSec': 'kafka.server:type=BrokerTopicMetrics,name=BytesOutPerSec'.
Kafka
Need a hint?

Use curly braces to create a dictionary. Each key is a metric name string, and each value is the exact JMX object name string.

2
Set the JMX port number
Create a variable called jmx_port and set it to 9999.
Kafka
Need a hint?

Just assign the number 9999 to the variable named jmx_port.

3
Simulate fetching metric values
Write a for loop using variables metric and object_name to iterate over kafka_metrics.items(). Inside the loop, create a dictionary called collected_metrics before the loop and add each metric with a simulated value of 100.
Kafka
Need a hint?

Initialize collected_metrics as an empty dictionary. Use a for loop with metric and object_name to add each metric with value 100.

4
Print the collected metrics
Write a print statement to display the collected_metrics dictionary.
Kafka
Need a hint?

Use print(collected_metrics) to show the dictionary.