简体   繁体   English

如何使用单个kafka命令列出所有组中的所有主题以及每个主题中的消息总数?

[英]How to list all the topics in all groups with total count of messages in each topic with single kafka command?

I'm trying to list all topics from all group ids with total number of messages in each topic but couldn't find such command anywhere. 我正在尝试列出所有组ID中的所有主题以及每个主题中的消息总数,但是在任何地方都找不到这样的命令。 Tried the below 2 commands but expecting the results of the below commands in a single command. 尝试了以下2条命令,但希望在单个命令中获得以下命令的结果。 Please help. 请帮忙。

Command 1:(To list all topics in Kafka server) 命令1 :(列出Kafka服务器中的所有主题)

bin/kafka-topics.sh --list --zookeeper localhost:2181

Command 2:(To know the count of total messages in a topic in Kafka server) 命令2 :(要了解Kafka服务器中某个主题中的总消息数)

bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 0.0.0.0:6667 --topic topicname --time -1

I have never heard of a kafka command that can do what you want. 我从未听说过可以执行所需操作的kafka命令。 However, you can achieve this with basic shell scripting. 但是,您可以使用基本的shell脚本来实现。 This command should do the job : 此命令应完成此工作:

./bin/kafka-topics.sh --zookeeper localhost:2181 --list | while read x; do ./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic $x --time -1; done

Tested with kafka 0.10.2 running on Linux. 已在Linux上运行的kafka 0.10.2中进行了测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM