Ali online analysis and diagnosis tools Arthas and jvm-sandbox use demo

1 Ali online analysis and diagnosis tool Arthas (Alsace)

Official documents: https://arthas.aliyun.com/doc/  All are subject to official documents

Reference:  https://alibaba.github.io/arthas/

Reference:  https://github.com/alibaba/arthas/blob/master/README_CN.md

2 Ali online analysis and diagnosis tool Jvm-Sandbox (JVM sandbox)

Reference:  https://github.com/alibaba/jvm-sandbox

3 Comparison of Arthas and Jvm-Sandbox

Arthas is like a sword mound, if you want to get a sword, just go in and get it! It provides a variety of commands to meet your various business needs, and the cost of getting started is relatively high.

Jvm-Sandbox is like a sword furnace. It provides the concept of Module. Each Module is an instance of AOP, that is, a sword. How to forge depends on the craftsman, that is, you! It provides a model, and the specific implementation needs to be written by yourself, which is more flexible. The cost of getting started is relatively low

  • The following will experience the two open source projects through the daily needs of adding logs.

4 Add log case

Project address:  https://github.com/70416450/Online-debugging-demo

  • For the springboot-demo project
  1. Use mvn clean install command to compile
  2. Upload the springboot-demo-1.0-SNAPSHOT.jar package to the server
  3. Use java -jar springboot-demo-1.0-SNAPSHOT.jar to start the project and see the following effects

4.1 Jvm-Sandbox experience

4.1.1 Download and unzip

# 下载最新版本的JVM-SANDBOX
wget http://ompc.oss-cn-hangzhou.aliyuncs.com/jvm-sandbox/release/sandbox-stable-bin.zip

# 解压
unzip sandbox-stable-bin.zip

4.1.2 Mount the target application

# 进入沙箱执行脚本
cd sandbox/bin

# 常用命令!!!
# 目标JVM进程93726(使用jps命令查看)
./sandbox.sh -p 93726
#卸载沙箱
./sandbox.sh -p 93726 -S
#查询沙箱
./sandbox.sh -p 93726 -l
#刷新沙箱
./sandbox.sh -p 93726 -F
#使用自定义module执行(my-sandbox-module:自定义的module名字,addLog自定义切入方法名字)
./sandbox.sh -p 93726 -d 'my-sandbox-module/addLog'

#日志配置及查看
#配置文件在    /sandbox/cfg/sandbox-logback.xml
#默认日志路径    ~/logs/sandbox/sandbox.log

  • For the springboot-demo project
  1. Use mvn clean compile assembly:single to package and upload to the sandbox/sandbox-module directory
  2. Go back to the bin directory,
    • ./sandbox.sh -p 93726 -S stop sandbox
    • ./sandbox.sh -p 93726 -F refresh sandbox
    • ./sandbox.sh -p 93726 -l View sandbox
    • ./sandbox.sh -p 93726 -d'my-sandbox-module/addLog' execute using custom module (my-sandbox-module: custom module name, addLog custom cut-in method name)
  3. Switch to springboot-demo project log view

4.2 Arthas experience

  • Download the idea plugin Alibaba Cloud Toolkit  https://plugins.jetbrains.com/plugin/11386-alibaba-cloud-toolkit/

  • Add server address and open Arthas monitoring

  • Enter the number to select the corresponding process

  • Successfully started

  • Use the sc command to find the ClassLoader of the class that needs to be modified

  •  sc -d *TestAdd | grep classLoaderHash
    
  • Modify TestAdd

  • Upload the recompiled class file to the specified directory of the server

  • Then use the redefine command to reload the newly compiled TestAdd.class (note the hash code and the class path that needs to be replaced)

  • redefine -c 439f5b3d /usr/local/src/jvm-sandbox/test/TestAdd.class
    
  • important point:

    • Restart the project can be restored
    • New addition of field/method is not allowed

Guess you like

Origin blog.csdn.net/zhaofuqiangmycomm/article/details/114921591