项目作者: alibaba

项目描述 :
阿里巴巴Java诊断工具阿尔萨斯/阿里巴巴Java诊断利器阿尔萨斯
高级语言: Java
项目地址: git://github.com/alibaba/arthas.git
创建时间: 2018-08-29T17:15:57Z
项目社区:https://github.com/alibaba/arthas

开源协议:GNU General Public License v3.0

下载


Arthas

arthas

Build Status
download
maven
license
Average time to resolve an issue
Percentage of issues still open
Leaderboard

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.

中文说明/Chinese Documentation

Background

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.

Key features

  • Check whether a class is loaded, or where the class is being loaded. (Useful for troubleshooting jar file conflicts)
  • Decompile a class to ensure the code is running as expected.
  • View classloader statistics, e.g. the number of classloaders, the number of classes loaded per classloader, the classloader hierarchy, possible classloader leaks, etc.
  • View the method invocation details, e.g. method parameter, return object, thrown exception, and etc.
  • Check the stack trace of specified method invocation. This is useful when a developers wants to know the caller of the said method.
  • Trace the method invocation to find slow sub-invocations.
  • Monitor method invocation statistics, e.g. qps, rt, success rate and etc.
  • Monitor system metrics, thread states and cpu usage, gc statistics, and etc.
  • Supports command line interactive mode, with auto-complete feature enabled.
  • Supports telnet and websocket, which enables both local and remote diagnostics with command line and browsers.
  • Supports profiler/Flame Graph
  • Support get objects in the heap that are instances of the specified class.
  • Supports JDK 6+ (version 4.x no longer supports JDK 6 and JDK 7).
  • Supports Linux/Mac/Windows.

Quick start

Downloadarthas-boot.jar,Start with java command:

  1. curl -O https://arthas.aliyun.com/arthas-boot.jar
  2. java -jar arthas-boot.jar

Print usage:

  1. java -jar arthas-boot.jar -h

Use as.sh

You 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:

  1. curl -L https://arthas.aliyun.com/install.sh | sh

The 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.

Documentation

Feature Showcase

Dashboard

dashboard

Thread

See what is eating your CPU (ranked by top CPU usage) and what is going on there in one glance:

  1. $ thread -n 3
  2. "as-command-execute-daemon" Id=29 cpuUsage=75% RUNNABLE
  3. at sun.management.ThreadImpl.dumpThreads0(Native Method)
  4. at sun.management.ThreadImpl.getThreadInfo(ThreadImpl.java:440)
  5. at com.taobao.arthas.core.command.monitor200.ThreadCommand$1.action(ThreadCommand.java:58)
  6. at com.taobao.arthas.core.command.handler.AbstractCommandHandler.execute(AbstractCommandHandler.java:238)
  7. at com.taobao.arthas.core.command.handler.DefaultCommandHandler.handleCommand(DefaultCommandHandler.java:67)
  8. at com.taobao.arthas.core.server.ArthasServer$4.run(ArthasServer.java:276)
  9. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  10. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  11. at java.lang.Thread.run(Thread.java:745)
  12. Number of locked synchronizers = 1
  13. - java.util.concurrent.ThreadPoolExecutor$Worker@6cd0b6f8
  14. "as-session-expire-daemon" Id=25 cpuUsage=24% TIMED_WAITING
  15. at java.lang.Thread.sleep(Native Method)
  16. at com.taobao.arthas.core.server.DefaultSessionManager$2.run(DefaultSessionManager.java:85)
  17. "Reference Handler" Id=2 cpuUsage=0% WAITING on java.lang.ref.Reference$Lock@69ba0f27
  18. at java.lang.Object.wait(Native Method)
  19. - waiting on java.lang.ref.Reference$Lock@69ba0f27
  20. at java.lang.Object.wait(Object.java:503)
  21. at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)

jad

Decompile your class with one shot:

  1. $ jad javax.servlet.Servlet
  2. ClassLoader:
  3. +-java.net.URLClassLoader@6108b2d7
  4. +-sun.misc.Launcher$AppClassLoader@18b4aac2
  5. +-sun.misc.Launcher$ExtClassLoader@1ddf84b8
  6. Location:
  7. /Users/xxx/work/test/lib/servlet-api.jar
  8. /*
  9. * Decompiled with CFR 0_122.
  10. */
  11. package javax.servlet;
  12. import java.io.IOException;
  13. import javax.servlet.ServletConfig;
  14. import javax.servlet.ServletException;
  15. import javax.servlet.ServletRequest;
  16. import javax.servlet.ServletResponse;
  17. public interface Servlet {
  18. public void init(ServletConfig var1) throws ServletException;
  19. public ServletConfig getServletConfig();
  20. public void service(ServletRequest var1, ServletResponse var2) throws ServletException, IOException;
  21. public String getServletInfo();
  22. public void destroy();
  23. }

