Skip to content

Instantly share code, notes, and snippets.

@hiimivantang
Created February 5, 2021 16:44
Show Gist options
  • Save hiimivantang/4ac57adccfe335aa8f5ec8942a7a71aa to your computer and use it in GitHub Desktop.
Save hiimivantang/4ac57adccfe335aa8f5ec8942a7a71aa to your computer and use it in GitHub Desktop.
Sample bash script to get total message count of a Kafka topic.
#!/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