How to monitor JMX metrics of Kafka broker on command line?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Monitoring Java Management Extensions (JMX) metrics of a Kafka broker provides insights into the broker’s performance, resource usage, and operational health. Apache Kafka, which is widely used for building real-time data pipelines and streaming applications, exposes a wide range of metrics that are crucial for monitoring and managing Kafka effectively.
Enabling JMX in Kafka
Before you can monitor any JMX metrics, you need to ensure that JMX is enabled on your Kafka brokers. By default, Kafka brokers start with JMX enabled but without remote access. To enable remote JMX access and set the JMX port, you need to add the following lines to your Kafka broker configuration (server.properties):
Accessing JMX Metrics via Command Line
Once JMX is enabled and configured, you can use various tools to monitor these metrics from the command line. The most straightforward tool is jconsole, which is included in the JDK.
Using Jconsole
- Open a terminal.
- Start
jconsoleby entering the command:
- This command connects
jconsoleto the JMX server running on the Kafka broker atlocalhoston port9999.
Using JMX Term
For a more command-line focused tool, you can use jmxterm, which is an open-source tool that provides a CLI for interacting with JMX servers.
Installing JMX Term
You can download jmxterm from its official repository (https://github.com/jiaqi/jmxterm). Extract and run it using a Java command:
Monitoring Kafka with JMX Term
- Open
jmxterm:
- You can then use commands to watch various metrics, for example:
Exporting Metrics for Prometheus
Prometheus is another powerful tool that can scrape JMX metrics if exposed correctly. Using the jmx_exporter is a popular method to expose these metrics.
Setting up JMX Exporter
- Download the
jmx_prometheus_javaagent.jarfrom its GitHub repository. - Add the following line to your Kafka’s
KAFKA_OPTSenvironment variable:
- The
config.yamlincludes rules for what metrics to expose and how.
Querying Metrics in Prometheus
After configuring, Prometheus can scrape these metrics from http://your.kafka.broker.host:7071/metrics.
Best Practices and Key Metrics to Monitor
Some of the crucial Kafka JMX metrics to track include:
- Messages in / sec: The rate at which messages are being received.
- Bytes in / sec: The rate at which bytes are being received.
- Bytes out / sec: The rate at which bytes are being sent to consumers.
- Partition count: The total number of partitions on the broker.
Summary Table
| Metric Name | Description | JMX Mbean Example |
| Messages in / sec | Rate of incoming messages | kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec |
| Bytes in / sec | Rate of incoming bytes | kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec |
| Bytes out / sec | Rate of outgoing bytes to consumers | kafka.server:type=BrokerTopicMetrics,name=BytesOutPerSec |
| Active ControllerCount | Number of active controllers in cluster | kafka.controller:type=KafkaController,name=ActiveControllerCount |
By routinely monitoring these metrics, you can gain insights into the performance and stability of your Kafka cluster and promptly address any issues that arise.
Related reading
- How to monitor messages rate in Kafka topics?
- How to monitor queue health in celery
- How to open rabbitmq in browser using docker container?
- How to pass data from Kafka to Spark Streaming?
- How to monitor the status of model training running on the server via fast-api
- How to monitor whether a ZeroMQ server exists?
- How to pass JAAS configuration kafka env variables kubernetes
- How to pass JAAS configuration kafka env variables kubernetes

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.