Get the App
SLTechnology News&Howtos  ›  Servers  › 

Monitor whether a zookeeper instance in the zookeeper cluster is down

Shulou Source: shulou.com Published: 2022-06-02 21:05:45 09月21日 Update

/ * *

* listen to whether a Zookeeper instance in the Zookeeper cluster is down

* @ author Administrator

*

, /

Public class ZookeeperServiceStatusTest {

Private static final String HOST = "192.168.0.128"

Private static final Integer PORT = 2182

@ Test

Public void serverStatus () throws IOException {

Socket sock = null

BufferedReader reader = null

String cmd = "status"

Try {

Sock = new Socket (HOST, PORT)

OutputStream outstream = sock.getOutputStream ()

/ / obtain the status of the server through the status command of Zookeeper

Outstream.write (cmd.getBytes ())

Outstream.flush ()

Sock.shutdownOutput ()

Reader = new BufferedReader (new InputStreamReader (sock.getInputStream ()

String line

While ((line = reader.readLine ())! = null) {

/ / if (line.indexOf ("Mode:")! =-1) {

/ / System.out.println (line.replaceAll ("Mode:", ") .trim ()

/ /}

System.out.println (line)

}

} catch (Exception e) {

System.out.println ("Zookeeper address:" + HOST + ":" + PORT + "connection failed" + "msg:" + ExceptionUtils.getStackTrace (e))

} finally {

If (sock! = null) {

Sock.close ()

}

If (reader! = null) {

Reader.close ()

}

}

}

}

Tags: Instance cluster command address server status service monitoring monitoring Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Shulou Information Huawei NVidia