Skip to content

Instantly share code, notes, and snippets.

@ram-pi
Created March 29, 2024 08:27
Show Gist options
  • Save ram-pi/14a64412541d0ac7495591f2a3679c41 to your computer and use it in GitHub Desktop.
Save ram-pi/14a64412541d0ac7495591f2a3679c41 to your computer and use it in GitHub Desktop.
Get IPs from all groups with kafka-consumer-group cli
#!/usr/bin/env bash
# example usage: ./ips.sh localhost:9092 /etc/kafka/consumer.properties
# get bootstrap servers from args
BOOTSTRAP_SERVER=$1
# get properties file location from args
PROPERTIES_FILE=$2
# get list of all consumer groups
groups=$(kafka-consumer-groups --bootstrap-server $BOOTSTRAP_SERVER --command-config $PROPERTIES_FILE --all-groups --list)
> ips.txt
# loop through all consumer groups
for group in $groups
do
# get list of all consumers in the group
consumers=$(kafka-consumer-groups --bootstrap-server $BOOTSTRAP_SERVER --command-config $PROPERTIES_FILE --group $group --describe | grep -oE "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | sort -u)
# loop through all consumers in the group
for consumer in $consumers
do
# print the consumer
echo $consumer >> ips.txt
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment