This is the 9th day of my participation in Gwen Challenge

Based on Arthas version 3.5.2, this article introduces the default arthas-Boot startup process.

Start arthas

The documentation on the official website recommends using arthas with arthas-boot.jar. The command is as follows:

curl -O https://arthas.aliyun.com/arthas-boot.jar

java -jar arthas-boot.jar
Copy the code

How do I debug arthas-boot

You can learn how to Debug arthas-boot.jar by using the arthas repository issue Debug arthas In IDEA on Github.

3. Start debugging

Select Remote Debug here.

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000 -jar arthas-boot.jar

Add a remote configuration to idea and set the same port as arthas-boot.jar, as shown in the following figure.

1. Output the arthas-boot version

throughBootstrap.class.getPackageYou can get the current arthas-Boot version, which you can see is 3.5.2

2. Resolve execution parameters

Next, the executed parameters are injected into the created bootstrap instance. whilecom.taobao.middleware.cliThis tool is used to facilitate command-line tool development, based onvert.x, and we will study it later when we are free. Here we just need to know the general effect.

3. Select a warehouse image

First of all, the default selection of the central warehouse (Center), if it is east 8 district, that is, in the domestic environment, the default selection of the warehouse mirror aliyun, because the download speed is much faster than the foreign central warehouse, and is not prone to error interruption.

4. Select the application to listen to

Select(bootstrap.isverbose (), telnetPortPid, bootstrap.getSelect())).

ListProcessByJps (v) is executed to get the Java program that is now running by executing the command JPS -l. ExecutingCommand. RunNative (command) is actually encapsulates the Runtime. The getRuntime (). The exec to perform this command and return a result, the return will filter out arthas and JPS – the boot process.

Select the Java program to listen on, in this case select 4, return process PID 696.

5. Find Arthas Home

The location of arthas-boot.jar is considered the location of arthas Home. Arthas-core. jar, arthas-agent.jar, arthas-spy.jar, arthas-spy.jar, arthas-spy.jar, arthas-spy.jar, arthas-spy.jar, arthas-spy.jar, arthas-spy.jar, arthas-spy.jar, arthas-spy.jar If you still don’t find arthas, download arthas remotely.

6. Remote download arthas

First, judge~/.arthas/libIf the directory does not exist, create it. Get and sort a list of arthas folder names under that directory. The default isarthasVersion number, so you can get the latest version of arthas in your current local directory.

DownloadUtils.readLatestReleaseVersionGet the latest remote version by accessinghttps://arthas.aliyun.com/api/latest_versionYou can get the latest remote version.

If you fail to obtain the remote version you will need to manually download the full arthas package. The remote version number is compared to the local arthas version, or you need to re-download the latest version if it is not the latest version locally. DownloadUtils. DownArthasPackaging download and unpack arthas – packaging – 3.5.1 track of – bin. Zip bags.

ProcessUtils. Arthas startArthasCore start – core. The jar, the actual command to execute

${JAVA_HOME}"/bin/java \
       ${opts} \
       -jar "${arthas_lib_dir}/arthas-core.jar" \
       -pid ${TARGET_PID} \
       -target-ip ${TARGET_IP} \
       -telnet-port ${TELNET_PORT} \
       -http-port ${HTTP_PORT} \
       -core "${arthas_lib_dir}/arthas-core.jar" \
       -agent "${arthas_lib_dir}/arthas-agent.jar"
Copy the code

throughURLClassLoader, the loadarthas-client.jarAnd performTelnetConsoleIn themainMethods. To start the Telnet service, the default port is 3658.

This concludes the main arthas-Boot startup process. We’ll look at the Agent mechanism later.