阿里开源 java 项目内存监控工具 arthas

本贴最后更新于 1260 天前,其中的信息可能已经渤澥桑田

介绍

Arthas(阿尔萨斯)是阿里巴巴开源的Java诊断工具,实现了jvm自带的几乎所有诊断功能,深受jvm分析人员喜爱。

安装

因为这个工具是jar文件,需要有java运行环境,所以请先确保系统安装了jre或jdk

# 检测环境

java -version
# 显示类似如下,说明已经拥有java运行环境;
# 如果报错,请先安装或检查jre\jdk是否安装且配置环境变量

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
# linux系统

# 下载jar包
curl -O https://arthas.aliyun.com/arthas-boot.jar

# 运行监控
java -jar arthas-boot.jar

# 获取工具帮助
java -jar arthas-boot.jar -h

[INFO] arthas-boot version: 3.3.9
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>] [--height <value>] [--width
       <value>] [-v] [--tunnel-server <value>] [--agent-id <value>] [--stat-url
       <value>] [--select <value>] [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 --tunnel-server 'ws://192.168.10.11:7777/ws'
  java -jar arthas-boot.jar --tunnel-server 'ws://192.168.10.11:7777/ws'
--agent-id bvDOe8XbTM2pQWjF4cfw
  java -jar arthas-boot.jar --stat-url 'http://192.168.10.11:8080/api/stat'
  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.3.9
  java -jar arthas-boot.jar --versions
  java -jar arthas-boot.jar --select arthas-demo
  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://arthas.aliyun.com/doc

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 1800
                                (30min)
    --arthas-home <value>       The arthas home
    --use-version <value>       Use special version arthas
    --repo-mirror <value>       Use special remote 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
    --height <value>            arthas-client terminal height
    --width <value>             arthas-client terminal width
 -v,--verbose                   Verbose, print debug info.
    --tunnel-server <value>     The tunnel server url
    --agent-id <value>          The agent id register to tunnel server
    --stat-url <value>          The report stat url
    --select <value>            select target process by classname or
                                JARfilename
 <pid>                          Target pid

卸载: rm -rf ~/.arthas/

监控java进程

运行 java -jar arthas-boot.jar

arthas01.png

如果当前系统有多个java服务,则会显示多个进程id,选择你要监控的服务id,输入前面中括号中的数值

想要查看当前系统,是否有java服务,可以执行: ps -ef |grep java 或者 jps 如果有返回,则说明当前系统有java服务正在运行

也可以先找到系统的java服务进程id,然后直接执行:java -jar arthas-boot.jar java进程id

进入了arthas运行模式

arthas02.png

查看当前进程信息

执行 dashboard, 结束查看,按 ctrl + c

arthas03.png

获取命令帮助

执行 dashboard -h

arthas04.png

-i 更新数据间隔时长,单位毫秒,默认间隔时长为5秒

-n 根据间隔时长,获取数据,总共获取的次数

arthas中,所有命令都可以用 -h 参数,获取命令的帮助信息

其他常用命令

arthas05.png

arthas06.png

回帖
请输入回帖内容 ...