Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2632,7 +2632,9 @@ Available commands include:
Information on client connections to server.
Note, depending on the number of client connections this operation may be expensive
(i.e. impact server performance).
Returns "connections", a list of connection info objects.
Returns "connections", a list of connection info objects. Each object
includes "auth_info", the list of authenticated identities (scheme and id)
of the connection.

* *hash*:
Txn digests in the historical digest list.
Expand Down Expand Up @@ -2716,7 +2718,8 @@ Available commands include:

* *stat_reset/srst* :
Resets server statistics. This is a subset of the information returned
by *server_stats* and *stats*.
by *server_stats* and *stats*. On the leader, proposal statistics are
also reset.
No new fields returned.

* *observers/obsr* :
Expand Down
17 changes: 17 additions & 0 deletions zookeeper-docs/src/main/resources/markdown/zookeeperJMX.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,20 @@ standalone is only used in development situations.
| ZooKeeperServer | StandaloneServer_port<#> | Statistics on the running server, also operations to reset these attributes. Note that the object name includes the client port of the server (name suffix). |
| DataTree | InMemoryDataTree | Statistics on the in memory znode database, also operations to access finer (and more computationally intensive) statistics on the data (such as ephemeral count). |
| ServerCnxn | < session_id > | Statistics on each client connection, also operations on those connections (such as termination). Note the object name is the session id of the connection in hex form. |

### Request and connection counters

The ZooKeeperServer MBean (including its Leader, Follower and Observer
subclasses) also exposes the following `long` attributes. Latencies are in
milliseconds and are measured for requests received from this server's clients.

| Attribute | Description |
|-----------|-------------|
| ReadRequestCount / WriteRequestCount | Requests counted as reads (exists, getData, getChildren, getChildren2, getACL) or writes (create, delete, setData, setACL, and multi containing a create, delete or setData result). Other operations are not counted. |
| Min/Avg/MaxReadRequestLatency | Read latency since the last latency reset. |
| Min/Avg/MaxWriteRequestLatency | Write latency since the last latency reset. |
| ConnectionCreateCount / ConnectionCloseCount | Established client connections opened and closed. Connections rejected before being established, such as failed TLS handshakes, are not counted. |
| SessionCreateCount / SessionCloseCount | Client connections that registered or unregistered a session connection MBean. A session moving to another connection or server is counted again. |

