Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Monitor whether a zookeeper instance in the zookeeper cluster is down

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

/ * *

* 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 ()

}

}

}

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report