Arthas阿里线上问题排查工具

目录

Arthas(阿尔萨斯) 能为你做什么?

Arthas先睹为快

watch打印入参和返回值

trace打印方法执行的顺序和执行情况

tt静态方法字段值调用

monitor方法执行时间

通过浏览器连接arthas


网地址:https://arthas.aliyun.com/doc/index.html 

Arthas(阿尔萨斯) 能为你做什么?

_images/arthas.png

Arthas 是Alibaba开源的Java诊断工具,深受开发者喜爱。

当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决:

  1. 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?

  2. 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?

  3. 遇到问题无法在线上 debug,难道只能通过加日志再重新发布吗?

  4. 线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!

  5. 是否有一个全局视角来查看系统的运行状况?

  6. 有什么办法可以监控到JVM的实时运行状态?

  7. 怎么快速定位应用的热点,生成火焰图?

Arthas支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 Tab 自动补全功能,进一步方便进行问题的定位和诊断。

Arthas先睹为快

前提是安装好Arthas,参考国内gitee地址:https://gitee.com/arthas/arthas

watch打印入参和返回值

[arthas@18656]$ watch com.forestar.redis.RedisDistributedLock tryGetDistributedLock "{params,returnObj}" -x 2 -b -s -n 10
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 81 ms, listenerId: 7
method=com.forestar.redis.RedisDistributedLock.tryGetDistributedLock location=AtEnter
ts=2021-03-03 09:15:33; [cost=0.038707ms] result=@ArrayList[
    @Object[][
        @String[xht:application:hly-id-lock],
        @String[71f3965f-9429-4104-a475-03eacfd48dec],
        @Integer[5000],
    ],
    null,
]
method=com.forestar.redis.RedisDistributedLock.tryGetDistributedLock location=AtExit
ts=2021-03-03 09:15:33; [cost=2.3058954671954437E10ms] result=@ArrayList[
    @Object[][
        @String[xht:application:hly-id-lock],
        @String[71f3965f-9429-4104-a475-03eacfd48dec],
        @Integer[5000],
    ],
    @Boolean[true],
]
method=com.forestar.redis.RedisDistributedLock.tryGetDistributedLock location=AtEnter
ts=2021-03-03 09:15:43; [cost=0.016312ms] result=@ArrayList[
    @Object[][
        @String[xht:application:hly-id-lock],
        @String[7471d14f-4a60-4011-9623-d42b11e6d78c],
        @Integer[5000],
    ],
    null,
]
method=com.forestar.redis.RedisDistributedLock.tryGetDistributedLock location=AtExit
ts=2021-03-03 09:15:43; [cost=2.3058964472276306E10ms] result=@ArrayList[
    @Object[][
        @String[xht:application:hly-id-lock],
        @String[7471d14f-4a60-4011-9623-d42b11e6d78c],
        @Integer[5000],
    ],
    @Boolean[true],
]
method=com.forestar.redis.RedisDistributedLock.tryGetDistributedLock location=AtEnter
ts=2021-03-03 09:15:46; [cost=0.016448ms] result=@ArrayList[
    @Object[][
        @String[xht:application:hly-id-lock],
        @String[9132dcb6-b999-4fdc-902e-f834acd6a029],
        @Integer[5000],
    ],
    null,
]
method=com.forestar.redis.RedisDistributedLock.tryGetDistributedLock location=AtExit
ts=2021-03-03 09:15:46; [cost=2.3058967163121655E10ms] result=@ArrayList[
    @Object[][
        @String[xht:application:hly-id-lock],
        @String[9132dcb6-b999-4fdc-902e-f834acd6a029],
        @Integer[5000],
    ],
    @Boolean[false],
]
method=com.forestar.redis.RedisDistributedLock.tryGetDistributedLock location=AtEnter
ts=2021-03-03 09:15:51; [cost=0.011194ms] result=@ArrayList[
    @Object[][
        @String[xht:application:hly-id-lock],
        @String[9132dcb6-b999-4fdc-902e-f834acd6a029],
        @Integer[5],
    ],
    null,
]

trace打印方法执行的顺序和执行情况

