Created
February 5, 2021 16:44
-
-
Save hiimivantang/4ac57adccfe335aa8f5ec8942a7a71aa to your computer and use it in GitHub Desktop.
Sample bash script to get total message count of a Kafka topic.
This file contains 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
#!/bin/bash | |
brokers="localhost:9092" | |
topic=<YOUR TOPIC> | |
sum_1=$(/<YOUR_KAFKA_BIN_DIRECTORY>/kafka-run-class kafka.tools.GetOffsetShell --broker-list $brokers --topic $topic --time -1 | grep -e ':[[:digit:]]*:' | awk -F ":" '{sum += $3} END {print sum}') | |
sum_2=$(/<YOUR_KAFKA_BIN_DIRECTORY>/kafka-run-class kafka.tools.GetOffsetShell --broker-list $brokers --topic $topic --time -2 | grep -e ':[[:digit:]]*:' | awk -F ":" '{sum += $3} END {print sum}') | |
echo "Number of records in topic ${topic}: "$((sum_1 - sum_2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment