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?
Here are a couple of quick functions I use when bash scripting Kafka Data Load into Demo Environments. In this example I use HDP with no security, but it is easily modified to other environments and intended to be quick and functional rather than particularly robust.
The first retrieves the address of the first ZooKeeper node from the config:
The second retrieves the Broker IDs from ZooKeeper:
The third parses ZooKeeper again to retrieve the list of Kafka Brokers Host:port ready for use in the command-line client:
This command will give you the list of the active brokers between brackets:
I did it like this
(replace localhost with the host where zookeeper is running)
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::
$ 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'
On MacOS, can try: