remove default value in as.sh/arthas-boot. #1561

This commit is contained in:
hengyunabc
2020-11-03 00:50:38 +08:00
parent e13ced6fdf
commit cdec5061b4
8 changed files with 176 additions and 86 deletions
+4 -1
View File
@@ -1,7 +1,10 @@
#arthas.config.overrideAll=true
arthas.telnetPort=3658
arthas.httpPort=8563
arthas.ip=localhost
arthas.ip=127.0.0.1
# seconds
arthas.sessionTimeout=1800
#arthas.tunnelServer=ws://127.0.0.1:7777/ws
#arthas.agentId=mmmmmmyiddddd
@@ -22,9 +22,6 @@ import java.util.Properties;
*/
public class Arthas {
private static final String DEFAULT_TELNET_PORT = "3658";
private static final String DEFAULT_HTTP_PORT = "8563";
private Arthas(String[] args) throws Exception {
attachAgent(parse(args));
}
@@ -35,11 +32,11 @@ public class Arthas {
Option agent = new TypedOption<String>().setType(String.class).setShortName("agent").setRequired(true);
Option target = new TypedOption<String>().setType(String.class).setShortName("target-ip");
Option telnetPort = new TypedOption<Integer>().setType(Integer.class)
.setShortName("telnet-port").setDefaultValue(DEFAULT_TELNET_PORT);
.setShortName("telnet-port");
Option httpPort = new TypedOption<Integer>().setType(Integer.class)
.setShortName("http-port").setDefaultValue(DEFAULT_HTTP_PORT);
.setShortName("http-port");
Option sessionTimeout = new TypedOption<Integer>().setType(Integer.class)
.setShortName("session-timeout").setDefaultValue("" + Configure.DEFAULT_SESSION_TIMEOUT_SECONDS);
.setShortName("session-timeout");
Option tunnelServer = new TypedOption<String>().setType(String.class).setShortName("tunnel-server");
Option agentId = new TypedOption<String>().setType(String.class).setShortName("agent-id");
@@ -55,15 +52,20 @@ public class Arthas {
configure.setJavaPid((Long) commandLine.getOptionValue("pid"));
configure.setArthasAgent((String) commandLine.getOptionValue("agent"));
configure.setArthasCore((String) commandLine.getOptionValue("core"));
configure.setSessionTimeout((Integer)commandLine.getOptionValue("session-timeout"));
if (commandLine.getOptionValue("target-ip") == null) {
throw new IllegalStateException("as.sh is too old to support web console, " +
"please run the following command to upgrade to latest version:" +
"\ncurl -sLk https://arthas.aliyun.com/install.sh | sh");
if (commandLine.getOptionValue("session-timeout") != null) {
configure.setSessionTimeout((Integer) commandLine.getOptionValue("session-timeout"));
}
if (commandLine.getOptionValue("target-ip") != null) {
configure.setIp((String) commandLine.getOptionValue("target-ip"));
}
if (commandLine.getOptionValue("telnet-port") != null) {
configure.setTelnetPort((Integer) commandLine.getOptionValue("telnet-port"));
}
if (commandLine.getOptionValue("http-port") != null) {
configure.setHttpPort((Integer) commandLine.getOptionValue("http-port"));
}
configure.setIp((String) commandLine.getOptionValue("target-ip"));
configure.setTelnetPort((Integer) commandLine.getOptionValue("telnet-port"));
configure.setHttpPort((Integer) commandLine.getOptionValue("http-port"));
configure.setTunnelServer((String) commandLine.getOptionValue("tunnel-server"));
configure.setAgentId((String) commandLine.getOptionValue("agent-id"));
@@ -17,11 +17,11 @@ import static java.lang.reflect.Modifier.isStatic;
*/
@Config(prefix = "arthas")
public class Configure {
public static final long DEFAULT_SESSION_TIMEOUT_SECONDS = ShellServerOptions.DEFAULT_SESSION_TIMEOUT/1000;
private String ip;
private int telnetPort;
private int httpPort;
private long javaPid;
private Integer telnetPort;
private Integer httpPort;
private Long javaPid;
private String arthasCore;
private String arthasAgent;
@@ -43,8 +43,9 @@ public class Configure {
/**
* session timeout seconds
* @see ShellServerOptions#DEFAULT_SESSION_TIMEOUT
*/
private long sessionTimeout = DEFAULT_SESSION_TIMEOUT_SECONDS;
private Long sessionTimeout;
public String getIp() {
return ip;
@@ -54,7 +55,7 @@ public class Configure {
this.ip = ip;
}
public int getTelnetPort() {
public Integer getTelnetPort() {
return telnetPort;
}
@@ -66,7 +67,7 @@ public class Configure {
this.httpPort = httpPort;
}
public int getHttpPort() {
public Integer getHttpPort() {
return httpPort;
}
@@ -94,7 +95,7 @@ public class Configure {
this.arthasCore = arthasCore;
}
public long getSessionTimeout() {
public Long getSessionTimeout() {
return sessionTimeout;
}
@@ -285,12 +285,12 @@ public class ArthasBootstrap {
}
// init random port
if (configure.getTelnetPort() == 0) {
if (configure.getTelnetPort() != null && configure.getTelnetPort() == 0) {
int newTelnetPort = SocketUtils.findAvailableTcpPort();
configure.setTelnetPort(newTelnetPort);
logger().info("generate random telnet port: " + newTelnetPort);
}
if (configure.getHttpPort() == 0) {
if (configure.getHttpPort() != null && configure.getHttpPort() == 0) {
int newHttpPort = SocketUtils.findAvailableTcpPort();
configure.setHttpPort(newHttpPort);
logger().info("generate random http port: " + newHttpPort);
@@ -322,8 +322,10 @@ public class ArthasBootstrap {
try {
ShellServerOptions options = new ShellServerOptions()
.setInstrumentation(instrumentation)
.setPid(PidUtils.currentLongPid())
.setSessionTimeout(configure.getSessionTimeout() * 1000);
.setPid(PidUtils.currentLongPid());
if (configure.getSessionTimeout() != null) {
options.setSessionTimeout(configure.getSessionTimeout() * 1000);
}
if (agentId != null) {
Map<String, String> welcomeInfos = new HashMap<String, String>();
@@ -1,5 +1,6 @@
package com.taobao.arthas.core.shell.term;
import com.taobao.arthas.common.ArthasConstants;
import com.taobao.arthas.core.config.Configure;
import com.taobao.arthas.core.shell.ShellServerOptions;
import com.taobao.arthas.core.shell.future.Future;
@@ -20,7 +21,8 @@ public abstract class TermServer {
* @return the term server
*/
public static TermServer createTelnetTermServer(Configure configure, ShellServerOptions options) {
return new TelnetTermServer(configure.getIp(), configure.getTelnetPort(), options.getConnectionTimeout());
int port = configure.getTelnetPort() != null ? configure.getTelnetPort() : ArthasConstants.TELNET_PORT;
return new TelnetTermServer(configure.getIp(), port, options.getConnectionTimeout());
}
/**