support session timeout config. #296

pull/539/head^2
hengyunabc 6 years ago
parent 35579b8ff5
commit 1a42377a98

@ -49,6 +49,10 @@ public class Bootstrap {
private String targetIp = DEFAULT_TARGET_IP; private String targetIp = DEFAULT_TARGET_IP;
private int telnetPort = DEFAULT_TELNET_PORT; private int telnetPort = DEFAULT_TELNET_PORT;
private int httpPort = DEFAULT_HTTP_PORT; private int httpPort = DEFAULT_HTTP_PORT;
/**
* @see com.taobao.arthas.core.shell.ShellServerOptions#DEFAULT_SESSION_TIMEOUT
*/
private Long sessionTimeout;
private boolean verbose = false; private boolean verbose = false;
@ -109,6 +113,12 @@ public class Bootstrap {
this.httpPort = httpPort; this.httpPort = httpPort;
} }
@Option(longName = "session-timeout")
@Description("The session timeout seconds, default 3000")
public void setSessionTimeout(Long sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}
@Option(longName = "arthas-home") @Option(longName = "arthas-home")
@Description("The arthas home") @Description("The arthas home")
public void setArthasHome(String arthasHome) { public void setArthasHome(String arthasHome) {
@ -291,6 +301,10 @@ public class Bootstrap {
attachArgs.add(new File(arthasHomeDir, "arthas-core.jar").getAbsolutePath()); attachArgs.add(new File(arthasHomeDir, "arthas-core.jar").getAbsolutePath());
attachArgs.add("-agent"); attachArgs.add("-agent");
attachArgs.add(new File(arthasHomeDir, "arthas-agent.jar").getAbsolutePath()); attachArgs.add(new File(arthasHomeDir, "arthas-agent.jar").getAbsolutePath());
if (bootStrap.getSessionTimeout() != null) {
attachArgs.add("-session-timeout");
attachArgs.add("" + bootStrap.getSessionTimeout());
}
AnsiLog.info("Try to attach process " + pid); AnsiLog.info("Try to attach process " + pid);
AnsiLog.debug("Start arthas-core.jar args: " + attachArgs); AnsiLog.debug("Start arthas-core.jar args: " + attachArgs);
@ -411,4 +425,8 @@ public class Bootstrap {
public boolean isHelp() { public boolean isHelp() {
return help; return help;
} }
public Long getSessionTimeout() {
return sessionTimeout;
}
} }

@ -4,6 +4,7 @@ import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor; import com.sun.tools.attach.VirtualMachineDescriptor;
import com.taobao.arthas.common.AnsiLog; import com.taobao.arthas.common.AnsiLog;
import com.taobao.arthas.core.config.Configure; import com.taobao.arthas.core.config.Configure;
import com.taobao.arthas.core.shell.ShellServerOptions;
import com.taobao.middleware.cli.CLI; import com.taobao.middleware.cli.CLI;
import com.taobao.middleware.cli.CLIs; import com.taobao.middleware.cli.CLIs;
import com.taobao.middleware.cli.CommandLine; import com.taobao.middleware.cli.CommandLine;
@ -34,14 +35,17 @@ public class Arthas {
.setShortName("telnet-port").setDefaultValue(DEFAULT_TELNET_PORT); .setShortName("telnet-port").setDefaultValue(DEFAULT_TELNET_PORT);
Option httpPort = new TypedOption<Integer>().setType(Integer.class) Option httpPort = new TypedOption<Integer>().setType(Integer.class)
.setShortName("http-port").setDefaultValue(DEFAULT_HTTP_PORT); .setShortName("http-port").setDefaultValue(DEFAULT_HTTP_PORT);
Option sessionTimeout = new TypedOption<Integer>().setType(Integer.class)
.setShortName("session-timeout").setDefaultValue("" + ShellServerOptions.DEFAULT_SESSION_TIMEOUT);
CLI cli = CLIs.create("arthas").addOption(pid).addOption(core).addOption(agent).addOption(target) CLI cli = CLIs.create("arthas").addOption(pid).addOption(core).addOption(agent).addOption(target)
.addOption(telnetPort).addOption(httpPort); .addOption(telnetPort).addOption(httpPort).addOption(sessionTimeout);
CommandLine commandLine = cli.parse(Arrays.asList(args)); CommandLine commandLine = cli.parse(Arrays.asList(args));
Configure configure = new Configure(); Configure configure = new Configure();
configure.setJavaPid((Integer) commandLine.getOptionValue("pid")); configure.setJavaPid((Integer) commandLine.getOptionValue("pid"));
configure.setArthasAgent((String) commandLine.getOptionValue("agent")); configure.setArthasAgent((String) commandLine.getOptionValue("agent"));
configure.setArthasCore((String) commandLine.getOptionValue("core")); configure.setArthasCore((String) commandLine.getOptionValue("core"));
configure.setSessionTimeout((Integer)commandLine.getOptionValue("session-timeout"));
if (commandLine.getOptionValue("target-ip") == null) { if (commandLine.getOptionValue("target-ip") == null) {
throw new IllegalStateException("as.sh is too old to support web console, " + throw new IllegalStateException("as.sh is too old to support web console, " +
"please run the following command to upgrade to latest version:" + "please run the following command to upgrade to latest version:" +

@ -1,5 +1,6 @@
package com.taobao.arthas.core.config; package com.taobao.arthas.core.config;
import com.taobao.arthas.core.shell.ShellServerOptions;
import com.taobao.arthas.core.util.reflect.ArthasReflectUtils; import com.taobao.arthas.core.util.reflect.ArthasReflectUtils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -12,6 +13,7 @@ import static java.lang.reflect.Modifier.isStatic;
* *
* *
* @author vlinux * @author vlinux
* @author hengyunabc 2018-11-12
*/ */
public class Configure { public class Configure {
@ -22,6 +24,12 @@ public class Configure {
private String arthasCore; private String arthasCore;
private String arthasAgent; private String arthasAgent;
/**
* session timeout seconds
* @see com.taobao.arthas.core.shell.ShellServerOptions#DEFAULT_SESSION_TIMEOUT
*/
private long sessionTimeout = ShellServerOptions.DEFAULT_SESSION_TIMEOUT/1000;
public String getIp() { public String getIp() {
return ip; return ip;
} }
@ -70,6 +78,14 @@ public class Configure {
this.arthasCore = arthasCore; this.arthasCore = arthasCore;
} }
public long getSessionTimeout() {
return sessionTimeout;
}
public void setSessionTimeout(long sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}
// 对象的编码解码器 // 对象的编码解码器
private final static FeatureCodec codec = new FeatureCodec(';', '='); private final static FeatureCodec codec = new FeatureCodec(';', '=');

@ -79,7 +79,10 @@ public class ArthasBootstrap {
} }
try { try {
ShellServerOptions options = new ShellServerOptions().setInstrumentation(instrumentation).setPid(pid); ShellServerOptions options = new ShellServerOptions()
.setInstrumentation(instrumentation)
.setPid(pid)
.setSessionTimeout(configure.getSessionTimeout() * 1000);
shellServer = new ShellServerImpl(options, this); shellServer = new ShellServerImpl(options, this);
BuiltinCommandPack builtinCommands = new BuiltinCommandPack(); BuiltinCommandPack builtinCommands = new BuiltinCommandPack();
List<CommandResolver> resolvers = new ArrayList<CommandResolver>(); List<CommandResolver> resolvers = new ArrayList<CommandResolver>();

Loading…
Cancel
Save