Java essay Java essay
首页
  • Java基础
  • Java进阶
  • 设计模式
  • Java你不知道的小事
  • Spring初识
  • Spring进阶
  • SpringBoot基础
  • SpringBoot进阶
  • 什么是微服务
  • SpringCloud全家桶
  • Dubbo
  • SpringCloud Alibaba
  • Zookeeper
  • Nginx
  • RabbitMQ
  • RocketMQ
  • Docker入门到精通
  • 性能分析工具
  • 数据库性能优化
  • 性能优化
  • Java基础面试必问
  • JavaWeb面试必问
  • Java框架面试必问
  • 数据库面试必问
  • 中间件面试必问
  • 分布式微服务面试必问
  • Linux面试必问
  • 计算机网络面试必问
  • 开放性问题面试问必问
  • 简介
  • 联系我

Mr.Fire

后端程序员一枚
首页
  • Java基础
  • Java进阶
  • 设计模式
  • Java你不知道的小事
  • Spring初识
  • Spring进阶
  • SpringBoot基础
  • SpringBoot进阶
  • 什么是微服务
  • SpringCloud全家桶
  • Dubbo
  • SpringCloud Alibaba
  • Zookeeper
  • Nginx
  • RabbitMQ
  • RocketMQ
  • Docker入门到精通
  • 性能分析工具
  • 数据库性能优化
  • 性能优化
  • Java基础面试必问
  • JavaWeb面试必问
  • Java框架面试必问
  • 数据库面试必问
  • 中间件面试必问
  • 分布式微服务面试必问
  • Linux面试必问
  • 计算机网络面试必问
  • 开放性问题面试问必问
  • 简介
  • 联系我
  • 性能分析工具

    • 阿里开源神器之Arthas
      • 1 Arthas是什么?
      • 2 Arthas安装下载
      • 3 启动
      • 4 控制台访问
      • 5 关于配置
      • 6 命令
      • 7 tunnel server
        • 7.1下载tunnel server
        • 7.2在服务机器上启动两个应用
        • 7.3连接
        • 7.4 通过Spring Boot的Endpoint查看agent节点
        • 7.5查看所有应用
      • 8基础命令
    • 阿里开源神器之Arthas进阶
    • SpringBoot整合Arthas
    • IDEA集成Arthas插件
  • 数据库性能优化

  • 性能优化

  • Java虚拟机

  • 性能分析
  • 性能分析工具
Mr.Fire
2022-07-08
目录

阿里开源神器之Arthas

# 1 Arthas是什么?

Arthas 是Alibaba开源的Java诊断工具,深受开发者喜爱。

当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决:

这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?

我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?

遇到问题无法在线上 debug,难道只能通过加日志再重新发布吗?

线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!

是否有一个全局视角来查看系统的运行状况?

有什么办法可以监控到JVM的实时运行状态?

怎么快速定位应用的热点,生成火焰图?

怎样直接从JVM内查找某个类的实例?

# 2 Arthas安装下载

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

或者官网下载压缩包

地址:https://github.com/alibaba/arthas/releases (opens new window)

# 3 启动

默认情况下,arthas只监听 127.0.0.1,所以如果想从远程连接,则可以使用 --target-ip参数指定listen的IP

java -jar arthas-boot.jar   #默认127.0.0.1
1

或者

java -jar arthas-boot.jar --target-ip 172.22.37.21   #指定ip,可通过Web Console远程访问
1

说明:本案例因为用的是阿里云服务器,公网ip是通过NAT映射到了云服务器上。由于本地并不存在对应ip网卡,因此绑定的是内外ip,远程访问Web Console用外网ip

选择进程,输入1

# 4 控制台访问

http://60.205.187.137:8563// (opens new window)

或者

http://60.205.187.137:3658/ (opens new window)

PS:两个端口 , 3658是 telnet, 8563是 http端口。

# 5 关于配置

arthas.properties文件在arthas的目录下。 如果是自动下载的arthas,则目录在~/.arthas/lib/3.x.x/arthas/下面 如果是下载的完整包,在arthas解压目录下

