kafka-常用脚本2

1、查询所有kafka的topic

./kafka-topics.sh --zookeeper localhost --list

2、查看topic的详细信息

./kafka-topics.sh -zookeeper localhost --describe --topic shangwei123

3、查看kafka消费者

./kafka-consumer-groups.sh --bootstrap-server 10.44.99.77:9092 --list

4、查看kafka消费组详情

./kafka-consumer-groups.sh --bootstrap-server 10.44.99.103:9092 --describe --group console-consumer-98422

5、向某个topic中生产数据

./kafka-console-producer.sh --broker-list 127.0.0.1:9092 --topic test0921

6、消费某个topic中的数据

新:./kafka-console-consumer.sh --zookeeper 10.44.99.103:9092 --topic test0921
旧:./kafka-console-consumer.sh --bootstrap-server 10.44.99.103:9092 --topic test0921

注:--from-beginning 可以消费最开始的数据,默认从最大值开始

7、创建topic

./kafka-topics.sh --zookeeper localhost:2181 --create --partitions 3 --replication-factor 2 --topic wanglei123

8、Kafka的入库性能测试

./kafka-producer-perf-test.sh --topic wanglei123 --num-records 10000 --record-size 10  --throughput 2000 --producer-props bootstrap.servers=10.44.99.103:9092

在入库测试的时候就可以查看 topic 的数据,来查看入库了什么.

 

 

9、获取topic消息数

./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic wanglei123 --time -1
./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic wanglei123 --time -2

 

 

 

--time-1 表示要获取指定topic所有分区当前的最大位移,--time-2 表示获取当前最早位移。

两个命令的输出结果相减便可得到所有分区当前的消息总数。

分区当前的消息总数 = [--time-1] - [--time-2]

相减是因为随着 kafka 的运行,topic 中有的消息可能会被删除,,因此 --time-1 的结果其实表示的是历史上该topic生产的最大消息数,如果用户要统计当前的消息总数就必须减去 --time-2 的结果。

 

posted @ 2020-12-17 17:24  你的小可爱吖  阅读(205)  评论(0编辑  收藏  举报