Reputation: 31
I have a kafka cluster with 3 brokers, I would like to know the total number of topics in the cluster.
Is there a script or any command to find out the total.
Upvotes: 2
Views: 1534
Reputation: 26875
There are multiple ways to find this out:
listTopics()
and just call size()
on names()
.kafka-topics.sh
tool: You can use ./kafka-topics.sh --zookeeper localhost --list | wc -l
.A topic is just a group of partitions. For Kafka it's the same if you have 1 topics with 10 partitions or 10 topics with 1 partition each. However, 10 topics with 1 partitions is not the same as 10 topics with 10 partitions each. That's why, in practice, you are usually interested in the number of partitions.
To count partitions:
kafka.server:type=ReplicaManager,name=PartitionCount
kafka-topics.sh
tool: You can use ./kafka-topics.sh --zookeeper localhost --describe | grep "Partition:" | wc -l
listTopics()
) and then call describeTopics()
. The number of partitions for each topic is available in the TopicDescription
object you get back.Upvotes: 2