How to monitor messages rate in Kafka topics?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Monitoring the message rate in Kafka topics is essential for managing cluster throughput and ensuring optimal performance. Kafka, an open-source stream-processing software platform, is designed to handle real-time data feeds efficiently. The message rate, typically defined as the number of messages produced, consumed, or stored within a given time frame, is a critical metric in assessing the health of the Kafka environment. Here we explore several methods and tools to monitor messages rate effectively.
Kafka Metrics for Monitoring
Kafka uses JMX (Java Management Extensions) to expose metrics about brokers, topics, and other components. The key metrics related to message rates are:
- Messages In Per Sec: The number of messages being received per second.
- Bytes In/Out Per Sec: The total bytes of messages being received/sent per second.
These metrics can be monitored by accessing the broker’s JMX port with tools like jconsole, VisualVM, or programmatically using a JMX client.
Using Kafka Tools
1. Kafka-Consumer-Groups
This command-line tool can be used to gather data on consumer lag, which indirectly helps in understanding the message production and consumption rates. The command provides details about offset positions for a consumer group on a topic, which implies how quickly messages are being consumed.
Example Usage:
2. Kafka-Consumer-Offset-Checker
This older tool is primarily aimed at checking the offset of a Kafka consumer group. Though deprecated, it can still be used in environments running older versions of Kafka.
Third-Party Monitoring Tools
Several comprehensive monitoring systems integrate with Kafka to provide metrics visualization and alerting:
- Prometheus and Grafana: Prometheus can scrape JMX metrics exposed by Kafka brokers, and Grafana can be used to create dashboards showing these data points in real-time.
- Datadog: Provides a Kafka integration that includes out-of-the-box dashboards for monitoring message rates among other metrics.
- New Relic: Also integrates with Kafka to monitor message rates and allows for setting alerts based on the metrics.
Using Prometheus
Set up Prometheus to scrape Kafka JMX metrics either directly or via JMX exporter. Here is an example configuration for Prometheus:
Monitoring Throughput with Kafka Tools
Kafka also includes built-in command-line tools like kafka-producer-perf-test and kafka-consumer-perf-test which can be used to test the throughput of Kafka clusters.
Example for producer performance test:
This tool helps simulate production scenarios on your Kafka cluster, providing insights on how well your setup handles high message rates.
Summary Table
| Metric/Tool | Description | Use Case |
| Messages In Per Sec | Number of messages received per second | Monitor incoming message rate |
| Bytes In/Out Per Sec | Total bytes sent/received per second | Assess total data throughput |
| kafka-consumer-groups | Consumes group message consumption stats | Indirect message rate monitoring |
| Prometheus + Grafana | Metrics scraping and visual analysis | Detailed real-time monitoring and alerting |
| kafka-producer/consumer-perf-test | Tests production and consumption throughput | Testing cluster capacity under load |
Conclusion
Efficient monitoring of message rates in Kafka topics helps in diagnosing issues, ensuring performance, and planning capacity. Using a combination of Kafka’s built-in tools, JMX metrics, and third-party monitoring solutions can provide comprehensive visibility into Kafka operations and its performance in handling real-time message streams.
Related reading
- 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 pass JAAS configuration kafka env variables kubernetes
- 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 Kinesis Firehose data to dynamodb table?

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.