当前位置: 首页 > news >正文

[arthas]arthas安装使用

arthas是阿里开源的一个java线上监控以及诊断工具,在docker容器中我们无需重启服务,也不用更改代码,就可以完成对应用内存、线程、日志级别的修改、方法调用的出入参、异常监测、执行耗时等,xxxx.xxxx.xxxxx为脱敏内容

1. 在docker容器中怎么安装和启动arthas

1.1 远程下载arthas的jar

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

1.2 启动arthas

java -jar arthas-boot.jar

2. arthas可以解决哪些问题以及怎么解决

2.1 线上发布的容器内是否是包含最新编写的代码?反编译

jad com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance

2.2 线上加载的环境变量有哪些,变量值是什么?

sysenv
sysenv JAVA_OPTS
ognl '#env=@System@getenv(),{#env}'
ognl '#config=@System@getenv("proxy.config"),{#config}'

2.3 线上的系统属性有哪些,属性值是什么?

sysprop
sysprop nacos.config.password
sysprop nacos.config.password test 永久修改
ognl '#properties=@System@getProperties(),{#properties}'
ognl '#SW_AGENT_NAME=@System@getProperty("SW_AGENT_NAME"),{#SW_AGENT_NAME}'

2.4 打印日志级别较低的日志:FATAL > ERROR > WARN > INFO > DEBUG > TRACE(未生效)

logger-- root路径下整体更新
logger --name ROOT --level debug-- 没有特别指定日志等级
logger -n com.xxxx.xxxx.xxxxx.cache;-- 查看classloader hashcode
sc -d com.xxxx.xxxx.xxxxx.cache;-- 根据hashcode更新level
logger -c 5cc69cfe --name ROOT --level debug

2.5 查看类的静态属性以及对静态属性的处理

getstatic com.xxxx.xxxx.xxxxx.cache.ApiDefCache apiDefCachegetstatic com.xxxx.xxxx.xxxxx.cache.ApiDefCache apiDefCache 'entrySet().iterator.{? #this.key=="I_REDPAY_P01_REDPAYGETORDER_1.0_DEF"}'
getstatic com.xxxx.xxxx.xxxxx.cache.ApiDefCache apiDefCache 'get("I_REDPAY_P01_REDPAYGETORDER_1.0_DEF")'
getstatic com.xxxx.xxxx.xxxxx.cache.ApiDefCache apiDefCache 'get("I_REDPAY_P01_REDPAYGETORDER_1.0_DEF").getCode()'
getstatic com.xxxx.xxxx.xxxxx.cache.ApiDefCache apiDefCache 'size()'
getstatic com.xxxx.xxxx.xxxxx.cache.ApiDefCache apiDefCache 'put("1","2")'
getstatic com.xxxx.xxxx.xxxxx.cache.ApiDefCache apiDefCache 'entrySet().iterator.{? #this.key=="1"}'
getstatic com.xxxx.xxxx.xxxxx.cache.ApiDefCache apiDefCache 'remove("1")'sc -d com.xxxx.xxxx.xxxxx.cache.ApiDefCache
ognl '@com.xxxx.xxxx.xxxxx.cache.ApiDefCache@apiDefCache'(不一定可以找到类,因为默认只会去SystemClassLoader里找类)
ognl -c 5cc69cfe '@com.xxxx.xxxx.xxxxx.cache.ApiDefCache@apiDefCache'getstatic com.xxxx.xxxx.xxxxx.util.ProxyUtil proxySelectFromDbSwitch
getstatic com.xxxx.xxxx.xxxxx.util.ProxyUtil proxySelectFromDbSwitch '#this.value=true' 
ognl -c 5cc69cfe '@com.xxxx.xxxx.xxxxx.util.ProxyUtil@proxySelectFromDbSwitch'
ognl -c 5cc69cfe '#value=true, @com.xxxx.xxxx.xxxxx.util.ProxyUtil@proxySelectFromDbSwitch.value=#value'

2.6 查看实例对象的方法调用以及实例对象的属性

watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send-- -x 指定输出结果的属性遍历深度
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send -x 3-- 只查看入参
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send "{params}"-- 只查看第一个入参
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send "{params[0]}"-- 只查看第一个入参的code字段
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send "{params[0].code}"-- 只查看第一个入参且入参的code字段值为payment
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send '{params[0]}' '{params[0].code=="payment"}'-- 只查看方法所在类对象实例
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send "{traget}"-- 只查看方法所在类对象实例的defaultOkHttpClient字段
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send "{target.defaultOkHttpClient}" -x 3-- 只查看方法的返回结果
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send "{result}"-- 查看方法的入参,所在类实例,返回结果
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send "{params, target, result}"-- 在方法调用之前观察(返回值,异常均不存在)
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send -b-- 在方法调用异常之后观察
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send -e-- 在方法返回之后观察(默认)
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send -s-- 在方法结束之后观察
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send -fAtEnter,AtExit,AtExceptionExit。对应函数入口,函数正常 return,函数抛出异常-- 当方法耗时超过200ms才进行观察
watch com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send '{params, returnObj}' '#cost>200' -x 2

2.7 调整展示结果的形式为json

options json-format true

2.8 方法调用链路分析

stack com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send
stack com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send '#cost>200'

2.9 将stack、watch等命令在后台执行并将结果输出到指定文件目录

stack com.xxxx.xxxx.xxxxx.communication.http.HttpClientInstance send >> stack.out & -- 查看
cat stack.out-- 查看后台执行的任务
jobs
-- 停止后台任务 
kill <job-id>
-- 后台任务最多支持同时执行8个,默认一天后会超时自动关闭,可以通过options的job-timeout调整超时时间

2.10 容器内部线程分析

–查看最繁忙的前3个线程

thread -n 3

3. 高级用法

  • 获取Spring context,然后调用bean执行方法等等:
    • https://github.com/alibaba/arthas/issues/482
  • 本地代码热部署到远程服务器:
    • https://arthas.aliyun.com/doc/idea-plugin.html

4. 官方文档

https://arthas.aliyun.com/doc

http://www.lqws.cn/news/157321.html

相关文章:

  • vue+element-ui一个页面有多个子组件组成。子组件里面有各种表单,实现点击enter实现跳转到下一个表单元素的功能。
  • 成都芯谷金融中心·文化科技产业园:构建产业新城的实践与探索
  • 基于大数据爬虫+智能AI的网络小说数据可视化系统设计与实现
  • Unity基础-Mathf相关
  • 3ds Max 渲染技术突破:一键解锁照片级真实感!
  • 小程序引入deepseek
  • 每日算法-250605
  • xmind转换为markdown
  • QQ邮箱发送验证码(Springboot)
  • SDC命令详解:使用set_max_fanout命令进行约束
  • MacOS解决局域网“没有到达主机的路由 no route to host“
  • [原创](现代Delphi 12指南):[macOS 64bit App开发]: TTask创建多线程, 更简单, 更快捷.
  • Git 安装全攻略Linux、macOS、Windows 与源码编译
  • redis数据过期策略、淘汰策略
  • 安卓四大组件数据存储Handler
  • React从基础入门到高级实战:React 实战项目 - 项目一:在线待办事项应用
  • Kafka入门-消费者
  • 作为过来人,浅谈一下高考、考研、读博
  • 关于akka官方quickstart示例程序(scala)的记录
  • UDP:简洁高效的报文结构解析与关键注意事项
  • 计算机网络备忘录
  • 网络通信核心概念全解析:从IP地址到TCP/UDP实战
  • ​减少交通拥堵、提高效率、改善交通安全的智慧交通开源了。
  • CodeGeeX 本地模式
  • Golang——9、反射和文件操作
  • 使用SSH tunnel访问内网的MySQL
  • VSCode主题定制:CSS个性化你的编程世界
  • nginx.conf配置详解:从(413 Request Entity Too Large)说起
  • 《前端面试题:CSS的display属性》
  • 基于SpringBoot和PostGIS的OSM时空路网数据入库实践