arthas安装使用说明

arthas安装使用说明

简介

Arthas(阿尔萨斯)  --- 阿里开源的一个Java在线分析诊断工具

一、安装arthas工具

(公司服务器禁止个人安装软件包,如无此工具的联系运维进行安装。)

yum install arthas -y

二、使用说明

a)  使用arthas诊断工具,当前用户需要有权限访问相应java进程,root用户可以访问所有进程,而非root用户,例如ops或dev账号登录的,需要先su切入到相应java进程用户。

  ( 我们服务器登录账号为dev, 应用程序运行账号统一为app用户,因此在dev用户下,需要执行 sudo su - app ,切换到app用户,或者使用快捷命令 su-app:

< dev@app5-ec-test-bj2:~ >$ whoami   # 切换前是dev用户

dev

< dev@app5-ec-test-bj2:~ >$ su-app   # 执行su-app命令切换到app用户

Last login: Wed Dec 12 19:52:24 CST 2018 on pts/2

< app@app5-ec-test-bj2:~ >$ whoami   # 切换后为app用户

app

< app@app5-ec-test-bj2:~ >$

b) arthas工具集成为一个 arthas-boot 命令

arthas-boot -h 可以查看帮助

< app@app5-ec-test-bj2:~ >$ arthas-boot -h

Usage: arthas-boot [-h] [--target-ip <value>] [--telnet-port <value>]

       [--http-port <value>] [--session-timeout <value>] [--arthas-home <value>]

       [--use-version <value>] [--repo-mirror <value>] [--versions] [--use-http]

       [--attach-only] [-c <value>] [-f <value>] [-v] [pid]

Bootstrap Arthas

EXAMPLES:

  java -jar arthas-boot.jar <pid>

  java -jar arthas-boot.jar --target-ip 0.0.0.0

  java -jar arthas-boot.jar --telnet-port 9999 --http-port -1

  java -jar arthas-boot.jar -c 'sysprop; thread' <pid>

  java -jar arthas-boot.jar -f batch.as <pid>

  java -jar arthas-boot.jar --use-version 3.0.5

  java -jar arthas-boot.jar --versions

  java -jar arthas-boot.jar --session-timeout 3600

  java -jar arthas-boot.jar --attach-only

  java -jar arthas-boot.jar --repo-mirror aliyun --use-http

WIKI:

  https://alibaba.github.io/arthas

Options and Arguments:

 -h,--help                      Print usage

    --target-ip <value>         The target jvm listen ip, default 127.0.0.1

    --telnet-port <value>       The target jvm listen telnet port, default 3658

    --http-port <value>         The target jvm listen http port, default 8563

    --session-timeout <value>   The session timeout seconds, default 300

    --arthas-home <value>       The arthas home

    --use-version <value>       Use special version arthas

    --repo-mirror <value>       Use special maven repository mirror, value is

                                center/aliyun or http repo url.

    --versions                  List local and remote arthas versions

    --use-http                  Enforce use http to download, default use https

    --attach-only               Attach target process only, do not connect

 -c,--command <value>           Command to execute, multiple commands separated

                                by ;

 -f,--batch-file <value>        The batch file to execute

 -v,--verbose                   Verbose, print debug info.

 <pid>                          Target pid

c) 查看需要诊断的java进程pid

< app@app5-ec-test-bj2:~ >$ ps aux|grep java

app       51645  1.8 11.4 5846204 932604 ?      Ssl  Dec11  24:48 /usr/java/default/jre/bin/java -jar xyy-ec-app.jar --spring.profiles.active=test

app       85637  3.6 11.4 7043724 935984 ?      Ssl  16:31   7:32 /usr/java/default/jre/bin/java -jar xyy-promotion-core-ms.jar --spring.profiles.active=test

app       85853  2.1 12.9 6931884 1058464 ?     Ssl  16:32   4:28 /usr/java/default/jre/bin/java -jar xyy-ec-promotion-business-ms.jar --spring.profiles.active=test

app      118139  0.0  0.0 112704   952 pts/2    S+   19:58   0:00 grep --colour java

d) 比如对 xyy-promotion-core-ms.jar 这个服务进程诊断,得到其PID:  85637  ,使用 arthas-boot <PID> 命令进出入arthas终端模式,输入help查看帮助。

官网文档:https://alibaba.github.io/arthas/quick-start.html

诊断完成后输入shutdown关闭arthas。

< app@app5-ec-test-bj2:~ >$ arthas-boot 85637

[INFO] Process 85637 already using port 3658

[INFO] Process 85637 already using port 8563

[INFO] arthas home: /usr/share/arthas

[INFO] The target process already listen port 3658, skip attach.

[INFO] arthas-client connect 127.0.0.1 3658

  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                          

 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                         

|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                         

|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                        

`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'                         

                                                                                 

wiki: https://alibaba.github.io/arthas

version: 3.0.5

pid: 85637

time: 2018-12-12 20:00:52

$ help

 NAME         DESCRIPTION                                                                                                                                                                                

 help         Display Arthas Help                                                                                                                                                                        

 keymap       Display all the available keymap for the specified connection.                                                                                                                             

 sc           Search all the classes loaded by JVM                                                                                                                                                       

 sm           Search the method of classes loaded by JVM                                                                                                                                                 

 classloader  Show classloader info                                                                                                                                                                      

 jad          Decompile class                                                                                                                                                                            

 getstatic    Show the static field of a class                                                                                                                                                           

 monitor      Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc.                                                                                         

 stack        Display the stack trace for the specified class and method                                                                                                                                 

 thread       Display thread info, thread stack                                                                                                                                                          

 trace        Trace the execution time of specified method invocation.                                                                                                                                   

 watch        Display the input/output parameter, return object, and thrown exception of specified method invocation                                                                                     

 tt           Time Tunnel                                                                                                                                                                                

 jvm          Display the target JVM information                                                                                                                                                         

 ognl         Execute ognl expression.                                                                                                                                                                   

 dashboard    Overview of target jvm's thread, memory, gc, vm, tomcat info.                                                                                                                              

 dump         Dump class byte array from JVM                                                                                                                                                             

 options      View and change various Arthas options                                                                                                                                                     

 cls          Clear the screen                                                                                                                                                                           

 reset        Reset all the enhanced classes                                                                                                                                                             

 version      Display Arthas version                                                                                                                                                                     

 shutdown     Shutdown Arthas server and exit the console                                                                                                                                                

 session      Display current session information                                                                                                                                                        

 sysprop      Display, and change the system properties.                                                                                                                                                 

 sysenv       Display the system env.                                                                                                                                                                    

 redefine     Redefine classes. @see Instrumentation#redefineClasses(ClassDefinition...)                                                                                                                 

 history      Display command history

e) 如果出现以下报错,说明上次执行arthas后,未执行shutdown进行关闭,请先使用arthas-boot <PID>命令进入并关闭上次诊断的java进程

$ < app@app5-ec-test-bj2:~ >$ arthas-boot 85853

[INFO] Process 85637 already using port 3658

[INFO] Process 85637 already using port 8563

[ERROR] Target process 85853 is not the process using port 3658, you will connect to an unexpected process.

[ERROR] If you still want to attach target process 85853, Try to set a different telnet port by using --telnet-port argument.

[ERROR] Or try to shutdown the process 85637 using the telnet port first.

猜你喜欢

转载自blog.csdn.net/zou100/article/details/84998559