Skip to content

Instantly share code, notes, and snippets.

@davewat
Last active March 30, 2022 19:03
Show Gist options
  • Save davewat/b3c5c4a383d1d9d26df33ecbb6ddd668 to your computer and use it in GitHub Desktop.
Save davewat/b3c5c4a383d1d9d26df33ecbb6ddd668 to your computer and use it in GitHub Desktop.
Kafka commands and scripts
# Calculate the latest and earliest offsets, and provide the total # of messages in the topic (the difference):
#!/bin/bash
if [[ $# -eq 0 ]] ; then
echo 'provide the name of a topic to get totals against'
exit 0
fi
latest=`bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic $1 --time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'`
earliest=`bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic $1 --time -2 --offsets 1 | awk -F ":" '{sum2 += $3} END {print sum2}'`
total=`expr $latest - $earliest`
echo Latest Total $latest
echo Earliest Total $earliest
echo InQueue Total $total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment