Mastering Arthas: Practical Guide to Java Process Debugging and Monitoring
This article walks through installing Arthas, selecting Java processes, and using core commands such as session, exit, dashboard, thread, jvm, trace, and monitor to diagnose, profile, and troubleshoot Java applications in production environments, complete with command examples and output snippets.
Installation
Run the one‑line installer to get Arthas ready:
curl -L https://arthas.aliyun.com/install.sh | shAfter installation, the as.sh script provides the main interface.
Selecting a Java Process
Execute ./as.sh to list running Java processes and choose one by its serial number, or directly specify the PID:
./as.sh # interactive selection
./as.sh 19408 # attach to process 19408The console will display the selected process information and attach to the target JVM.
Session Command
Shows current session details, such as the Java PID and session ID:
[arthas@19408]$ session
Name Value
--------------------------
JAVA_PID 19408
SESSION_ID 37832025-711c-45f8-880e-114aa51c5dccExit / Quit Commands
Terminate the current Arthas client without stopping the server:
[arthas@19408]$ quit
Connection closed by foreign host.Re‑attach later; the server remains running.
Dashboard Command
Displays a real‑time panel of thread and memory metrics. Example excerpt:
[arthas@19408]$ dashboard
ID NAME STATE %CPU TIME
77 SimplePauseDetectorThread_0 TIMED_WAIT 0.0 80:04.758
...Key sections include thread list, memory usage, GC statistics, and runtime information.
Thread Command
Lists all threads with detailed attributes (ID, name, group, priority, state, CPU%, etc.) and supports filters such as most busy threads or blocking threads:
[arthas@19408]$ thread -n 3
"arthas-command-execute" Id=164 cpuUsage=0.85% ...JVM Command
Provides JVM configuration and runtime details, including version, class‑loading stats, compilation time, garbage‑collector counts, memory managers, and thread counts.
[arthas@19408]$ jvm
RUNTIME
--------------------------------
MACHINE-NAME 19408@host-192-168-65-23
JVM-START-TIME 2022-01-24 11:32:18
...Trace Command (use with caution in production)
Shows the call chain of a specific method and the time spent at each node:
[arthas@19625]$ trace com.pilot.basic.system.controller.SysUserManageController saveUser
---[134.78ms] com.pilot...SysUserManageController$$Enhancer...saveUser()
+---[108.34ms] com.pilot...BaseParam:getCurrSystemPkId()
...
`---throw: BusinessException [不允许添加超级管理员。]Monitor Command (use with caution in production)
Monitors method execution statistics such as total calls, successes, failures, average response time, and failure rate:
[arthas@19625]$ monitor com.pilot.basic.system.controller.SysUserManageController saveUser -c 2
timestamp class method total success fail avg-rt(ms) fail-rate
2022-02-26 23:35:06 com.pilot...SysUserManageController saveUser 1 0 1 47.04 100.00%Key Tips
Check DEADLOCK-COUNT (zero indicates no deadlocks).
Focus on success count, average response time, and failure rate when using trace or monitor.
For the next article, the author promises to continue using Arthas for online issue tracing and tracking.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect's Alchemy Furnace
A comprehensive platform that combines Java development and architecture design, guaranteeing 100% original content. We explore the essence and philosophy of architecture and provide professional technical articles for aspiring architects.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