mc

Memory compiler, compiles .java files into .class files in memory.

  1. $ mc /tmp/Test.java

retransform

Load the external *.class files to retransform/hotswap the loaded classes in JVM.

  1. retransform /tmp/Test.class
  2. retransform -c 327a647b /tmp/Test.class /tmp/Test\$Inner.class

sc

Search any loaded class with detailed information.

  1. $ sc -d org.springframework.web.context.support.XmlWebApplicationContext
  2. class-info org.springframework.web.context.support.XmlWebApplicationContext
  3. code-source /Users/xxx/work/test/WEB-INF/lib/spring-web-3.2.11.RELEASE.jar
  4. name org.springframework.web.context.support.XmlWebApplicationContext
  5. isInterface false
  6. isAnnotation false
  7. isEnum false
  8. isAnonymousClass false
  9. isArray false
  10. isLocalClass false
  11. isMemberClass false
  12. isPrimitive false
  13. isSynthetic false
  14. simple-name XmlWebApplicationContext
  15. modifier public
  16. annotation
  17. interfaces
  18. super-class +-org.springframework.web.context.support.AbstractRefreshableWebApplicationContext
  19. +-org.springframework.context.support.AbstractRefreshableConfigApplicationContext
  20. +-org.springframework.context.support.AbstractRefreshableApplicationContext
  21. +-org.springframework.context.support.AbstractApplicationContext
  22. +-org.springframework.core.io.DefaultResourceLoader
  23. +-java.lang.Object
  24. class-loader +-org.apache.catalina.loader.ParallelWebappClassLoader
  25. +-java.net.URLClassLoader@6108b2d7
  26. +-sun.misc.Launcher$AppClassLoader@18b4aac2
  27. +-sun.misc.Launcher$ExtClassLoader@1ddf84b8
  28. classLoaderHash 25131501

vmtool

Get objects in the heap that are instances of the specified class.

  1. $ vmtool --action getInstances --className java.lang.String --limit 10
  2. @String[][
  3. @String[com/taobao/arthas/core/shell/session/Session],
  4. @String[com.taobao.arthas.core.shell.session.Session],
  5. @String[com/taobao/arthas/core/shell/session/Session],
  6. @String[com/taobao/arthas/core/shell/session/Session],
  7. @String[com/taobao/arthas/core/shell/session/Session.class],
  8. @String[com/taobao/arthas/core/shell/session/Session.class],
  9. @String[com/taobao/arthas/core/shell/session/Session.class],
  10. @String[com/],
  11. @String[java/util/concurrent/ConcurrentHashMap$ValueIterator],
  12. @String[java/util/concurrent/locks/LockSupport],
  13. ]

stack

View the call stack of test.arthas.TestStack#doGet:

  1. $ stack test.arthas.TestStack doGet
  2. Press Ctrl+C to abort.
  3. Affect(class-cnt:1 , method-cnt:1) cost in 286 ms.
  4. ts=2018-09-18 10:11:45;thread_name=http-bio-8080-exec-10;id=d9;is_daemon=true;priority=5;TCCL=org.apache.catalina.loader.ParallelWebappClassLoader@25131501
  5. @test.arthas.TestStack.doGet()
  6. at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
  7. at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  8. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  9. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  10. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  11. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  12. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  13. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  14. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  15. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  16. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
  17. ...
  18. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
  19. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  20. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  21. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:451)
  22. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1121)
  23. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
  24. at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
  25. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  26. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  27. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  28. at java.lang.Thread.run(Thread.java:745)

Trace

See what is slowing down your method invocation with trace command:

trace

Watch

Watch the first parameter and thrown exception of test.arthas.TestWatch#doGet only if it throws exception.

  1. $ watch test.arthas.TestWatch doGet {params[0], throwExp} -e
  2. Press Ctrl+C to abort.
  3. Affect(class-cnt:1 , method-cnt:1) cost in 65 ms.
  4. ts=2018-09-18 10:26:28;result=@ArrayList[
  5. @RequestFacade[org.apache.catalina.connector.RequestFacade@79f922b2],
  6. @NullPointerException[java.lang.NullPointerException],
  7. ]

Monitor

