【tower-boot 系列】Arthas 集成

Arthas 介绍

Arthas是Alibaba开源的一款Java诊断工具,方便开发者在线排查问题,无需重启,同时可以跟踪Java代码,实时监控JVM状态,目前Arthas仅支持JDK6+,支持Linux/Mac/Windows,采用命令行交互模式,具有 Tab 自动补全功能,便于开发者进行快速定位和诊断问题。

Arthas 集成

一、下载

参考官网:https://arthas.aliyun.com/doc/ 集成。
下载部署 arthas-tunnel-server.jar
从 Maven 仓库下载:https://arthas.aliyun.com/download/arthas-tunnel-server/latest_version?mirror=aliyun
从 Github Releases 页下载: https://github.com/alibaba/arthas/releases

二、部署 arthas-tunnel-server.jar 3.7.1版本为例

1、直接启动 或后台启动写法

java -jar arthas-tunnel-server-3.7.1-fatjar.jar
nohup java -jar arthas-tunnel-server-3.7.1-fatjar.jar > server.out &

2、管理平台
默认情况下,arthas tunnel server 的web 端口是8080,arthas agent 连接的端口是7777。
通过 Spring Boot 的 Endpoint,可以查看到具体的连接信息:http://127.0.0.1:8080/actuator/arthas ,
登陆用户名是arthas,密码在 arthas tunnel server 的日志里可以找到。

三、spring 项目引用配置

1、pom依赖

<dependency>
    <groupId>com.taobao.arthas</groupId>
    <artifactId>arthas-spring-boot-starter</artifactId>
    <version>3.7.1</version>
</dependency>

2、yml 依赖

arthas:
  # telnetPort、httpPort为 -1 ,则不listen telnet端口,为 0 ,则随机telnet端口
  # 如果是防止一个机器上启动多个 arthas端口冲突。可以配置为随机端口,或者配置为 -1,并且通过tunnel server来使用arthas。
  # ~/logs/arthas/arthas.log (用户目录下面)里可以找到具体端口日志
  telnetPort: -1
  httpPort: -1
  # 127.0.0.1只能本地访问,0.0.0.0则可网络访问,但是存在安全问题
  ip: 127.0.0.1
  appName: arthas_test
  # 默认情况下,会生成随机ID,如果 arthas agent配置了 appName,则生成的agentId会带上appName的前缀。
  agent-id: hxl123456
  # tunnel-server地址
  tunnel-server: ws://127.0.0.1:7777/ws

四、其他集成方式

1、pom依赖

<dependency>
    <groupId>com.taobao.arthas</groupId>
    <artifactId>arthas-agent-attach</artifactId>
    <version>${arthas.version}</version>
</dependency>

<dependency>
    <groupId>com.taobao.arthas</groupId>
    <artifactId>arthas-packaging</artifactId>
    <version>${arthas.version}</version>
</dependency>

2、用法

HashMap<String, String> configMap = new HashMap<String, String>();
configMap.put("arthas.appName", "demo");
configMap.put("arthas.tunnelServer", "ws://127.0.0.1:7777/ws");
ArthasAgent.attach(configMap);

五、常见命令

dashboard - 当前系统的实时数据面板
getstatic - 查看类的静态属性
heapdump - dump java heap, 类似 jmap 命令的 heap dump 功能
jvm - 查看当前 JVM 的信息
logger - 查看和修改 logger
mbean - 查看 Mbean 的信息
memory - 查看 JVM 的内存信息
ognl - 执行 ognl 表达式
perfcounter - 查看当前 JVM 的 Perf Counter 信息
sysenv - 查看 JVM 的环境变量
sysprop - 查看和修改 JVM 的系统属性
thread - 查看当前 JVM 的线程堆栈信息
vmoption - 查看和修改 JVM 里诊断相关的 option
vmtool - 从 jvm 里查询对象,执行 forceGc

六、tower-boot sdk 集成

github: https://github.com/sanxiaoshitou/tower-boot

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值