How to Check Kafka Broker Health Quickly and Easily
To check Kafka broker health, use the
kafka-broker-api-versions.sh or kafka-topics.sh --describe commands to verify broker connectivity and topic metadata. Additionally, monitor broker metrics via JMX or tools like kafka-consumer-groups.sh and external monitoring systems for real-time health status.Syntax
These commands help check Kafka broker health:
kafka-broker-api-versions.sh --bootstrap-server <broker_host:port>: Checks if the broker responds and lists supported API versions.kafka-topics.sh --describe --bootstrap-server <broker_host:port> --topic <topic_name>: Shows topic partitions and leader info to confirm broker leadership.kafka-consumer-groups.sh --bootstrap-server <broker_host:port> --describe --group <group_id>: Displays consumer group offsets and lag to assess broker activity.
bash
kafka-broker-api-versions.sh --bootstrap-server <broker_host:port> kafka-topics.sh --describe --bootstrap-server <broker_host:port> --topic <topic_name> kafka-consumer-groups.sh --bootstrap-server <broker_host:port> --describe --group <group_id>
Example
This example checks broker health by listing API versions and describing a topic:
bash
kafka-broker-api-versions.sh --bootstrap-server localhost:9092 kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test-topic
Output
apiVersions:
ApiVersionsResponse(apiKeys=[ApiVersionsResponse.ApiVersion(apiKey=0, minVersion=0, maxVersion=9), ...])
Topic: test-topic PartitionCount: 3 ReplicationFactor: 1 Configs:
Partition: 0 Leader: 1 Replicas: 1 Isr: 1
Partition: 1 Leader: 1 Replicas: 1 Isr: 1
Partition: 2 Leader: 1 Replicas: 1 Isr: 1
Common Pitfalls
Common mistakes when checking Kafka broker health include:
- Using incorrect
--bootstrap-serveraddresses causing connection failures. - Not specifying the correct topic or consumer group, leading to empty or misleading output.
- Ignoring broker metrics and logs which provide deeper health insights.
- Assuming a broker is healthy just because it responds; always check partition leadership and ISR (in-sync replicas).
bash
Wrong command example: kafka-topics.sh --describe --bootstrap-server wronghost:9092 --topic test-topic Right command example: kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test-topic
Quick Reference
Summary tips for checking Kafka broker health:
- Use
kafka-broker-api-versions.shto verify broker responsiveness. - Describe topics with
kafka-topics.shto check partition leaders and ISR. - Check consumer group lag with
kafka-consumer-groups.shto monitor broker activity. - Use JMX metrics or monitoring tools like Prometheus for continuous health tracking.
Key Takeaways
Use kafka-broker-api-versions.sh to quickly check if a broker is responsive.
Describe topics to verify partition leaders and in-sync replicas for broker health.
Check consumer group offsets and lag to assess broker activity and message flow.
Always use correct bootstrap server addresses to avoid connection errors.
Combine CLI checks with monitoring tools for comprehensive broker health insights.