How to know the broker that is the active controller?
Asked Answered
M

4

12

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?

Menefee answered 16/1, 2018 at 18:5 Comment(0)
H
24

You can find the active controller using the zookeeper-shell tool as follows:

./bin/zookeeper-shell.sh [ZK_IP] get /controller
Heliopolis answered 16/1, 2018 at 18:41 Comment(2)
Really Cool.. Thanks a lot!, and For someone who would like to find this out via prometheus monitoring, I would suggest this as a starting pointMenefee
If you're using bitnami then do /opt/bitnami/zookeeper/bin/zkCli.sh. Once connected get /controller. To list all brokers do ls /brokers/ids.Printing
C
10

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.

Cedell answered 8/10, 2018 at 15:5 Comment(2)
This is a nice one.Joker
This should be the right and generic answer because it is not necessary that the node path will be /controller for everyone. one can also execute echo dump| 127.0.0.1 2181 from the zookeeper host itself.Kazantzakis
B
2

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.

Boesch answered 30/7 at 11:15 Comment(0)
D
1

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[]
Darlenedarline answered 13/1, 2021 at 19:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.