|
@@ -19,6 +19,7 @@
|
|
|
package org.apache.zookeeper.server;
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* Basic Server Statistics
|
|
|
*/
|
|
@@ -29,13 +30,14 @@ public class ServerStats {
|
|
|
private long minLatency = Long.MAX_VALUE;
|
|
|
private long totalLatency = 0;
|
|
|
private long count = 0;
|
|
|
-
|
|
|
+
|
|
|
private final Provider provider;
|
|
|
|
|
|
public interface Provider {
|
|
|
public long getOutstandingRequests();
|
|
|
public long getLastProcessedZxid();
|
|
|
public String getState();
|
|
|
+ public int getNumAliveConnections();
|
|
|
}
|
|
|
|
|
|
public ServerStats(Provider provider) {
|
|
@@ -75,9 +77,14 @@ public class ServerStats {
|
|
|
}
|
|
|
|
|
|
public String getServerState() {
|
|
|
- return provider.getState();
|
|
|
+ return provider.getState();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /** The number of client connections alive to this server */
|
|
|
+ public int getNumAliveClientConnections() {
|
|
|
+ return provider.getNumAliveConnections();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String toString(){
|
|
|
StringBuilder sb = new StringBuilder();
|
|
@@ -85,6 +92,8 @@ public class ServerStats {
|
|
|
+ getAvgLatency() + "/" + getMaxLatency() + "\n");
|
|
|
sb.append("Received: " + getPacketsReceived() + "\n");
|
|
|
sb.append("Sent: " + getPacketsSent() + "\n");
|
|
|
+ sb.append("Connections: " + getNumAliveClientConnections() + "\n");
|
|
|
+
|
|
|
if (provider != null) {
|
|
|
sb.append("Outstanding: " + getOutstandingRequests() + "\n");
|
|
|
sb.append("Zxid: 0x"+ Long.toHexString(getLastProcessedZxid())+ "\n");
|
|
@@ -123,7 +132,6 @@ public class ServerStats {
|
|
|
packetsReceived = 0;
|
|
|
packetsSent = 0;
|
|
|
}
|
|
|
-
|
|
|
synchronized public void reset() {
|
|
|
resetLatency();
|
|
|
resetRequestCounters();
|