java线上项目排查,Arthas简单上手

Arthas 是Alibaba开源的Java诊断工具。参考:Arthas 用户文档 — Arthas 3.5.4 文档
当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决:

  1. 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?
  2. 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?
  3. 遇到问题无法在线上 debug,难道只能通过加日志再重新发布吗?
  4. 线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!
  5. 是否有一个全局视角来查看系统的运行状况?
  6. 有什么办法可以监控到JVM的实时运行状态?
  7. 怎么快速定位应用的热点,生成火焰图?
    Arthas支持JDK 6+,支持Linux/Mac/Winodws,采用命令行交互模式,同时提供丰富的 Tab 自动补全功能,进一步方便进行问题的定位和诊断。

1、安装(Linux):

curl -L https://alibaba.github.io/arthas/install.sh | sh

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value

2、启动:

./as.as

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
在这里插入图片描述

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
序号后的数值(如:15075)为当前服务器上的进程PID。选择你要排查的项目进程,选择序号(如:1):
在这里插入图片描述

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
则进入到arthas交互页面。

3、常用命令:

3.1)“上帝视角”,即Dashboard。对当前项目的数据监控。
在这里插入图片描述

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
3.2)thread。查看当前线程信息,查看线程的堆栈。
thread:查看所有线程。
thread -n 5:查看最忙(CPU使用率最高)的5条线程。
thread -b:找出当前阻塞其他线程的线程。
thread -state:查看指定状态的线程。
在这里插入图片描述

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
3.3)jad。反编译class。

jad com.icode.controller.VersionController

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
在这里插入图片描述

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
3.4) watch。观察指定方法的调用情况。能观察到的范围为:返回值、抛出异常、入参,通过编写 OGNL 表达式进行对应变量的查看。
如查看某个方法的返回值:

watch 全路径类名 方法名 returnObj

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
在这里插入图片描述

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
3.5) trace。输出方法路径上的每个节点上耗时。

trace 全路径类名 方法名

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
在这里插入图片描述

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value
3.6)jvm。查看当前JVM信息。
在这里插入图片描述

http://172.18.156.232:8090/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.broken.image&locale=zh_CN&version=2com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value

4、中断、退出:

4.1)使用ctrl+c中断artahs执行。
4.2)使用 exit 退出arthas。

此外,arthas还提供web console。通过浏览器连接arthas。
其他常用命令,以及用法参考官方文档。 这里只展示几个测试用的简单上手命令。以供以后查阅。

示例为Linux版本操作,windows大致一致

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值