# 6 命令

参考 https://arthas.aliyun.com/doc/commands.html (opens new window)

# 7 tunnel server

为什么要用tunnel server? 在流式计算里,Java进程可以是在不同的机器启动的,想要使用Arthas去诊断会比较麻烦,因为用户通常没有机器的权限,即使登陆机器也分不清是哪个Java进程 通常情况下,生产的机器都不会是一个,大部分是集群模式,利用tunnel server我们就可以把所有集群节点都管理起来

# 7.1下载tunnel server

下载地址: https://github.com/alibaba/arthas/releases (opens new window)

启动tunnel server

java -jar arthas-tunnel-server-3.6.3-fatjar
1

默认会生成一个密码,后续可用于登录tunnel-server控制台

访问http://60.205.187.137:8080/ (opens new window) ,目前还没有应用被attach

# 7.2在服务机器上启动两个应用

说明:这里我的应用已经集成了Arthas,启动自动attach到服务,无需单独启动arthas去attach, 关于SpringBoot集成arthas参考https://javaessay.cn/pages/f6a4ce/#_1-创建springboot项目 (opens new window) 通过IDEA直接启动或者通过下面脚本启动:

启动应用1

java -jar arthas-demo-0.0.1-SNAPSHOT.jar 

1
2

properties配置

server.port=8081
arthas.ip=127.0.0.1
arthas.http-port=8563
arthas.telnet-port=3658
arthas.agent-id=arthas_fire_1
arthas.tunnel-server=ws://127.0.0.1:7777/ws
arthas.outputPath=arthas-output
logging.config=classpath:log4j2.xml
1
2
3
4
5
6
7
8

启动应用2

java -jar arthas-demo-0.0.2-SNAPSHOT.jar 
1

properties配置

server.port=8082
arthas.ip=127.0.0.1
arthas.http-port=8564
arthas.telnet-port=3659
arthas.agent-id=arthas_fire_2
arthas.tunnel-server=ws://127.0.0.1:7777/ws
arthas.outputPath=arthas-output
logging.config=classpath:log4j2.xml
1
2
3
4
5
6
7
8

配置说明

  • arthas.agent-id :agentid,用于连接tunnel server ,不指定则自动生成的id即agentid,用于tunnel server连接

# 7.3连接

输入agentid,成功连接

# 7.4 通过Spring Boot的Endpoint查看agent节点

访问:http://60.205.187.137/actuator/arthas (opens new window),需要登录

  • 用户名:arthas
  • 密码:即刚刚启动生成的密码

# 7.5查看所有应用

访问http://60.205.187.137:8080/apps.html (opens new window)

# 8基础命令

https://arthas.aliyun.com/doc/commands.html (opens new window)

help  查看命令帮助信息
cls   清空当前屏幕区域
session  查看当前会话的信息
reset  重置增强类,将被 Arthas 增强过的类全部还原,Arthas 服务端关闭时会重置所有增强过的类
version  输出当前目标 Java 进程所加载的 Arthas 版本号
history  打印命令历史
quit   退出当前 Arthas 客户端,其他 Arthas 客户端不受影响
stop   关闭 Arthas 服务端,所有 Arthas 客户端全部退出
keymap   Arthas快捷键列表及自定义快捷键
dashboard   当前系统的实时数据面板
thread   查看当前 JVM 的线程堆栈信息
heapdump  类似jmap,只dump存活 --live
jad  查看源码
profiler 生成火焰图

参考:

官网:https://arthas.aliyun.com/en-us/ (opens new window)

文档:https://arthas.aliyun.com/doc/ (opens new window)

GitHub:https://github.com/alibaba/arthas (opens new window)

#Arthas
最后更新时间: 2023/03/01, 22:17:09
阿里开源神器之Arthas进阶

阿里开源神器之Arthas进阶→

最近更新
01
分布式系统核心理论CAP和BASE理论
03-05
02
分布式锁的几种实现方式
03-05
03
一文详解ThreadLocal是什么
03-01
更多文章>
Theme by Vdoing | Copyright © 2021-2023 Mr.Fire | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式