0
0
Kafkadevops~5 mins

Key broker metrics in Kafka - Commands & Configuration

Choose your learning style9 modes available
Introduction
Kafka brokers handle messages between producers and consumers. Monitoring key broker metrics helps keep the system healthy and fast by showing how well brokers are working and if there are any problems.
When you want to check if your Kafka broker is handling messages without delays
When you need to find out if brokers are overloaded or under heavy load
When you want to monitor network traffic between brokers and clients
When you want to track message processing rates to ensure smooth data flow
When you want to detect errors or failures in broker operations early
Commands
This command connects to the Kafka broker's JMX interface to get the current rate of incoming messages per second. It helps you see how many messages the broker is receiving.
Terminal
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
Expected OutputExpected
kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec Count=12345.0 OneMinuteRate=150.0 FiveMinuteRate=140.0 FifteenMinuteRate=130.0 MeanRate=145.0
--jmx-url - Specifies the JMX connection URL to the Kafka broker
--object-name - Specifies the exact metric to query from the broker
This command fetches the rate of Produce requests per second handled by the broker. It shows how many produce operations the broker processes.
Terminal
kafka-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
Expected OutputExpected
kafka.network:type=RequestMetrics,name=RequestsPerSec,request=Produce Count=6789.0 OneMinuteRate=80.0 FiveMinuteRate=75.0 FifteenMinuteRate=70.0 MeanRate=77.0
--jmx-url - Connects to the broker's JMX interface
--object-name - Specifies the Produce request metric
This command checks how many partitions are under-replicated, meaning they don't have enough copies for safety. It helps detect risks to data durability.
Terminal
kafka-run-class.sh kafka.tools.JmxTool --jmx-url service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi --object-name kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions
Expected OutputExpected
kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions Value=0
--jmx-url - Connects to the broker's JMX interface
--object-name - Checks under-replicated partitions metric
This command shows the rate of failed requests per second on the broker. It helps identify if the broker is having trouble processing requests.
Terminal
kafka-run-class.sh kafka.tools.JmxTool --jmx-url service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi --object-name kafka.network:type=RequestMetrics,name=FailedRequestsPerSec
Expected OutputExpected
kafka.network:type=RequestMetrics,name=FailedRequestsPerSec Count=2.0 OneMinuteRate=0.01 FiveMinuteRate=0.02 FifteenMinuteRate=0.01 MeanRate=0.015
--jmx-url - Connects to the broker's JMX interface
--object-name - Fetches failed requests metric
Key Concept

If you remember nothing else from this pattern, remember: monitoring key Kafka broker metrics through JMX helps you keep your messaging system healthy and responsive.

Common Mistakes
Trying to run JMX commands without enabling JMX on the Kafka broker
The commands fail because the broker is not exposing metrics for JMX to connect
Start the Kafka broker with JMX enabled by setting environment variable KAFKA_JMX_OPTS before running the broker
Using wrong JMX URL or port when running kafka-run-class.sh JmxTool
The tool cannot connect to the broker's JMX interface and returns connection errors
Verify the JMX port and URL configured on the broker and use the exact same in the command
Querying incorrect or misspelled metric names in --object-name
The tool returns no data or errors because the metric does not exist
Use exact metric names as documented in Kafka metrics reference
Summary
Use kafka-run-class.sh with JmxTool to query Kafka broker metrics via JMX.
Check metrics like MessagesInPerSec, RequestsPerSec, UnderReplicatedPartitions, and FailedRequestsPerSec to monitor broker health.
Ensure JMX is enabled and the correct JMX URL and metric names are used for successful queries.