Created
March 29, 2024 08:27
-
-
Save ram-pi/14a64412541d0ac7495591f2a3679c41 to your computer and use it in GitHub Desktop.
Get IPs from all groups with kafka-consumer-group cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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