Download Arthas code

wget https://arthas.aliyun.com/arthas-boot.jar;

Run Arthas code: java -jar arthas-boot.jar

It comes with autocompletation with TAB When you run Arthas code, it will list all java process, simply select the one.

To select the first process, type 1 ,then enter.

To quit, you can quit or exit

More details
  • JVM details can be listed with jvm command including Memory/OS/Thread/FileDescriptor
  • to see system properties you can use sysprop,
  • or use sysenv to see environment variables.
  • you can even set new value: sysprop testKey testValue

To see thread lists in real-time, you can run the following command:

dashboard 

From dashboard, you can see threadID, and to see stacktrace of given thread you can do:

thread 1 | grep 'main('

sc/sm view loaded classes

Sometimes you may need to see which class is loaded, you can use:

sc -d *MathGame

if you are looking for specific methods of the class:

sm -d java.math.RoundingMode
sm java.math.RoundingMode <init> #or constructor

If you need to look for spessific object that is on JVM, you may use vmtool command.

vmtool --action getInstances --className java.lang.String --limit 10

Decompile class

You can even decompile the class to see the code,

jad demo.MathGame

#or source code only
jad --source-only demo.MathGame

watch command can view the parameter/return code/exception of method

watch demo.MathGame primeFactors returnObj

watch com.example.demo.arthas.user.UserController * '{params, throwExp}'
#More options for watch
    # loader
    # clazz
    # method
    # target
    # params
    # returnObj
    # throwExp
    # isBefore
    # isThrow
    # isReturn

If you need to monitor method that just throw exception you could use -e Or look for expensive calls:

watch com.example.demo.arthas.user.UserController * '{params, returnObj}' '#cost>200'
You execute code dynamically:
ognl '@java.lang.System@out.println("hello ognl")

Use case: Change logger level,

Find the ClassLoader of the UserController

sc -d com.example.demo.arthas.user.UserController | grep classLoaderHash

Get the logger

ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@com.example.demo.arthas.user.UserController@logger'

Change the logger level of UserController

ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@com.example.demo.arthas.user.UserController@logger.setLevel(@ch.qos.logback.classic.Level@DEBUG)'

Change the global logger lever

ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@org.slf4j.LoggerFactory@getLogger("root").setLevel(@ch.qos.logback.classic.Level@DEBUG)'