private static String[] getServerStats(String server, int timeout) throws IOException {
    String[] sp = server.split(":");
    if (sp.length == 0) {
      return null;
    }

    String host = sp[0];
    int port = sp.length > 1 ? Integer.parseInt(sp[1]) : HConstants.DEFAULT_ZOOKEEPER_CLIENT_PORT;

    try (Socket socket = new Socket()) {
      InetSocketAddress sockAddr = new InetSocketAddress(host, port);
      if (sockAddr.isUnresolved()) {
        throw new UnknownHostException(host + " cannot be resolved");
      }
      socket.connect(sockAddr, timeout);
      socket.setSoTimeout(timeout);
      try (
        PrintWriter out = new PrintWriter(new BufferedWriter(
          new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8)), true);
        BufferedReader in = new BufferedReader(
          new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8))) {
        out.println("stat");
        out.flush();
        ArrayList<String> res = new ArrayList<>();
        while (true) {
          String line = in.readLine();
          if (line != null) {
            res.add(line);
          } else {
            break;
          }
        }
        return res.toArray(new String[res.size()]);
      }
    }
  }
Gets the statistics from the given server.
@param server  The server to get the statistics from.
@param timeout The socket timeout to use.
@return The array of response strings.
@throws IOException When the socket communication fails.
hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKDump.java