LinuxCommandLibrary

arthas

Diagnose and troubleshoot Java applications in real-time

TLDR

Start Arthas

$ java -jar [path/to/arthas-boot.jar]
copy

Reconnect Arthas (default port used by Arthas is 3658)
$ telnet localhost [port_number]
copy

Exit the current Arthas client without affecting other clients. equals exit、logout、q command
$ [exit|quit|logout|q]
copy

Terminate the Arthas server, all the Arthas clients connecting to this server will be disconnected
$ stop
copy

SYNOPSIS

Arthas is typically invoked using the as.sh wrapper script or by attaching its agent directly to a JVM. The general invocation for the script is:

as.sh [options] [PID | APP_NAME]

Once attached, an interactive console is provided where various Arthas commands can be executed, for example:
dashboard
thread -n 3
trace com.example.MyClass myMethod

PARAMETERS

PID
    The Process ID of the target Java application to attach to.

APP_NAME
    The name of the application, used to find the target Java process.

-h, --help
    Display help information for the as.sh script.

-c
    Execute a specific Arthas command directly and then exit, without entering the interactive console.

--attach-only
    Attach to the target process only, without attempting to connect to the Arthas console.

DESCRIPTION

Arthas is a versatile and powerful diagnostic tool designed for troubleshooting, monitoring, and diagnosing Java applications running in production environments. Developed by Alibaba, it provides a comprehensive set of capabilities to interact with a running Java Virtual Machine (JVM) without requiring application restarts or code modifications.

It allows developers and operators to perform various diagnostic tasks such as viewing real-time JVM metrics (CPU, memory, garbage collection), inspecting thread stacks for deadlock detection or performance bottlenecks, tracing method calls with execution times, watching variable changes, decompiling classes on the fly, and even hot-swapping classes for immediate bug fixes or experimental changes. Arthas attaches to a running Java process, offering a command-line interface for interaction, making it invaluable for in-depth analysis and problem resolution of complex Java applications.

CAVEATS

While powerful, Arthas operates directly within the target JVM's memory space. Improper use, such as aggressively tracing methods with high frequency or redefining critical classes without thorough understanding, can potentially impact application performance or stability. It's crucial to use it responsibly in production environments. Security is another consideration; ensure that access to Arthas is restricted to authorized personnel, as it provides deep insights and control over the running application.

KEY INTERNAL COMMANDS

Once Arthas is attached, it provides a rich set of internal commands to interact with the JVM:
dashboard: Overview of JVM metrics (CPU, memory, threads).
thread: View thread information, detect deadlocks.
trace: Trace method execution paths and time consumption.
watch: Watch variable changes at method entry, exit, or exceptions.
jad: Decompile loaded classes.
redefine: Hot-swap loaded classes dynamically.
ognl: Execute OGNL expressions to inspect objects.
sysprop: View and modify system properties.

HISTORY

Arthas was developed internally by Alibaba in China to address complex troubleshooting challenges faced with their massive-scale Java applications in production. Recognizing its immense value, Alibaba open-sourced Arthas in 2018, making it available to the wider Java development community. Since then, it has gained significant popularity and is widely adopted for its robust diagnostic capabilities, becoming a go-to tool for developers and operations engineers alike when dealing with Java application issues.

SEE ALSO

jps(1), jstack(1), jmap(1), jstat(1), VisualVM, BTrace, async-profiler

Copied to clipboard