0
0
Kafkadevops~20 mins

JMX metrics in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 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.