Arthas 新的打开方式

3,578 阅读2分钟

Arthas 新的打开方式

随着微服务的发展,spring boot应用越来越多。监控和排查问题的手段也越来越多。

本文就简单介绍一下Arthas与spring boot的简单使用。

1.引入jar包

  • 在已有的spring boot项目中引入arthas-spring-boot-starter,我这里用的是最新版本的jar。
<dependency>
  <groupId>com.taobao.arthas</groupId>
  <artifactId>arthas-spring-boot-starter</artifactId>
  <version>3.4.1</version>
</dependency>

2.配置application.yml信息

# arthas tunnel server配置
arthas:
  agent-id: maomao
  tunnel-server: ws://47.75.156.201:7777/ws

# 监控配置
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always
  • 配置扩展:

arthas.telnet-port: -1:则不监听telnet端口。0:随机端口。

arthas.http-port: -1: 不监听http端口。0:随机端口。

为了防止一台机器上启动多个arthas端口冲突,可以配置为随机端口0或者-1,然后通过tunnel server的方式来访问arthas。

本文采用的是tunnel server方式。

3.启动项目

启动项目后,然后在浏览器中输入[http://localhost:3658]地址。显示如下界面,就代表已经设置成功了。

image-20200920230417825
image-20200920230417825

我们也可以是输入在终端输入命令:java -jar arthas-boot.jar 70542 --tunnel-server 'ws://47.75.156.201:7777/ws' --agent-id 'maomao0' --attach-only

然后结果会显示为:

image-20200920230611016
image-20200920230611016

结果的大概意思就是说明arthas已经启动成功了,并且开始了telnet的监听端口3658,http监听端口为8563.

然后我们就可以在地址[http://localhost:3658]中使用arthas来查询相关信息了。

这里如果很多命令记住的情况下这里推荐使用idea的Arthas的插件,使用方法就不过多说明,大家可以自行研究。插件地址和介绍请看文末的参考内容。

4. 结语

本文简单了介绍了Arthas与spring boot的项目应用的集成,相对简单。非spring boot项目也可以集成Arthas,这里就不过说明,方式都是一样的。

该集成方式本人觉得还是很方便的,传统的运用Arthas来查看项目的相关信息时是要求Arthas启动的用户和项目的的启动用户是相同的,且是同级目录下才行。个人认为是有一定的缺陷的,因为生产环境的权限不是人人都有,或者不能修改Arthas的启动用户(这里的让运维协助来完成)。

将Arthas集成到项目中就显得非常方便。

参考