Key broker metrics in Kafka - Commands & Configuration
kafka-run-class.sh kafka.tools.JmxTool --jmx-url service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi --object-name kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec--jmx-url - Specifies the JMX connection URL to the Kafka broker--object-name - Specifies the exact metric to query from the brokerkafka-run-class.sh kafka.tools.JmxTool --jmx-url service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi --object-name kafka.network:type=RequestMetrics,name=RequestsPerSec,request=Produce--jmx-url - Connects to the broker's JMX interface--object-name - Specifies the Produce request metrickafka-run-class.sh kafka.tools.JmxTool --jmx-url service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi --object-name kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions--jmx-url - Connects to the broker's JMX interface--object-name - Checks under-replicated partitions metrickafka-run-class.sh kafka.tools.JmxTool --jmx-url service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi --object-name kafka.network:type=RequestMetrics,name=FailedRequestsPerSec--jmx-url - Connects to the broker's JMX interface--object-name - Fetches failed requests metricIf you remember nothing else from this pattern, remember: monitoring key Kafka broker metrics through JMX helps you keep your messaging system healthy and responsive.
Practice
What does the MessagesInPerSec metric in Kafka broker monitoring indicate?
Solution
Step 1: Understand the metric name
The metricMessagesInPerSecliterally means messages coming in per second to the broker.Step 2: Match the metric to its meaning
This metric counts how many messages the broker receives every second, showing its input load.Final Answer:
The number of messages the broker receives per second -> Option AQuick Check:
MessagesInPerSec = messages received per second [OK]
- Confusing message count with connection count
- Thinking it measures disk usage
- Mixing it up with partition count
Which of the following is the correct JMX metric name to monitor the broker's outgoing bytes per second?
Solution
Step 1: Identify the direction of data flow
Outgoing bytes means data sent out from the broker, so the metric should say 'Out'.Step 2: Match the exact metric name
The correct metric for outgoing bytes per second isBytesOutPerSec.Final Answer:
BytesOutPerSec -> Option CQuick Check:
Outgoing bytes = BytesOutPerSec [OK]
- Choosing BytesInPerSec which is incoming data
- Confusing messages with bytes
- Using a non-existent metric name
Given the following JMX metric values for a Kafka broker:MessagesInPerSec = 500BytesInPerSec = 1024000BytesOutPerSec = 2048000
What does this tell you about the broker's activity?
Solution
Step 1: Analyze the metric values
MessagesInPerSec is 500, BytesInPerSec is 1,024,000 bytes, BytesOutPerSec is 2,048,000 bytes.Step 2: Compare incoming and outgoing bytes
Outgoing bytes (2,048,000) is exactly twice the incoming bytes (1,024,000), meaning the broker sends out twice as much data as it receives.Final Answer:
The broker is sending out twice as much data as it receives in messages -> Option DQuick Check:
BytesOutPerSec = 2 x BytesInPerSec [OK]
- Ignoring the difference between bytes and messages
- Assuming equal incoming and outgoing bytes
- Misreading the numeric values
Consider this snippet monitoring Kafka broker metrics in Java:
double bytesIn = jmxClient.getAttribute("kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec");
double bytesOut = jmxClient.getAttribute("kafka.server:type=BrokerTopicMetrics,name=BytesOutPerSec");
if (bytesIn > bytesOut) {
System.out.println("More incoming data");
} else {
System.out.println("More outgoing data");
}What is the likely bug in this code?
Solution
Step 1: Review the if-else logic
The code checks if bytesIn is greater than bytesOut, else prints "More outgoing data".Step 2: Identify missing case handling
If bytesIn equals bytesOut, the else block runs, printing "More outgoing data" which is misleading.Final Answer:
The code does not handle the case when bytesIn equals bytesOut -> Option AQuick Check:
Equal values need explicit handling [OK]
- Assuming metric names are wrong
- Ignoring equal value scenario
- Casting to wrong data type without error
You want to alert if the Kafka broker's RequestHandlerAvgIdlePercent metric drops below 20%, indicating high load. Which approach correctly implements this check in pseudocode?
1. FetchRequestHandlerAvgIdlePercentmetric value
2. If value < 20 then alert 'High broker load'
Solution
Step 1: Understand the metric meaning
RequestHandlerAvgIdlePercentshows how idle the request handler threads are; lower means busier.Step 2: Apply the alert condition
If this value is less than 20%, it means the broker is busy, so alerting on < 20 is correct.Final Answer:
if (RequestHandlerAvgIdlePercent < 20) { alert('High broker load'); } -> Option BQuick Check:
Idle percent < 20 means high load [OK]
- Using greater than instead of less than
- Checking equality only
- Using not equal which triggers too often
Ready to prove it?
Pass the test and this pattern moves unknown