[arthas@18656]$ trace com.forestar.xht.hly.XHRYCtrl hly_add 
Press Q or Ctrl+C to abort.
Affect(class count: 2 , method count: 2) cost in 319 ms, listenerId: 10
`---ts=2021-03-03 09:33:07;thread_name=http-nio-8081-exec-7;id=27;is_daemon=true;priority=5;TCCL=org.apache.catalina.loader.WebappClassLoader@432cd66e
    `---[2.241784ms] com.forestar.xht.hly.XHRYCtrl$$EnhancerByCGLIB$$9eca3052:hly_add()
        `---[2.068124ms] net.sf.cglib.proxy.MethodInterceptor:intercept() #95
            `---[1.930108ms] com.forestar.xht.hly.XHRYCtrl:hly_add()
                +---[0.036573ms] data.common.util.StringUtils:IsNullOrEmpty() #183
                +---[0.01407ms] com.forestar.xht.util.Utils:getWorkSpace() #189
                +---[0.044448ms] com.forestar.xht.util.Utils:getMetadataWorkspace() #192
                +---[0.017292ms] data.metadata.IMetadataWorkspace:OpenTable() #95
                +---[0.00912ms] com.forestar.xht.util.Utils:getBaseDataService() #193
                +---[0.183323ms] com.alibaba.fastjson.JSONObject:parseObject() #196
                +---[0.011264ms] data.general.RowBase:<init>() #198
                +---[0.010371ms] data.general.RowBase:setCurrentObjects() #199
                +---[0.008256ms] com.forestar.core.session.SessionFactory:getSession() #201
                +---[0.010008ms] com.forestar.core.session.ISession:getTableSuffix() #95
                +---[0.037512ms] data.general.RowBase:getCurrentObjects() #202
                +---[0.010109ms] com.forestar.syscore.encrypt.MD5:<init>() #203
                +---[0.006698ms] data.general.RowBase:getCurrentObjects() #204
                +---[0.034949ms] com.forestar.syscore.encrypt.MD5:getMD5() #95
                +---[0.008434ms] data.general.RowBase:getCurrentObjects() #206
                +---[0.007273ms] data.general.QueryFilter:<init>() #207
                +---[0.024029ms] data.general.QueryFilter:setWhereString() #208
                `---[0.77195ms] com.forestar.redis.RedisDistributedLock:tryGetDistributedLockByBlocking() #215
 
`---ts=2021-03-03 09:33:16;thread_name=http-nio-8081-exec-35;id=52;is_daemon=true;priority=5;TCCL=org.apache.catalina.loader.WebappClassLoader@432cd66e
    `---[1.0833ms] com.forestar.xht.hly.XHRYCtrl$$EnhancerByCGLIB$$9eca3052:hly_add()
        `---[1.019633ms] net.sf.cglib.proxy.MethodInterceptor:intercept() #95
            `---[0.954022ms] com.forestar.xht.hly.XHRYCtrl:hly_add()
                +---[0.007426ms] data.common.util.StringUtils:IsNullOrEmpty() #183
                +---[0.038057ms] com.forestar.xht.util.Utils:getWorkSpace() #189
                +---[0.00616ms] com.forestar.xht.util.Utils:getMetadataWorkspace() #192
                +---[0.007478ms] data.metadata.IMetadataWorkspace:OpenTable() #95
                +---[0.007375ms] com.forestar.xht.util.Utils:getBaseDataService() #193
                +---[0.038762ms] com.alibaba.fastjson.JSONObject:parseObject() #196
                +---[0.005113ms] data.general.RowBase:<init>() #198
                +---[0.006275ms] data.general.RowBase:setCurrentObjects() #199
                +---[0.006229ms] com.forestar.core.session.SessionFactory:getSession() #201
                +---[0.006964ms] com.forestar.core.session.ISession:getTableSuffix() #95
                +---[0.004853ms] data.general.RowBase:getCurrentObjects() #202
                +---[0.005499ms] com.forestar.syscore.encrypt.MD5:<init>() #203
                +---[0.004376ms] data.general.RowBase:getCurrentObjects() #204
                +---[0.019182ms] com.forestar.syscore.encrypt.MD5:getMD5() #95
                +---[0.004806ms] data.general.RowBase:getCurrentObjects() #206
                +---[0.005104ms] data.general.QueryFilter:<init>() #207
                +---[0.004758ms] data.general.QueryFilter:setWhereString() #208
                `---[0.511894ms] com.forestar.redis.RedisDistributedLock:tryGetDistributedLockByBlocking() #215
 
`---ts=2021-03-03 09:33:25;thread_name=http-nio-8081-exec-15;id=2f;is_daemon=true;priority=5;TCCL=org.apache.catalina.loader.WebappClassLoader@432cd66e
    `---[0.95822ms] com.forestar.xht.hly.XHRYCtrl$$EnhancerByCGLIB$$9eca3052:hly_add()
        `---[0.920732ms] net.sf.cglib.proxy.MethodInterceptor:intercept() #95
            `---[0.866213ms] com.forestar.xht.hly.XHRYCtrl:hly_add()
                +---[0.007652ms] data.common.util.StringUtils:IsNullOrEmpty() #183
                +---[0.011245ms] com.forestar.xht.util.Utils:getWorkSpace() #189
                +---[0.005283ms] com.forestar.xht.util.Utils:getMetadataWorkspace() #192
                +---[0.007431ms] data.metadata.IMetadataWorkspace:OpenTable() #95
                +---[0.007284ms] com.forestar.xht.util.Utils:getBaseDataService() #193
                +---[0.039893ms] com.alibaba.fastjson.JSONObject:parseObject() #196
                +---[0.005045ms] data.general.RowBase:<init>() #198
                +---[0.004925ms] data.general.RowBase:setCurrentObjects() #199
                +---[0.005901ms] com.forestar.core.session.SessionFactory:getSession() #201
                +---[0.008045ms] com.forestar.core.session.ISession:getTableSuffix() #95
                +---[0.00491ms] data.general.RowBase:getCurrentObjects() #202
                +---[0.005447ms] com.forestar.syscore.encrypt.MD5:<init>() #203
                +---[0.004425ms] data.general.RowBase:getCurrentObjects() #204
                +---[0.017348ms] com.forestar.syscore.encrypt.MD5:getMD5() #95
                +---[0.004585ms] data.general.RowBase:getCurrentObjects() #206
                +---[0.004571ms] data.general.QueryFilter:<init>() #207
                +---[0.004564ms] data.general.QueryFilter:setWhereString() #208
                `---[0.431266ms] com.forestar.redis.RedisDistributedLock:tryGetDistributedLockByBlocking() #215

tt静态方法字段值调用

获取类的静态字段、调用类的静态方法:https://arthas.aliyun.com/doc/tt.html

monitor方法执行时间

通过浏览器连接arthas

Arthas目前支持Web Console,用户在attach成功之后,可以直接访问:http://127.0.0.1:3658/

可以填入IP,远程连接其它机器上的arthas。

_images/web-console-local.png

默认情况下,arthas只listen 127.0.0.1,所以如果想从远程连接,则可以使用 --target-ip参数指定listen的IP,更多参考-h的帮助说明。 注意会有安全风险,考虑下面的tunnel server的方案。

猜你喜欢

转载自blog.csdn.net/boonya/article/details/114314081