How do I count the number of messages in a Kafka topic?

I want to know how many messages are in the topic, how can I do this?

1 Like

@rmoff don’t we all want to know the answer to this :smile:
But I am certainly interested to know what others are doing to handle this.

Here are a few options: Counting the number of messages in a Kafka topic :slight_smile:

Also check out this cool vid from @gAmUssA

Another option is using the kafka.tools.GetOffsetShell command:

bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list <BROKER_LIST> --topic <TOPIC_NAME> --time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'

The source-code of this command is not very intuitive (Scala :face_vomiting:) but it may provide an idea about how it works:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.