Reputation: 1510
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?
Upvotes: 13
Views: 18911
Reputation: 4347
Starting from Kafka 3.3.1, Kafka uses KRaft instead of ZooKeeper to elect/manage the active controller. See this question on how to find the active controller in such a cluster.
Upvotes: 2
Reputation: 122
Also by calling zookeeper-shell.sh twice, we can get directly the broker name that is the active controller, instead of the broker id.
Example for a zookeeper instance running on localhost:
/opt/kafka/bin/zookeeper-shell.sh localhost get /brokers/ids/$(/opt/kafka/bin/zookeeper-shell.sh localhost get /controller|tail -1|jq .brokerid)|tail -1|jq .endpoints[]
Upvotes: 1
Reputation: 26865
You can find the active controller using the zookeeper-shell
tool as follows:
./bin/zookeeper-shell.sh [ZK_IP] get /controller
Upvotes: 25
Reputation: 336
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.
Upvotes: 10