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

[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.xdnf.cn/news/12350.html

相关文章:

  • NVM!(可以快速替换你的node版本)
  • Mysql主从复制原理分析
  • 高性能分布式消息队列系统(三)
  • CVE-2020-17518源码分析与漏洞复现(Flink 路径遍历)
  • AtCoder 第408​场初级竞赛 A~E题解
  • 强化学习入门:Gym实现CartPole随机智能体
  • VBA信息获取与处理专题五第一节:利用CDO发送简单邮件
  • AirSim/Cosys-AirSim 游戏开发(二)使用自定义场景
  • Python训练营---Day45
  • DeepSeek 农业大模型:应用潜力与数据隐私保护的双重考量
  • Python训练营---Day44
  • MySQL常用知识总结
  • 三分算法与DeepSeek辅助证明是单峰函数
  • 学习路之PHP--webman安装及使用、webman/admin安装
  • OpenLayers 地图投影转换
  • 视频监控EasyCVR3.7.2版本支持更改播放器默认解码方式,该如何进行配置?
  • 组合与排列
  • 湖北理元理律所债务优化实践:法律技术与人文关怀的双轨服务
  • 【LC#39270】判断子序列爬楼梯(dp算法 第一期)
  • 面向开发者的提示词工程③——文本总结(Summarizing)
  • [蓝桥杯]序列计数
  • 26考研|数学分析:多元函数极限与连续
  • 面试总结。
  • 数据迁移是什么?数据迁移过程中
  • 细说STM32单片机FreeRTOS空闲任务及低功耗的设计方法及应用
  • Java(io)字节流
  • Java应用10(客户端与服务器通信)
  • App使用webview套壳引入h5(一)—— webview和打开的h5进行通信传参
  • 为什么 SDXL 用两个文本编码器?
  • aiohttp异步爬虫实战:从零构建高性能图书数据采集系统(2025最新版)