ShowConnections: Only show start and idle columns for mina backend
The nio2 backend does not provide these data, so displaying dummy values can confuse users. Modify the command to only show those columns when the backend is mina, which does support them. Change-Id: I889339a4811e38c1b02211983bde6b6e017cd600
This commit is contained in:
parent
3d6717840b
commit
a407a3fb5b
@ -42,7 +42,7 @@ Session::
|
||||
|
||||
Start::
|
||||
Time (local to the server) that this connection started.
|
||||
Only valid for MINA backend.
|
||||
Only shown for MINA backend.
|
||||
|
||||
Idle::
|
||||
Time since the last data transfer on this connection.
|
||||
@ -50,7 +50,7 @@ Idle::
|
||||
connection keep-alive, but also an encrypted keep alive
|
||||
higher up in the SSH protocol stack. That higher keep
|
||||
alive resets the idle timer, about once a minute.
|
||||
Only valid for MINA backend.
|
||||
Only shown for MINA backend.
|
||||
|
||||
User::
|
||||
The username of the account that is authenticated on this
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.sshd.commands;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE;
|
||||
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
@ -107,32 +108,41 @@ final class ShowConnections extends SshCommand {
|
||||
|
||||
hostNameWidth = wide ? Integer.MAX_VALUE : columns - 9 - 9 - 10 - 32;
|
||||
|
||||
final long now = TimeUtil.nowMs();
|
||||
stdout.print(String.format("%-8s %8s %8s %-15s %s\n", //
|
||||
"Session", "Start", "Idle", "User", "Remote Host"));
|
||||
stdout.print("--------------------------------------------------------------\n");
|
||||
for (final IoSession io : list) {
|
||||
AbstractSession s = AbstractSession.getSession(io, true);
|
||||
SshSession sd = s != null ? s.getAttribute(SshSession.KEY) : null;
|
||||
if (getBackend().equals("mina")) {
|
||||
long now = TimeUtil.nowMs();
|
||||
stdout.print(String.format("%-8s %8s %8s %-15s %s\n",
|
||||
"Session", "Start", "Idle", "User", "Remote Host"));
|
||||
stdout.print("--------------------------------------------------------------\n");
|
||||
for (final IoSession io : list) {
|
||||
checkState(io instanceof MinaSession, "expected MinaSession");
|
||||
MinaSession minaSession = (MinaSession) io;
|
||||
long start = minaSession.getSession().getCreationTime();
|
||||
long idle = now - minaSession.getSession().getLastIoTime();
|
||||
AbstractSession s = AbstractSession.getSession(io, true);
|
||||
SshSession sd = s != null ? s.getAttribute(SshSession.KEY) : null;
|
||||
|
||||
final SocketAddress remoteAddress = io.getRemoteAddress();
|
||||
MinaSession minaSession = io instanceof MinaSession
|
||||
? (MinaSession) io
|
||||
: null;
|
||||
final long start = minaSession == null
|
||||
? 0
|
||||
: minaSession.getSession().getCreationTime();
|
||||
final long idle = minaSession == null
|
||||
? now
|
||||
: now - minaSession.getSession().getLastIoTime();
|
||||
stdout.print(String.format("%8s %8s %8s %-15.15s %s\n",
|
||||
id(sd),
|
||||
time(now, start),
|
||||
age(idle),
|
||||
username(sd),
|
||||
hostname(io.getRemoteAddress())));
|
||||
}
|
||||
} else {
|
||||
stdout.print(String.format("%-8s %-15s %s\n",
|
||||
"Session", "User", "Remote Host"));
|
||||
stdout.print("--------------------------------------------------------------\n");
|
||||
for (final IoSession io : list) {
|
||||
AbstractSession s = AbstractSession.getSession(io, true);
|
||||
SshSession sd = s != null ? s.getAttribute(SshSession.KEY) : null;
|
||||
|
||||
stdout.print(String.format("%8s %8s %8s %-15.15s %s\n", //
|
||||
id(sd), //
|
||||
time(now, start), //
|
||||
age(idle), //
|
||||
username(sd), //
|
||||
hostname(remoteAddress)));
|
||||
stdout.print(String.format("%8s %-15.15s %s\n",
|
||||
id(sd),
|
||||
username(sd),
|
||||
hostname(io.getRemoteAddress())));
|
||||
}
|
||||
}
|
||||
|
||||
stdout.print("--\n");
|
||||
stdout.print("SSHD Backend: " + getBackend() + "\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user