Other than using JMX is there any other way to know, whether a broker is an ActiveController?
I know that the cluster generates a metric kafka.controller:type=KafkaController,name=ActiveControllerCount
, but I cannot find which broker is the active controller.
Is it necessary to write a JMX client to know it or is there another (better?) way?
The recommended way to detect if a given broker is the controller is via the kafka. controller:type=KafkaController,name=ActiveControllerCount metric.
Controller Broker (KafkaController) is a Kafka service that runs on every broker in a Kafka cluster, but only one can be active (elected) at any point in time. The process of promoting a broker to be the active controller is called Kafka Controller Election.
Active controller In a Kafka cluster, one of the brokers serves as the controller, which is responsible for managing the states of partitions and replicas and for performing administrative tasks like reassigning partitions. At any given time there is only one controller broker in your cluster.
There are 2 ways to get the list of available brokers in a Kafka cluster. Both with the help of scripts from zookeeper. Zookeeper manages the leader election and other coordination things for a Kafka cluster. So Zookeeper has a list of all the Kafka brokers in the cluster.
You can find the active controller using the zookeeper-shell
tool as follows:
./bin/zookeeper-shell.sh [ZK_IP] get /controller
Perhaps easier way, since you don't need to have kafka and it's zookeeper-shell.sh, is using command line to connect to zookeeper's client port with:
nc [zookeeper_ip] [zookeeper_port]
or
telnet [zookeeper_ip] [zookeeper_port]
and then executing
dump
It will print sessions with ephemeral nodes and one can see which broker is a controller by finding session that contains /controller path
For example, a dump result like this:
Sessions with Ephemerals (3):
0x266542cfaa90000:
/brokers/ids/1
0x166542cfe670001:
/brokers/ids/3
0x166542cfe670000:
/controller
/brokers/ids/2
means that controller is a broker whose broker_id is 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With