arthas-boot remove logback dependency

This commit is contained in:
hengyunabc 2018-11-10 13:11:51 +08:00
parent 8d32e691c9
commit 617f990cfe
4 changed files with 17 additions and 38 deletions

View File

@ -22,14 +22,6 @@
<artifactId>cli</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -14,10 +14,9 @@ import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import com.taobao.arthas.common.AnsiLog;
import com.taobao.arthas.common.SocketUtils;
import com.taobao.middleware.cli.CLI;
import com.taobao.middleware.cli.CommandLine;
@ -39,7 +38,6 @@ import com.taobao.middleware.cli.annotations.Summary;
+ " java -jar arthas-boot.jar --target-ip 0.0.0.0 --telnet-port 9999' \n"
+ " java -jar arthas-boot.jar -f batch.as 127.0.0.1\n")
public class Bootstrap {
private static final Logger logger = LoggerFactory.getLogger(Bootstrap.class);
private static final int DEFAULT_TELNET_PORT = 3658;
private static final int DEFAULT_HTTP_PORT = 8563;
private static final String DEFAULT_TARGET_IP = "127.0.0.1";
@ -187,13 +185,13 @@ public class Bootstrap {
if (bootStrap.getTelnetPort() > 0) {
telnetPortPid = SocketUtils.findTcpListenProcess(bootStrap.getTelnetPort());
if (telnetPortPid > 0) {
logger.info("Process {} already using port {}", telnetPortPid, bootStrap.getTelnetPort());
AnsiLog.info("Process {} already using port {}", telnetPortPid, bootStrap.getTelnetPort());
}
}
if (bootStrap.getHttpPort() > 0) {
httpPortPid = SocketUtils.findTcpListenProcess(bootStrap.getHttpPort());
if (httpPortPid > 0) {
logger.info("Process {} already using port {}", httpPortPid, bootStrap.getHttpPort());
AnsiLog.info("Process {} already using port {}", httpPortPid, bootStrap.getHttpPort());
}
}
@ -208,12 +206,12 @@ public class Bootstrap {
}
if (telnetPortPid > 0 && pid != telnetPortPid) {
logger.warn("Target process {} is not the process using port {}, you will connect to an unexpected process.",
AnsiLog.warn("Target process {} is not the process using port {}, you will connect to an unexpected process.",
pid, bootStrap.getTelnetPort());
}
if (httpPortPid > 0 && pid != httpPortPid) {
logger.warn("Target process {} is not the process using port {}, you will connect to an unexpected process.",
AnsiLog.warn("Target process {} is not the process using port {}, you will connect to an unexpected process.",
pid, bootStrap.getHttpPort());
}
@ -269,7 +267,7 @@ public class Bootstrap {
verifyArthasHome(arthasHomeDir.getAbsolutePath());
logger.info("arthas home: " + arthasHomeDir);
AnsiLog.info("arthas home: " + arthasHomeDir);
// start arthas-core.jar
List<String> attachArgs = new ArrayList<String>();
@ -288,11 +286,11 @@ public class Bootstrap {
attachArgs.add("-agent");
attachArgs.add(new File(arthasHomeDir, "arthas-agent.jar").getAbsolutePath());
logger.info("Try to attach process " + pid);
logger.debug("Start arthas-core.jar args: " + attachArgs);
AnsiLog.info("Try to attach process " + pid);
AnsiLog.debug("Start arthas-core.jar args: " + attachArgs);
ProcessUtils.startArthasCore(pid, attachArgs);
logger.info("Attach process {} success.", pid);
AnsiLog.info("Attach process {} success.", pid);
if (bootStrap.isAttachOnly()) {
System.exit(0);
@ -319,7 +317,7 @@ public class Bootstrap {
telnetArgs.add(bootStrap.getTargetIp());
telnetArgs.add("" + bootStrap.getTelnetPort());
logger.debug("Start arthas-client.jar args: " + telnetArgs);
AnsiLog.debug("Start arthas-client.jar args: " + telnetArgs);
mainMethod.invoke(null, new Object[] { telnetArgs.toArray(new String[0]) });
}

View File

@ -12,12 +12,11 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.taobao.arthas.common.AnsiLog;
import com.taobao.arthas.common.IOUtils;
/**
@ -26,9 +25,6 @@ import com.taobao.arthas.common.IOUtils;
*
*/
public class DownloadUtils {
private static final Logger logger = LoggerFactory.getLogger(DownloadUtils.class);
private static final String MAVEN_METADATA_URL = "${REPO}/com/taobao/arthas/arthas-packaging/maven-metadata.xml";
private static final String REMOTE_DOWNLOAD_URL = "${REPO}/com/taobao/arthas/arthas-packaging/${VERSION}/arthas-packaging-${VERSION}-bin.zip";
@ -83,7 +79,7 @@ public class DownloadUtils {
File tempFile = File.createTempFile("arthas", "arthas");
String remoteDownloadUrl = REMOTE_DOWNLOAD_URL.replace("${REPO}", repoUrl).replace("${VERSION}", arthasVersion);
logger.info("Start download arthas from remote server: " + remoteDownloadUrl);
AnsiLog.info("Start download arthas from remote server: " + remoteDownloadUrl);
saveUrl(tempFile.getAbsolutePath(), remoteDownloadUrl);
IOUtils.unzip(tempFile.getAbsolutePath(), unzipDir.getAbsolutePath());

View File

@ -1,10 +1,8 @@
package com.taobao.arthas.boot;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Iterator;
@ -13,9 +11,7 @@ import java.util.List;
import java.util.Map;
import java.util.Scanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.taobao.arthas.common.AnsiLog;
import com.taobao.arthas.common.ExecutingCommand;
import com.taobao.arthas.common.IOUtils;
@ -25,8 +21,6 @@ import com.taobao.arthas.common.IOUtils;
*
*/
public class ProcessUtils {
private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class);
private static String PID = "-1";
static {
@ -51,7 +45,7 @@ public class ProcessUtils {
Map<Integer, String> processMap = listProcessByJps(v);
if (processMap.isEmpty()) {
logger.info("Can not find java process.");
AnsiLog.info("Can not find java process. Try to pass pid in command line.");
return -1;
}
@ -118,7 +112,6 @@ public class ProcessUtils {
}
return result;
}
public static void startArthasCore(int targetPid, List<String> attachArgs) {
@ -199,7 +192,7 @@ public class ProcessUtils {
int exitValue = proc.exitValue();
if (exitValue != 0) {
logger.error("attach fail, targetPid: " + targetPid);
AnsiLog.error("attach fail, targetPid: " + targetPid);
System.exit(1);
}
} catch (Throwable e) {
@ -219,7 +212,7 @@ public class ProcessUtils {
}
}
logger.debug("can not find java under current java home: " + javaHome);
AnsiLog.debug("can not find java under current java home: " + javaHome);
return null;
}
@ -234,7 +227,7 @@ public class ProcessUtils {
}
}
logger.debug("can not find jps under current java home: " + javaHome);
AnsiLog.debug("can not find jps under current java home: " + javaHome);
return null;
}