Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dpalomar/84ab2ced22739bd47834c0aa34c79ea7 to your computer and use it in GitHub Desktop.
Save dpalomar/84ab2ced22739bd47834c0aa34c79ea7 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