Introduction to Arthas
Arthas is an open-source Java diagnostic tool developed by Alibaba. It provides developers a powerful method to troubleshoot issues in Java applications without the need to change code or restart servers. This tool is invaluable in situations where direct debugging is not feasible.
Background
In many cases, production systems are not accessible from the local development environment. Debugging these systems directly can cause operations to halt, affecting business continuity. Replicating issues in a test environment can also be problematic, as some problems vanish upon restart. Traditional methods that involve adding logs followed by a full deployment cycle are inefficient and time-consuming. Arthas comes to the rescue by allowing on-the-fly diagnostics without disrupting the running application.
Key Features
- Class Loading and Decompilation: Identify if and how a class is loaded, pinpoint issues like jar file conflicts, and decompile classes to verify the live code functionality.
- Classloader Insights: Access classloader statistics, learn about classloader hierarchies, and detect potential classloader leaks.
- Method Invocation Details: Examine method parameters, return objects, and exceptions thrown during method execution.
- Stack and Performance Tracing: Analyze method call stack traces and detect performance bottlenecks in real-time.
- System Monitoring: Keep an eye on system metrics, thread states, CPU usage, and garbage collection statistics.
- User Interface: Arthas supports command line interaction with auto-complete, telnet, and websocket interfaces for both local and remote diagnostics.
- Wide Compatibility: It works across multiple platforms (Linux, Mac, Windows) and supports Java versions starting from JDK 6, though version 4.x drops support for JDK 6 and 7.
Quick Start Guide
For a seamless experience, Arthas can be started using arthas-boot.jar
. Simply download the jar file and run:
curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar
Alternatively, on Unix-like systems, use a single line command to install Arthas:
curl -L https://arthas.aliyun.com/install.sh | sh
Documentation and Online Tutorials
Arthas offers extensive documentation, including user manuals, installation guides, and advanced usage examples. These resources are available online. For beginners, Arthas’ online tutorials are a great way to get started.
Feature Showcase
- Dashboard: A visual monitor to track system operations and metrics in real-time.
- Thread Monitoring: Identify and assess CPU usage by threads to detect what's consuming the most resources.
- jad (Java Decompiler): Quickly decompile Java classes to review code.
- Memory Compiler (mc): Compile Java files in-memory to class files without disrupting the system.
- Retransform: Replace loaded classes in the JVM without stopping the application.
- Monitor and Watch: Tools for monitoring method invocation statistics and parameters, and watching specific method executions under given conditions.
Web Console and Profiler
Arthas includes a web console for an easier and more interactive user experience. The Profiler tool allows analysis of CPU usage through Flame Graphs, helping to visualize which parts of the systems are consuming resources.
Community and Contributions
Arthas has a thriving community with over 120 registered users including big names like Alibaba, Alipay, and many others. Contributions are welcomed, and the project is in continuous development thanks to its many contributors.
Derivative Projects and Credits
Arthas has inspired derivative projects such as Bistoury. It benefits from other open-source projects including Greys-Anatomy and Termd, forming a vibrant ecosystem for Java diagnostics.
Arthas represents an indispensable toolkit for Java developers experiencing the challenge of debugging production environments efficiently and safely.