Last active
October 27, 2022 12:16
-
-
Save bepcyc/c443859f92541d2b82142591c2fd082c to your computer and use it in GitHub Desktop.
Get kafka topic sizes in GB and sort them by size in ascending order
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 | |
topic-size() { kafka-log-dirs --command-config /opt/kafka/ssl/client.txt --bootstrap-server server:9093 --topic-list ${1} --describe | tail -n1 | jq '.brokers[0].logDirs[0].partitions | map(.size/1000000000) | add' | xargs echo ${1} =; } | |
list-topics() { kafka-topics --command-config /opt/kafka/ssl/client.txt --bootstrap-server server:9093 --list; } | |
export -f topic-size | |
TEMP_FILE=$(mktemp) | |
list-topics | xargs -I{} bash -c 'topic-size "{}"' > $TEMP_FILE | |
sort -g -k3 $TEMP_FILE | |
rm $TEMP_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will list only size of logDir 0 in broker 0 right?