Skip to content

Instantly share code, notes, and snippets.

@farukcankaya
Created May 31, 2022 16:57
Show Gist options
  • Save farukcankaya/30c63e85e59e904f6d422eab2f5ba8f7 to your computer and use it in GitHub Desktop.
Save farukcankaya/30c63e85e59e904f6d422eab2f5ba8f7 to your computer and use it in GitHub Desktop.
Check number of consumers in given consumer group with CLI
#!/bin/bash
# Usage
# Make install_kafka.sh and check_consumers.sh executable via `chmod +x _file_`.
# Then, run the script:
# ./check_consumers.sh -g 'consumer.group.retry' -b 'localhost:9092,localhost:9093'
while getopts g:b: flag
do
case "${flag}" in
g) consumer_group_name_to_check=${OPTARG};;
b) brokers=${OPTARG};;
esac
done
echo "Check if $consumer_group_name_to_check exists in:"
for broker in ${brokers//,/ }
do
echo -n "- $broker... "
consumer_group=`bin/kafka-consumer-groups.sh --list --bootstrap-server $broker | grep $consumer_group_name_to_check`
#[ -z "$consumer_group" ] && echo "NOT EXIST" || echo "OK"
if [ -z "$consumer_group" ]
then
echo "NOT EXIST"
else
echo -n "OK "
consumer_count=`bin/kafka-consumer-groups.sh --describe --group "$consumer_group" --bootstrap-server $broker --members | wc -l`
default_count=2
consumer_count=$((consumer_count-default_count))
if [ "$consumer_count" -gt "0" ]
then
echo "There are $consumer_count consumers"
else
echo "CIS"
fi
fi
done
apt-get update && apt install wget
wget https://dlcdn.apache.org/kafka/3.2.0/kafka_2.13-3.2.0.tgz
tar -xzf kafka_2.13-3.2.0.tgz
cd kafka_2.13-3.2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment