Arthas线上诊断
   点滴记录   2 评论   731 浏览

Arthas线上诊断

   点滴记录   2 评论   731 浏览

场景

遇到个线上问题,调用三方接口报错:“请求需要使用token认证;请检查请求Header中是否填了正确的Authorization”。
该问题很明显是token填写格式问题,由于是商店应用本地调试需要更改很多配置,所以线上调试会更快。

Arthas

线上服务器执行

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

之后会列出服务器正在运行的jar程序

[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 22023 xxx.jar
  [2]: 18084 xxx2.jar
  [3]: 21167 org.apache.catalina.startup.Bootstrap

假如报错的为程序1,输入1后回车

此时为终端输入模式,输入如下命令定位该问题,之后将会解释下命令内容和给出命令文档:

watch com.rawchen.tools.PooledHttpUtils getData -x 2 -b -s -n 5

此时终端为监听模式,只要再次触发com.rawchen.tools.PooledHttpUtils包下的getData方法,将会准备输出该方法中的入参,出参,抛出异常,类中字段值。至多5条。

Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 82 ms, listenerId: 4
▌

最后得到的数据:

method=com.rawchen.tools.PooledHttpUtils.getData location=AtExit
ts=2024-03-22 11:21:05; [cost=6.452475626433412E10ms] result=@ArrayList[
    @Object[][
        @String[621d8594dc],
        @HttpConfig[headers=[Authorization: Beareru-eeharKx8hpbaLPojKdKJcak3FcK8F5l9W014Kw20j], cookies=null],
        null,
    ],
    @ApiController[
        log=@Logger[Logger[com.rawchen.alipan.controller.ApiController]],
        parentFileId=@String[root],
        apiUrl=@String[https://api.baidu.com],
        apiUrlV3=@String[https://api.baidu.com/v3],
        oauthTokenUrl=@String[https://baidu.com/token],
        openApiUrl=@String[https://baidu.com],
        refererURL=@String[https://baidu.com],
        passwordFileName=@String[pwd],
        appId=@String[5dde4e1bdf9e4966b387ba58f4b],
    ],
    @ArrayList[
        @PanFile[PanFile{fileId='621d85af96156951062f4cb4ad0b06fb5', type='folder', name='测试文件夹1', parentFileId='621d8594dc9e9ad3b63e47d9b599edbb04', createdAt='2022-03-01T02:32:15.410Z', fileExtension='null', size=0, url='null', previewUrl='null', encrypted=false}],
        @PanFile[PanFile{fileId='621d85b6c6f56dac771645f2b413b39ae', type='folder', name='测试文件夹2', parentFileId='621d8594dc9e9ad3b63e47d9b599edbb04', createdAt='2022-03-01T02:32:22.717Z', fileExtension='null', size=0, url='null', previewUrl='null', encrypted=false}],
    ],
]

分析

由此便可知问题了,可以看出请求头出现Authorization为Bearer后加token,拼接时出现少空格情况。因为我们统一在common层做的处理,此时才知道是引入的common为旧版依赖,所以代码有缺陷导致的。

总结

其实这只是Arthas最基础的线上方法观测功能,还有很多例如方法监测、线上调试、JVM运行状态、线程堆栈、反编译、解决冲突等。可以查看Arthas官方文档

dashboard

monitor

profiler

用户案例

https://github.com/alibaba/arthas/issues?q=label%3Auser-case

原理分析

attach连接JVM、实现应用代码隔离类隔离、支持OGNL
https://blog.csdn.net/lym152898/article/details/131345547

本文由 RawChen 发表, 最后编辑时间为:2024-03-22 14:14
如果你觉得我的文章不错,不妨鼓励我继续写作。

发表评论
选择表情
  1. 不觉明历+1 chigua.png

       Windows 10   Chrome 114
  2. icon_eek.png 这个看着有点高深了,不觉明历 哈哈

       Windows 10   Chrome 123
Top