mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
support disabledCommands part 1. #1729
This commit is contained in:
+11
@@ -34,6 +34,10 @@ public class ArthasProperties {
|
||||
* when arthas agent init error will throw exception by default.
|
||||
*/
|
||||
private boolean slientInit = false;
|
||||
/**
|
||||
* disabled commands,default disable stop command
|
||||
*/
|
||||
private String disabledCommands = "stop";
|
||||
|
||||
public String getHome() {
|
||||
return home;
|
||||
@@ -115,4 +119,11 @@ public class ArthasProperties {
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
public String getDisabledCommands() {
|
||||
return disabledCommands;
|
||||
}
|
||||
|
||||
public void setDisabledCommands(String disabledCommands) {
|
||||
this.disabledCommands = disabledCommands;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.taobao.arthas.boot;
|
||||
|
||||
import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_ERROR;
|
||||
import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -11,12 +14,12 @@ import java.security.CodeSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.InputMismatchException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
@@ -36,9 +39,6 @@ import com.taobao.middleware.cli.annotations.Name;
|
||||
import com.taobao.middleware.cli.annotations.Option;
|
||||
import com.taobao.middleware.cli.annotations.Summary;
|
||||
|
||||
import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_ERROR;
|
||||
import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT;
|
||||
|
||||
/**
|
||||
* @author hengyunabc 2018-10-26
|
||||
*
|
||||
@@ -57,6 +57,7 @@ import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT;
|
||||
+ " java -jar arthas-boot.jar --versions\n"
|
||||
+ " java -jar arthas-boot.jar --select math-game\n"
|
||||
+ " java -jar arthas-boot.jar --session-timeout 3600\n" + " java -jar arthas-boot.jar --attach-only\n"
|
||||
+ " java -jar arthas-boot.jar --disabled-commands stop,dump\n"
|
||||
+ " java -jar arthas-boot.jar --repo-mirror aliyun --use-http\n" + "WIKI:\n"
|
||||
+ " https://arthas.aliyun.com/doc\n")
|
||||
public class Bootstrap {
|
||||
@@ -128,6 +129,8 @@ public class Bootstrap {
|
||||
|
||||
private String select;
|
||||
|
||||
private String disabledCommands;
|
||||
|
||||
static {
|
||||
ARTHAS_LIB_DIR = new File(
|
||||
System.getProperty("user.home") + File.separator + ".arthas" + File.separator + "lib");
|
||||
@@ -293,6 +296,12 @@ public class Bootstrap {
|
||||
this.select = select;
|
||||
}
|
||||
|
||||
@Option(longName = "disabled-commands")
|
||||
@Description("disable some commands ")
|
||||
public void setDisabledCommands(String disabledCommands) {
|
||||
this.disabledCommands = disabledCommands;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException,
|
||||
ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException,
|
||||
IllegalArgumentException, InvocationTargetException {
|
||||
@@ -547,6 +556,11 @@ public class Bootstrap {
|
||||
attachArgs.add(bootstrap.getStatUrl());
|
||||
}
|
||||
|
||||
if (bootstrap.getDisabledCommands() != null){
|
||||
attachArgs.add("-disabled-commands");
|
||||
attachArgs.add(bootstrap.getDisabledCommands());
|
||||
}
|
||||
|
||||
AnsiLog.info("Try to attach process " + pid);
|
||||
AnsiLog.debug("Start arthas-core.jar args: " + attachArgs);
|
||||
ProcessUtils.startArthasCore(pid, attachArgs);
|
||||
@@ -849,4 +863,8 @@ public class Bootstrap {
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getDisabledCommands() {
|
||||
return disabledCommands;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,6 @@ arthas.sessionTimeout=1800
|
||||
#arthas.tunnelServer=ws://127.0.0.1:7777/ws
|
||||
#arthas.agentId=mmmmmmyiddddd
|
||||
|
||||
#arthas.disabledCommands=stop,dump
|
||||
|
||||
#arthas.outputPath=arthas-output
|
||||
@@ -46,11 +46,12 @@ public class Arthas {
|
||||
Option appName = new TypedOption<String>().setType(String.class).setShortName(ArthasConstants.APP_NAME);
|
||||
|
||||
Option statUrl = new TypedOption<String>().setType(String.class).setShortName("stat-url");
|
||||
Option disabledCommands = new TypedOption<String>().setType(String.class).setShortName("disabled-commands");
|
||||
|
||||
CLI cli = CLIs.create("arthas").addOption(pid).addOption(core).addOption(agent).addOption(target)
|
||||
.addOption(telnetPort).addOption(httpPort).addOption(sessionTimeout)
|
||||
.addOption(username).addOption(password)
|
||||
.addOption(tunnelServer).addOption(agentId).addOption(appName).addOption(statUrl);
|
||||
.addOption(tunnelServer).addOption(agentId).addOption(appName).addOption(statUrl).addOption(disabledCommands);
|
||||
CommandLine commandLine = cli.parse(Arrays.asList(args));
|
||||
|
||||
Configure configure = new Configure();
|
||||
@@ -78,6 +79,7 @@ public class Arthas {
|
||||
configure.setTunnelServer((String) commandLine.getOptionValue("tunnel-server"));
|
||||
configure.setAgentId((String) commandLine.getOptionValue("agent-id"));
|
||||
configure.setStatUrl((String) commandLine.getOptionValue("stat-url"));
|
||||
configure.setDisabledCommands((String) commandLine.getOptionValue("disabled-commands"));
|
||||
configure.setAppName((String) commandLine.getOptionValue(ArthasConstants.APP_NAME));
|
||||
return configure;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,11 @@ public class Configure {
|
||||
*/
|
||||
private Long sessionTimeout;
|
||||
|
||||
/**
|
||||
* disabled commands
|
||||
*/
|
||||
private String disabledCommands;
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
@@ -180,6 +185,14 @@ public class Configure {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getDisabledCommands() {
|
||||
return disabledCommands;
|
||||
}
|
||||
|
||||
public void setDisabledCommands(String disabledCommands) {
|
||||
this.disabledCommands = disabledCommands;
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化成字符串
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user