`resetLatency` resets the latency attributes, `resetMaxLatency` sets each maximum
to its current minimum, and `resetStatistics` resets all of these attributes.
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ public void processRequest(Request request) {
switch (request.type) {
case OpCode.ping: {
lastOp = "PING";
updateStats(request, lastOp, lastZxid);
updateStats(request.type, request, lastOp, lastZxid);
Comment thread
bellatrix007 marked this conversation as resolved.
Resolved

responseSize = cnxn.sendResponse(new ReplyHeader(ClientCnxn.PING_XID, lastZxid, 0), null, "response");
return;
}
case OpCode.createSession: {
lastOp = "SESS";
updateStats(request, lastOp, lastZxid);
updateStats(request.type, request, lastOp, lastZxid);

zks.finishSessionInit(request.cnxn, true);
return;
Expand Down Expand Up @@ -612,7 +612,31 @@ public void processRequest(Request request) {

ReplyHeader hdr = new ReplyHeader(request.cxid, lastZxid, err.intValue());

updateStats(request, lastOp, lastZxid);
int type = request.type;
if (type == OpCode.multi) {
// check if contains only read operation
boolean containsWrite = false;
// Throttled or failed multi requests have no sub-results.
if (rc != null && rc.multiResult != null) {
for (ProcessTxnResult subTxnResult : rc.multiResult) {
switch (subTxnResult.type) {
case OpCode.create:
case OpCode.delete:
case OpCode.setData:
containsWrite = true;
break;
case OpCode.check:
case OpCode.error:
default:
break;
}
}
}
if (!containsWrite) {
type = OpCode.check;
}
}
updateStats(type, request, lastOp, lastZxid);

try {
if (path == null || rsp == null) {
Expand Down Expand Up @@ -693,12 +717,12 @@ public void shutdown() {
LOG.info("shutdown of request processor complete");
}

private void updateStats(Request request, String lastOp, long lastZxid) {
private void updateStats(int type, Request request, String lastOp, long lastZxid) {
if (request.cnxn == null) {
return;
}
long currentTime = Time.currentElapsedTime();
zks.serverStats().updateLatency(request, currentTime);
zks.serverStats().updateLatency(type, request, currentTime);
request.cnxn.updateStatsForResponse(request.cxid, lastZxid, lastOp, request.createTime, currentTime);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ public boolean removeCnxn(NIOServerCnxn cnxn) {
if (!cnxns.remove(cnxn)) {
return false;
}
increaseConnectionCloseCount();
cnxnExpiryQueue.remove(cnxn);

removeCnxnFromSessionMap(cnxn);
Expand Down Expand Up @@ -816,6 +817,7 @@ private void addCnxn(NIOServerCnxn cnxn) throws IOException {
set.add(cnxn);

cnxns.add(cnxn);
increaseConnectionCreateCount();
touchCnxn(cnxn);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void close() {
}
return;
}
factory.increaseConnectionCloseCount();
Comment thread
bellatrix007 marked this conversation as resolved.
Resolved

LOG.debug("close in progress for session id: 0x{}", Long.toHexString(sessionId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ public void operationComplete(Future<Channel> future) {
new ServerAuthenticationProvider.ServerObjs(zkServer, cnxn), null);
if (KeeperException.Code.OK != code) {
zkServer.serverStats().incrementAuthFailedCount();
LOG.error("Authentication failed for session 0x{}", Long.toHexString(cnxn.getSessionId()));
LOG.error("Authentication failed for session 0x{} from address '{}'",
Long.toHexString(cnxn.getSessionId()), cnxn.getRemoteSocketAddress());
cnxn.close(ServerCnxn.DisconnectReason.SASL_AUTH_FAILURE);
return;
}
Expand All @@ -472,7 +473,8 @@ public void operationComplete(Future<Channel> future) {
addCnxn(cnxn);
} else {
zkServer.serverStats().incrementAuthFailedCount();
LOG.error("Unsuccessful handshake with session 0x{}", Long.toHexString(cnxn.getSessionId()));
LOG.error("Unsuccessful handshake with session 0x{} from address '{}'",
Long.toHexString(cnxn.getSessionId()), cnxn.getRemoteSocketAddress());
ServerMetrics.getMetrics().UNSUCCESSFUL_HANDSHAKE.add(1);
cnxn.close(ServerCnxn.DisconnectReason.FAILED_HANDSHAKE);
}
Expand Down Expand Up @@ -777,6 +779,7 @@ public InetSocketAddress getLocalAddress() {

private void addCnxn(final NettyServerCnxn cnxn) {
cnxns.add(cnxn);
increaseConnectionCreateCount();
InetAddress addr = ((InetSocketAddress) cnxn.getChannel().remoteAddress()).getAddress();

ipMap.compute(addr, (a, cnxnCount) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ public synchronized Map<String, Object> getConnectionInfo(boolean brief) {
info.put("outstanding_requests", getOutstandingRequests());
info.put("packets_received", getPacketsReceived());
info.put("packets_sent", getPacketsSent());
info.put("auth_info", getAuthInfo());
if (!brief) {
info.put("session_id", getSessionId());
info.put("last_operation", getLastOperation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,43 @@ public static ServerCnxnFactory createFactory(InetSocketAddress addr, int maxCli

private final ConcurrentHashMap<ServerCnxn, ConnectionBean> connectionBeans = new ConcurrentHashMap<ServerCnxn, ConnectionBean>();

// Connection create count is increased after connection established. But this connection may not establish a session.
// In this case, registerConnection won't be called.
// So the following method need to be called in the implementation class.
public void increaseConnectionCreateCount() {
if (zkServer != null) {
zkServer.serverStats().incrementConnectionCreated();
}
}

// Called only when an established connection is removed from cnxns, so repeated
// close calls and connections rejected before being established are not counted.
void increaseConnectionCloseCount() {
if (zkServer != null) {
zkServer.serverStats().incrementConnectionClosed();
}
}

private void increaseSessionCreateCount() {
if (zkServer != null) {
zkServer.serverStats().incrementSessionCreated();
}
}

private void increaseSessionCloseCount() {
if (zkServer != null) {
zkServer.serverStats().incrementSessionClosed();
}
}

// Connection set is relied on heavily by four letter commands
// Construct a ConcurrentHashSet using a ConcurrentHashMap
protected final Set<ServerCnxn> cnxns = Collections.newSetFromMap(new ConcurrentHashMap<ServerCnxn, Boolean>());
public void unregisterConnection(ServerCnxn serverCnxn) {
ConnectionBean jmxConnectionBean = connectionBeans.remove(serverCnxn);
if (jmxConnectionBean != null) {
MBeanRegistry.getInstance().unregister(jmxConnectionBean);
increaseSessionCloseCount();
}
}

Expand All @@ -216,6 +246,7 @@ public void registerConnection(ServerCnxn serverCnxn) {
try {
MBeanRegistry.getInstance().register(jmxConnectionBean, zkServer.jmxServerBean);
connectionBeans.put(serverCnxn, jmxConnectionBean);
increaseSessionCreateCount();
} catch (JMException e) {
LOG.warn("Could not register connection", e);
}
Expand Down
Loading