Monitor a specific method invocation statistics, including the total number of invocations, average response time, success rate, and every 5 seconds:

  1. $ monitor -c 5 org.apache.dubbo.demo.provider.DemoServiceImpl sayHello
  2. Press Ctrl+C to abort.
  3. Affect(class-cnt:1 , method-cnt:1) cost in 109 ms.
  4. timestamp class method total success fail avg-rt(ms) fail-rate
  5. ----------------------------------------------------------------------------------------------------------------------------
  6. 2018-09-20 09:45:32 org.apache.dubbo.demo.provider.DemoServiceImpl sayHello 5 5 0 0.67 0.00%
  7. timestamp class method total success fail avg-rt(ms) fail-rate
  8. ----------------------------------------------------------------------------------------------------------------------------
  9. 2018-09-20 09:45:37 org.apache.dubbo.demo.provider.DemoServiceImpl sayHello 5 5 0 1.00 0.00%
  10. timestamp class method total success fail avg-rt(ms) fail-rate
  11. ----------------------------------------------------------------------------------------------------------------------------
  12. 2018-09-20 09:45:42 org.apache.dubbo.demo.provider.DemoServiceImpl sayHello 5 5 0 0.43 0.00%

Time Tunnel(tt)

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.

  1. $ tt -t org.apache.dubbo.demo.provider.DemoServiceImpl sayHello
  2. Press Ctrl+C to abort.
  3. Affect(class-cnt:1 , method-cnt:1) cost in 75 ms.
  4. INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD
  5. -------------------------------------------------------------------------------------------------------------------------------------
  6. 1000 2018-09-20 09:54:10 1.971195 true false 0x55965cca DemoServiceImpl sayHello
  7. 1001 2018-09-20 09:54:11 0.215685 true false 0x55965cca DemoServiceImpl sayHello
  8. 1002 2018-09-20 09:54:12 0.236303 true false 0x55965cca DemoServiceImpl sayHello
  9. 1003 2018-09-20 09:54:13 0.159598 true false 0x55965cca DemoServiceImpl sayHello
  10. 1004 2018-09-20 09:54:14 0.201982 true false 0x55965cca DemoServiceImpl sayHello
  11. 1005 2018-09-20 09:54:15 0.214205 true false 0x55965cca DemoServiceImpl sayHello
  12. 1006 2018-09-20 09:54:16 0.241863 true false 0x55965cca DemoServiceImpl sayHello
  13. 1007 2018-09-20 09:54:17 0.305747 true false 0x55965cca DemoServiceImpl sayHello
  14. 1008 2018-09-20 09:54:18 0.18468 true false 0x55965cca DemoServiceImpl sayHello

Classloader

  1. $ classloader
  2. name numberOfInstances loadedCountTotal
  3. BootstrapClassLoader 1 3346
  4. com.taobao.arthas.agent.ArthasClassloader 1 1262
  5. java.net.URLClassLoader 2 1033
  6. org.apache.catalina.loader.ParallelWebappClassLoader 1 628
  7. sun.reflect.DelegatingClassLoader 166 166
  8. sun.misc.Launcher$AppClassLoader 1 31
  9. com.alibaba.fastjson.util.ASMClassLoader 6 15
  10. sun.misc.Launcher$ExtClassLoader 1 7
  11. org.jvnet.hk2.internal.DelegatingClassLoader 2 2
  12. sun.reflect.misc.MethodUtil 1 1

Web Console

web console

Profiler/FlameGraph

  1. $ profiler start
  2. Started [cpu] profiling
  1. $ profiler stop
  2. profiler output file: /tmp/demo/arthas-output/20211207-111550.html
  3. OK

View profiler results under arthas-output via browser:

Arthas Spring Boot Starter

Known Users

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)

Alibaba
Alipay
Aliyun
Taobao
ICBC
雪球财经
顺丰科技
贝壳找房
vipkid
百度凤巢
有赞
科大讯飞
智联招聘
达美盛

Derivative Projects

Credits

Contributors

This project exists, thanks to all the people who contributed.

Projects

  • bytekit Java Bytecode Kit.
  • greys-anatomy: The Arthas code base has derived from Greys, we thank for the excellent work done by Greys.
  • termd: Arthas’s terminal implementation is based on termd, an open source library for writing terminal applications in Java.
  • crash: Arthas’s text based user interface rendering is based on codes extracted from here
  • cli: Arthas’s command line interface implementation is based on cli, open sourced by vert.x
  • compiler Arthas’s memory compiler.
  • Apache Commons Net Arthas’s telnet client.
  • async-profiler Arthas’s profiler command.