Arthas使用指导

总结摘要
Arthas使用指导

学习教程

简介

https://arthas.aliyun.com/doc/

tutorials

https://arthas.aliyun.com/doc/arthas-tutorials

工作六年,我学会了用 Arthas 来辅助我的日常工作

https://juejin.cn/post/7291931708920512527?searchId=202508300951578825515275F1B4F7698E#

无敌的Arthas!

https://juejin.cn/post/7393551590458556451

Arthas实践–jad/mc/redefine线上热更新一条龙 #537

https://github.com/alibaba/arthas/issues/537

手把手教你实现热更新功能,带你了解 Arthas 热更新背后的原理

https://www.cnblogs.com/goodAndyxublog/p/11880314.html

[笔记]使用 Arthas 获取Class 对象参数

https://blog.csdn.net/qq_19922839/article/details/126709510

相关工具

arthas-idea

https://plugins.jetbrains.com/plugin/13581-arthas-idea

https://www.yuque.com/arthas-idea-plugin/help/pe6i45

Arthas Idea Help Tools,Help generated Arthas Common Command Arthas Idea Plugin Document

实践案例

执行静态方法

1
2
3
4
## 执行静态方法
sc *SpringUtil
sc -d cn.hutool.extra.spring.SpringUtil
ognl -c 213c313 ‘@cn.hutool.extra.spring.SpringUtil@getBean(@com.example.Main@class)

问题记录

问题

Arthas 运行依赖完整版的JDK 环境。·
否则可能报错 Exception in thread "main" java.lang.IllegalArgumentException: Can not find tools.jar under java home

解决方案

  1. 部署完整 JDK。
  2. 部署 jattach。

参考资料
听说你没法在JRE中使用arthas?不,你可以
https://robberphex.com/attach-arthas-on-jre/
生产环境只装了JRE #2049
https://github.com/alibaba/arthas/issues/2049

问题

OGNL 命令 ognl '@com.xxx.className@methodName("param")' 执行报错 Failed to execute ognl, exception message: ognl.MethodFailedException

解决方案

ognl 添加参数指定类加载器,示例 ognl -c 5ef04b5 xxx
可以通过 sc -d className 命令查询类加载器。

参考资料

新版本 ognl 有一个 UseStricterInvocation 模块,默认开启,执行 ognl 表达式容易出现: cannot be called from within OGNL invokeMethod() under stricter invocation mode #2955
https://github.com/alibaba/arthas/issues/2955
Arthas ognl ClassNotFoundException
https://blog.csdn.net/tz986548749/article/details/131223731

问题

arthas 命令执行失败,错误信息显示“please check $HOME/logs/arthas/arthas.log for more details”,但是该日志文件中未记录相关异常日志。

解决方案
异常日志实际打印在 Tomcat 工具的 catalina.out 日志文件中。
背景:业务代码打包为 war 部署在独立的 Tomcat 之中。

mc 命令一直报错Memory compiler error, exception message: null, please check $HOME/logs/arthas/arthas.log for more details. #799

https://github.com/alibaba/arthas/issues/799

解决方案:arthas 和 Java 程序使用相同的 jre/jdk 环境。

如果使用 jre,可能需要将 jdk 中的 tools.jar 和 libattach.so 复制到 jre/lib 中相关目录。

Arthas使用mc 命令时,报错:Memory compiler error, exception message: Can not load JavaCompiler …

https://blog.csdn.net/m0_47743175/article/details/128692770

确保arthas-boot.jar与监控项目所启动的JDK保持一致!

Arthas排查Kubernetes中的应用频繁挂掉重启问题 #561

https://github.com/alibaba/arthas/issues/561

异常分析:java.lang.UnsatisfiedLinkError: no attach in java.library.path

解决方案:把tools.jar补全放入jre/lib 后, 你还差一步, 需要将libattach.so也copy到相应的位置, arm的机器jre/lib/aarch64/

sandbox load jvm failed : no attach in java.library.path #1129

https://github.com/chaosblade-io/chaosblade/issues/1129

异常分析:java.lang.UnsatisfiedLinkError: no attach in java.library.path

解决方案:把tools.jar补全放入jre/lib 后, 你还差一步, 需要将libattach.so也copy到相应的位置, arm的机器jre/lib/aarch64/

尝试一

修改依赖 MyBatis 框架的 Dao Interface 中的 @Insert 注解中的 SQL,redefine 命令执行成功,但实际上未修改代码。

推测是因为热部署 class 不会影响 MyBatis 缓存的结果。

用 redefine 生成的 class 替换 tomcat 中解压应用程序的 class 并重启应用程序,代码修改生效。

尝试二

修改 class 中 filed 的字段类型、新增方法。

Arthas 明确说明不支持此类修改。

END