Bird
Raised Fist0
Kafkadevops~20 mins

JMX metrics in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Kafka JMX Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this JMX query for Kafka broker metrics?
Given the following JMX query executed against a Kafka broker's MBean server, what is the output?
Kafka
ObjectName name = new ObjectName("kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
AttributeList attributes = mbs.getAttributes(name, new String[]{"Count"});
for (Attribute attr : attributes.asList()) {
    System.out.println(attr.getName() + ": " + attr.getValue());
}
Ajavax.management.InstanceNotFoundException
BCount: 1000
CCount: null
DCount: 0
Attempts:
2 left
💡 Hint
Think about the default state of the metric if no messages have been processed yet.
❓ Predict Output
intermediate
2:00remaining
What error does this JMX code produce when querying a non-existent Kafka metric?
Consider this Java code snippet querying a Kafka JMX metric that does not exist. What error will it produce?
Kafka
ObjectName name = new ObjectName("kafka.server:type=BrokerTopicMetrics,name=NonExistentMetric");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.getAttribute(name, "Count");
Ajavax.management.InstanceNotFoundException
Bjavax.management.AttributeNotFoundException
CNullPointerException
DNo error, returns 0
Attempts:
2 left
💡 Hint
The MBean server throws an exception if the MBean name is not registered.
🔧 Debug
advanced
2:00remaining
Why does this JMX Kafka metric query return null instead of the expected value?
This Java code queries the 'BytesInPerSec' metric from Kafka but prints 'null'. What is the likely cause?
Kafka
ObjectName name = new ObjectName("kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Object value = mbs.getAttribute(name, "OneMinuteRate");
System.out.println(value);
AThe MBeanServer is not connected to the Kafka broker process
BThe 'OneMinuteRate' attribute is not exposed by the MBean
CThe ObjectName is incorrect and does not match any MBean
DThe 'OneMinuteRate' attribute exists but its value is zero, printed as null
Attempts:
2 left
💡 Hint
Check the attributes exposed by the 'BytesInPerSec' MBean carefully.
🧠 Conceptual
advanced
2:00remaining
Which JMX metric best indicates the current number of active Kafka connections?
Among Kafka JMX metrics, which one best reflects the current active network connections to the broker?
Akafka.network:type=SocketServer,name=ConnectionCount
Bkafka.network:type=SocketServer,name=NetworkProcessorAvgIdlePercent
Ckafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec
Dkafka.controller:type=KafkaController,name=ActiveControllerCount
Attempts:
2 left
💡 Hint
Look for a metric that counts connections, not rates or percentages.
❓ Predict Output
expert
2:00remaining
What is the output of this JMX query code snippet for Kafka's UnderReplicatedPartitions metric?
Analyze the following Java code querying Kafka's 'UnderReplicatedPartitions' metric. What will it print?
Kafka
ObjectName name = new ObjectName("kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Integer count = (Integer) mbs.getAttribute(name, "Value");
System.out.println("UnderReplicatedPartitions: " + count);
Ajavax.management.AttributeNotFoundException
BUnderReplicatedPartitions: 0
Cjavax.management.InstanceNotFoundException
DUnderReplicatedPartitions: null
Attempts:
2 left
💡 Hint
Check if the ObjectName and attribute name are correct for this metric.

Practice

(1/5)
1. What is the primary purpose of JMX metrics in Kafka?
easy
A. To configure Kafka brokers dynamically
B. To send messages between Kafka topics
C. To monitor Kafka's internal performance and health
D. To store data permanently in Kafka

Solution

  1. Step 1: Understand JMX metrics role

    JMX metrics provide data about Kafka's internal state and performance.
  2. Step 2: Identify the correct purpose

    Monitoring performance and health is the main use of JMX metrics in Kafka.
  3. Final Answer:

    To monitor Kafka's internal performance and health -> Option C
  4. Quick Check:

    JMX metrics = Monitoring Kafka [OK]
Hint: JMX metrics are for monitoring, not messaging or storage [OK]
Common Mistakes:
  • Confusing metrics with message sending
  • Thinking JMX configures Kafka brokers
  • Assuming JMX stores Kafka data
2. Which of the following is the correct way to identify a Kafka JMX metric?
easy
A. Using a topic name and partition number
B. Using a unique ObjectName and attribute
C. Using a consumer group ID
D. Using a broker ID and port number

Solution

  1. Step 1: Recall JMX metric identification

    Each JMX metric is accessed by a unique ObjectName and attribute in Kafka.
  2. Step 2: Compare options

    Only Using a unique ObjectName and attribute correctly describes the identification method for JMX metrics.
  3. Final Answer:

    Using a unique ObjectName and attribute -> Option B
  4. Quick Check:

    JMX metric ID = ObjectName + attribute [OK]
Hint: JMX metrics use ObjectName and attribute, not topic or group IDs [OK]
Common Mistakes:
  • Mixing JMX metric IDs with Kafka topic or consumer IDs
  • Confusing broker info with metric identifiers
  • Assuming partition number identifies metrics
3. Given the following Java snippet to get a Kafka JMX metric attribute, what will be the output if the metric value is 150?
ObjectName name = new ObjectName("kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Integer value = (Integer) mbs.getAttribute(name, "Count");
System.out.println(value);
medium
A. MBeanServerException
B. null
C. Count
D. 150

Solution

  1. Step 1: Understand the code's purpose

    The code queries the JMX MBeanServer for the 'Count' attribute of the specified metric.
  2. Step 2: Interpret the output

    If the metric value is 150, the printed output will be the integer 150.
  3. Final Answer:

    150 -> Option D
  4. Quick Check:

    Metric value printed = 150 [OK]
Hint: JMX attribute value prints directly if metric exists [OK]
Common Mistakes:
  • Expecting attribute name instead of value
  • Assuming null if metric exists
  • Confusing exceptions with normal output
4. You try to read a Kafka JMX metric but get a javax.management.InstanceNotFoundException. What is the most likely cause?
medium
A. The ObjectName used does not match any registered MBean
B. The Kafka broker is down
C. The attribute name is misspelled
D. The MBeanServer is not initialized

Solution

  1. Step 1: Understand the exception meaning

    InstanceNotFoundException means the requested MBean ObjectName is not found in the MBeanServer.
  2. Step 2: Identify the cause

    If the ObjectName does not match any registered MBean, this exception occurs.
  3. Final Answer:

    The ObjectName used does not match any registered MBean -> Option A
  4. Quick Check:

    InstanceNotFoundException = Wrong ObjectName [OK]
Hint: Check ObjectName spelling if InstanceNotFoundException occurs [OK]
Common Mistakes:
  • Blaming attribute name for InstanceNotFoundException
  • Assuming broker down causes this exception
  • Thinking MBeanServer is uninitialized
5. You want to monitor Kafka's message throughput using JMX metrics and alert if MessagesInPerSec.Count exceeds 1000. Which approach correctly combines JMX metric reading and alert logic in Java?
hard
A. Query the MBeanServer for the metric attribute, then compare the value to 1000 and trigger alert if greater
B. Subscribe to Kafka topic and count messages manually, ignoring JMX metrics
C. Use Kafka consumer lag metrics instead of MessagesInPerSec
D. Restart Kafka broker when MessagesInPerSec.Count exceeds 1000

Solution

  1. Step 1: Understand monitoring with JMX

    To monitor throughput, read the MessagesInPerSec.Count attribute from Kafka's JMX MBeanServer.
  2. Step 2: Implement alert logic

    Compare the retrieved metric value to 1000 and trigger an alert if it exceeds this threshold.
  3. Final Answer:

    Query the MBeanServer for the metric attribute, then compare the value to 1000 and trigger alert if greater -> Option A
  4. Quick Check:

    Read metric + compare + alert = Correct approach [OK]
Hint: Read metric value then compare to threshold for alert [OK]
Common Mistakes:
  • Ignoring JMX metrics and counting messages manually
  • Using unrelated metrics like consumer lag
  • Restarting broker instead of alerting
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard