hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject svn commit: r884476 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
Date Thu, 26 Nov 2009 09:37:26 GMT
Author: apurtell
Date: Thu Nov 26 09:37:25 2009
New Revision: 884476

URL: http://svn.apache.org/viewvc?rev=884476&view=rev
Log:
HBASE-2011 Add zktop like output to HBase's master UI

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=884476&r1=884475&r2=884476&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Nov 26 09:37:25 2009
@@ -207,6 +207,8 @@
                dfsadmin -safemode wait"
    HBASE-2009  [EC2] Support mapreduce
    HBASE-2012  [EC2] LZO support
+   HBASE-2011  Add zktop like output to HBase's master UI (Lars George via
+               Andrew Purtell)
 
   NEW FEATURES
    HBASE-1901  "General" partitioner for "hbase-48" bulk (behind the api, write

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java?rev=884476&r1=884475&r2=884476&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java Thu
Nov 26 09:37:25 2009
@@ -19,8 +19,12 @@
  */
 package org.apache.hadoop.hbase.zookeeper;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
 import java.net.InetAddress;
+import java.net.Socket;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
@@ -171,8 +175,62 @@
     for (HServerAddress address : scanRSDirectory()) {
       sb.append("\n    - ").append(address);
     }
+    sb.append("\n  Quorum Server Statistics:");
+    String[] servers = quorumServers.split(",");
+    for (String server : servers) {
+      sb.append("\n    - ").append(server);
+      try {
+        String[] stat = getServerStats(server);
+        for (String s : stat) {
+          sb.append("\n        ").append(s);
+        }
+      } catch (Exception e) {
+        sb.append("\n        ERROR: ").append(e.getMessage());
+      }
+    }
     return sb.toString();
   }
+  
+  /**
+   * Gets the statistics from the given server. Uses a 1 minute timeout.
+   * 
+   * @param server  The server to get the statistics from.
+   * @return The array of response strings.
+   * @throws IOException When the socket communication fails.
+   */
+  public String[] getServerStats(String server) 
+  throws IOException {
+    return getServerStats(server, 1 * 60 * 1000);
+  }
+  
+  /**
+   * 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.
+   */
+  public String[] getServerStats(String server, int timeout) 
+  throws IOException {
+    String[] sp = server.split(":");
+    Socket socket = new Socket(sp[0], 
+      sp.length > 1 ? Integer.parseInt(sp[1]) : 2181);
+    socket.setSoTimeout(timeout);
+    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
+    BufferedReader in = new BufferedReader(new InputStreamReader(
+      socket.getInputStream()));
+    out.println("stat");
+    out.flush();
+    ArrayList<String> res = new ArrayList<String>();
+    while (true) {
+      String line = in.readLine();
+      if (line != null) res.add(line);
+      else break;
+    }
+    socket.close();
+    return res.toArray(new String[res.size()]);
+  }
 
   private boolean exists(String znode) {
     try {



Mime
View raw message