Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas
Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas
Arthas is a Java Diagnostic tool open sourced by Alibaba.
Arthas allows developers to troubleshoot production issues for Java applications without modifying code or restarting servers.
Often times, the production system network is inaccessible from the local development environment. If issues are encountered in production systems, it is impossible to use IDEs to debug the application remotely. More importantly, debugging in production environment is unacceptable, as it will suspend all the threads, resulting in the suspension of business services.
Developers could always try to reproduce the same issue on the test/staging environment. However, this is tricky as some issues cannot be reproduced easily on a different environment, or even disappear once restarted.
And if you're thinking of adding some logs to your code to help troubleshoot the issue, you will have to go through the following lifecycle; test, staging, and then to production. Time is money! This approach is inefficient! Besides, the issue may not be reproducible once the JVM is restarted, as described above.
Arthas was built to solve these issues. A developer can troubleshoot your production issues on-the-fly. No JVM restart, no additional code changes. Arthas works as an observer, which will never suspend your existing threads.
arthas-boot(Recommended)Downloadarthas-boot.jar,Start with java command:
curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jarPrint usage:
java -jar arthas-boot.jar -has.shYou can install Arthas with one single line command on Linux, Unix, and Mac. Copy the following command and paste it into the command line, then press Enter to run:
curl -L https://arthas.aliyun.com/install.sh | shThe command above will download the bootstrap script as.sh to the current directory. You can move it any other place you want, or put its location in $PATH.
You can enter its interactive interface by executing as.sh, or execute as.sh -h for more help information.
See what is eating your CPU (ranked by top CPU usage) and what is going on there in one glance:
…Decompile your class with one shot:
…Memory compiler, compiles .java files into .class files in memory.
$ mc /tmp/Test.javaLoad the external *.class files to retransform/hotswap the loaded classes in JVM.
retransform /tmp/Test.class
retransform -c 327a647b /tmp/Test.class /tmp/Test\$Inner.classSearch any loaded class with detailed information.
…Get objects in the heap that are instances of the specified class.
…View the call stack of test.arthas.TestStack#doGet:
…See what is slowing down your method invocation with trace command:
Watch the first parameter and thrown exception of test.arthas.TestWatch#doGet only if it throws exception.
$ watch test.arthas.TestWatch doGet {params[0], throwExp} -e
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 65 ms.
ts=2018-09-18 10:26:28;result=@ArrayList[
@RequestFacade[org.apache.catalina.connector.RequestFacade@79f922b2],
@NullPointerException[java.lang.NullPointerException],
]Monitor a specific method invocation statistics, including the total number of invocations, average response time, success rate, and every 5 seconds:
…Record method invocation data, so that you can check the method invocation parameters, returned value, and thrown exceptions later. It works as if you could come back and replay the past method invocation via time tunnel.
……$ profiler start
Started [cpu] profiling$ profiler stop
profiler output file: /tmp/demo/arthas-output/20211207-111550.html
OKView profiler results under arthas-output via browser:
Arthas has more than 120 registered users, View All.
Welcome to register the company name in this issue: https://github.com/alibaba/arthas/issues/111 (in order of registration)
This project exists, thanks to all the people who contributed.
邀请 arthas 加入 GithubStarMate,让更多人发现你的作品
thread 显示的线程ID 只能显示2位数字,长线程ID会被截断,导致不同线程出现相同ID,无法准确查看到堆栈细节
线程相关信息超出tty 宽度时,信息会被隐藏,而不是换行
Upgrade the bundled async-profiler to v4.5 to fix long JVM pauses when loading/attaching the profiler (async-profiler issue 1406)
fix: replace printStackTrace with proper logging
Potential Vulnerabilities Due To Hidden Dependencies
使用Arthas 获取 Spring 应用运行时配置值
k8s 临时 debug 容器无法 attach 应用容器中的 Java 进程(跨 mount namespace)
springboot整合arthas-tunnel-server
多层agent使用arthas-spring-boot-starter反编译问题