0
votes

When I describe a kafka topic it doesn't show the log end offset of any partition but show all the other metadata such as ISR,Replicas,Leader.

How do I see a log end offset of the partition for a given topic?

Ran this: ./kafka-topics.sh --zookeeper zk-service:2181 --describe --topic "__consumer_offsets"

Output Doesn't have a offset column.

Note: Need Only the log end offset.

3
kafka-consumer-groups.sh is the one you need.aran
what if there is no group which has subscribed that topicSai Sushanth
you must specify a consumer group in order to see offsets (it wouldn't have sense otherwise)aran
I only need to see the log end offsetSai Sushanth

3 Answers

2
votes

Since you're only looking for the log end offset for a topic, you can use kafka-run-class with the kafka.tools.GetOffsetShell class.

Assuming your topic is __consumer_offsets, you would get the end offset by running:

./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --time -1 --topic __consumer_offsets

Change the --broker-list localhost:9092 to your desired Kafka address. This will list all of the log end offsets for each partition in the topic.

1
votes

Following is the command you would need to get the offset of all partitions for a given kafka topic for a given consumer group:

kafka-consumer-groups --bootstrap-server <kafka-broker-list-with-ports> --describe --group <consumer-group-name>

Please note that the <consumer-group-name> at the end is important as the offsets are committed by consumers that are typically a part of a consumer group.

The output of this command may look something like:

TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID <topic-name> 0 62 62 0 <consumer-id> <host> <client>

In your post however, you're trying to get this information for the internal topic __consumer_offsets so you would need a consumer group which would have consumers consuming from this internal topic. You could perhaps do the following:

  1. kafka-console-consumer --bootstrap-server <kafka-broker-list-with-ports> --topic __consumer_offsets --formatter "kafka.coordinator.group.GroupMetadataManager\$OffsetsMessageFormatter" --max-messages 5

Output of the above command:

[<consumer-group-name>,<topic-name>,0]::[OffsetMetadata[481690879,NO_METADATA],CommitTime 1479708539051,ExpirationTime 1480313339051]

  1. Just use the <consumer-group-name> from the output and put it in the kafka-consumer-groups command mentioned in the beginning and you'll get the offset details for all the 50 partitions for the given consumer group only.

I hope this helps.

0
votes

install kafkacat, its an easy to use kafka tool:

    sudo apt-get update
    sudo apt-get install kafkacat

    kafkacat -C -b <kafka-broker-ip-and-port> -t <topic> -o -1

This will not consume anything because the offset is incremented after a message is added. But it will give you the offsets for all the partitions. Note however that this isn't the current offset that you are consuming at... The above answers will help you more in terms of looking into partition lag.