Arthas 是一款线上监控诊断产品,通过全局视角实时查看应用 load、内存、gc、线程的状态信息,并能在不修改应用代码的情况下,对业务问题进行诊断,包括查看方法调用的出入参、异常,监测方法执行耗时,类加载信息等,大大提升线上问题排查效率。
我这里使用的是Arthas Tunnel。
关于arthas Tunnel的部署,请移步《docker(二十九)docker-compose部署arthas》
部署成功之后,接下来我们研究如何在Springboot3中集成arthas Tunnel
这部分,还是参考官方文档:arthas.aliyun.com/doc/spring-…
参考官网给出的提示:arthas 3.7.2及以后的版本同时支持 springboot 2/3
一:添加POM依赖
<!--arthas监控-->
<dependency>
<groupId>com.taobao.arthas</groupId>
<artifactId>arthas-spring-boot-starter</artifactId>
<version>3.6.6</version>
</dependency>
二:application.properties文件添加配置
arthas.agent-id= form-demo_123123123
arthas.tunnel-server=ws://127.0.0.1:7777/ws
**1) ** 如果agent-id没有_,直接返回了null,列表就不显示应用了,所以后面添加 随机id,前面最好不要有,例如form_demo_123123123最后会显示form
**2) ** 上方的127.0.0.1换成你的IP
到这里,你就可以启动你的项目了,应用启动后,spring 会启动 arthas,并且 attach 自身进程。控制台输出如下图所示:

访问arthas Tunnel:http://127.0.0.1:9080/apps.html,如下图所示:
三:配置IDEA-arthas插件
IDEA有arthas插件,可以让我们更加方便的使用arthas
使用也很简单:想对某个方法进行追踪,点到方法名后【右键】
如:选择【Trace】后,已完成复制,直接粘贴即可,以下就是复制完粘贴自动出来的:
trace com.modules.controller.fontend.IndexController getData -n 5 --skipJDKMethod false
简单解释一下上方的命令:
1) trace是Arthas提供的命令,用于动态跟踪方法调用。
2) com.modules.controller.fontend.IndexController是你想要跟踪的类的全限定名。
3) getData是你想要跟踪的方法名。
4) -n 5表示只显示最近5次的调用记录。
5) --skipJDKM表示跳过对JDK方法的跟踪。
四:使用arthas Tunnel监控
在arthas中运行上方复制的命令:
trace com.modules.controller.fontend.IndexController getData -n 5 --skipJDKMethod false
报错:
ERROR c.t.arthas.core.advisor.Enhancer -Enhancer error, matchingClasses: [class com.modules.controller.fontend.IndexController,
class com.modules.controller.fontend.IndexController$$EnhancerBySpringCGLIB$$1]
java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields)
这个报错是因为我项目中集成了skywalking造成的。
解决方案:
在IDEA的配置中添加:
-Dskywalking.agent.is_cache_enhanced_class=true -Dskywalking.agent.class_cache_mode=MEMORY
再次在arthas Tunnel中执行命令:
trace com.modules.controller.fontend.IndexController getData -n 5 --skipJDKMethod false
更多使用请参考官方文档:
arthas.aliyun.com/doc/command…
以上大概就是Springboot集成arthas Tunnel以及简单使用的全部过程。
更加深入的使用,后期再说。
最后切记:arthas Tunnel是没有权限控制的,只要是知道地址,既可以访问,所以呢,使用的时候需要注意一下。或者使用Security。
有好的建议,请在下方输入你的评论。