Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all available Kafka brokers in a cluster?

Tags:

apache-kafka

I am writing a shell script to monitor kafka brokers.

I have gone through some links and found that if ZooKeeper contains a list of brokers, and if, in this list, the IP address is present, then a kafka broker is running.

I want a command that I can use in my shell script to get the broker list and check whether kafka is running.

Is there any curl command to get the kafka cluster status like elasticsearch?

like image 514
Shivkumar Mallesappa Avatar asked Oct 20 '16 06:10

Shivkumar Mallesappa


People also ask

How many brokers are there in Kafka?

A Kafka cluster has exactly one broker that acts as the Controller.

How many active controllers are there in a Kafka cluster with 10 brokers?

There is only 1 controller at a time.

How do I find my broker ID in Kafka?

you can use kafka-manager, an open-source tool powered by yahoo. Show activity on this post. This will list all of the brokers with their id and the beginning offset.

How do I check my Kafka cluster health?

If you are looking for the Kafka cluster broker status, you can use zookeeper cli to find the details for each broker as given below: ls /brokers/ids returns the list of active brokers IDs on the cluster. get /brokers/ids/<id> returns the details of the broker with the given ID.


2 Answers

This command will give you the list of the active brokers between brackets:

./bin/zookeeper-shell.sh localhost:2181 ls /brokers/ids 
like image 144
jimijazz Avatar answered Oct 13 '22 04:10

jimijazz


Alternate way using Zk-Client:

If you do not prefer to pass arguments to ./zookeeper-shell.sh and want to see the broker details from Zookeeper CLI, you need to install standalone Zookeeper (As traditional Kafka do not comes up with Jline JAR).

Once you install(unzip) the standalone Zookeeper,then:

  • Run the Zookeeper CLI:
    $ zookeeper/bin/zkCli.sh -server localhost:2181 #Make sure your Broker is already running

  • If it is successful, you can see the Zk client running as:

WATCHER::

WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] 
  • From here you can explore the broker details using various commands:

$ ls /brokers/ids # Gives the list of active brokers
$ ls /brokers/topics #Gives the list of topics
$ get /brokers/ids/0 #Gives more detailed information of the broker id '0'

like image 30
Panchu Avatar answered Oct 13 '22 05:10

Panchu