Skip to content

Instantly share code, notes, and snippets.

@denzhel
Created May 28, 2025 06:09
Show Gist options
  • Save denzhel/7d4110033f5768cae207ada093a99d7c to your computer and use it in GitHub Desktop.
Save denzhel/7d4110033f5768cae207ada093a99d7c to your computer and use it in GitHub Desktop.
kafka: list topics with under replicated partitions

To get the list of topics that has under replicated paritiions, use the following command:

kafka-topics.sh --bootstrap-server <broker> --describe | \
awk '/Topic:/ && /Partition:/ && /Isr:/ {
  n=split($0,a,"Replicas: "); split(a[2],b," "); r=split(b[1],_,",");
  n=split($0,a,"Isr: "); split(a[2],b," "); i=split(b[1],_,",");
  if (r != i) print $2
}' | sort | uniq

To describe the topic use:

kafka-topics.sh --bootstrap-server <broker> --describe --topic <topicName>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment