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.

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在Ubuntu上安装Arthas,您可以按照以下步骤进行操作: 1. 首先,确保您的系统已经安装了curl。如果没有安装,可以使用以下命令安装curl: ``` sudo apt-get update sudo apt-get install curl ``` 2. 然后,使用curl命令下载Arthas安装包: ``` curl -0 https://arthas.aliyun.com/arthas-boot.jar --output arthas-boot.jar ``` 3. 下载完成后,您可以使用以下命令运行Arthas: ``` java -jar arthas-boot.jar ``` 这样就完成了在Ubuntu上安装Arthas的过程。请注意,您需要确保您的系统已经安装Java开发工具包(JDK)。 希望这个回答对您有帮助!如果您还有其他问题,请随时提问。 #### 引用[.reference_title] - *1* [java诊断神器 arthas(阿尔萨斯)](https://blog.csdn.net/Asia1752/article/details/119391408)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [ubuntu18.04 atash安装](https://blog.csdn.net/weixin_42108533/article/details/124599152)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Alibaba开源的Java诊断工具Arthas(阿尔萨斯) 安装文档](https://blog.csdn.net/weixin_34235135/article/details/92419781)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值