【kafka】kafka 主题、分区check脚本

image.png
image.png
image.png

$ cat check_kafka.sh

#!/bin/bash

kafka_host="xx.xx.xx.xx"
kafka_port="9092"
kafka_zookeeper_port="2189"
kafka_bin_path="/path/to/kafka/bin"


# list 出所有topic并describe每个topic详情
topics=`${kafka_bin_path}/kafka-topics.sh  --zookeeper  ${kafka_host}:${kafka_zookeeper_port} --list`
for topic in ${topics};
do
  echo "######################################################################"
  echo ""
  ${kafka_bin_path}/kafka-topics.sh --zookeeper ${kafka_host}:${kafka_zookeeper_port} --topic ${topic}  --describe
done

# list 出所有consumer_group并describe每个consumer_group详情
consumer_groups=`${kafka_bin_path}/kafka-consumer-groups.sh  --bootstrap-server  ${kafka_host}:${kafka_port}  --list`
for consumer_group in ${consumer_groups};
do
  echo "########################################################################"
  ${kafka_bin_path}/kafka-consumer-groups.sh --bootstrap-server ${kafka_host}:${kafka_port} --group ${consumer_group} --describe
done

# 修改 topic的partition,根据业务决定
partition_num="9"
${kafka_bin_path}/kafka-topics.sh --zookeeper ${kafka_host}:${kafka_zookeeper_port} --topic ${topic}  --alter  --partitions  ${partition_num}

你可能感兴趣的:(【kafka】kafka 主题、分区check脚本)