• arthars在线诊断


    官网地址:https://arthas.aliyun.com/doc/quick-start.html#_6-

    1.安装启动

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

    2.选择对应进程编号+回车在这里插入图片描述3.watch命令

    官网命令文档:https://arthas.aliyun.com/doc/arthas-tutorials.html?language=cn&id=command-watch
    作用:监控函数的输入、输出、异常等信息。
    watch 命令定义了 4 个观察事件点,即 -b 函数调用前,-e 函数异常后,-s 函数返回后,-f 函数结束后(默认开启)
    在 watch 命令的结果里,会打印出location信息。location有三种可能值:AtEnter,AtExit,AtExceptionExit。对应函数入口,函数正常 return,函数抛出异常。
    -x:指定输出结果的属性遍历深度
    -n:只执行多少次数
    -e表示抛出异常时才触发

    查看调用之前函数的结果以及函数调用之后的结果
     watch com.hqhp.jwt.utils.JwtUtil getFieldValue '{params,returnObj,throwExp}' -x 2
    
    • 1
    • 2

    在这里插入图片描述

    只有第一个参数小于0才会触发watch
    watch demo.MathGame primeFactors "{params,target,returnObj}" -x 2 -b -s -n 2
    
    • 1
    • 2
    查看响应异常信息
    watch demo.MathGame primeFactors "{params[0],throwExp}" -e -x 2
    
    • 1
    • 2
    对监控方法耗时进行过滤(200单位ms)
    watch demo.MathGame primeFactors '{params, returnObj}' '#cost>200' -x 2
    
    • 1
    • 2
    查看函数运行前后当前对象属性,也就是函数所在class包含属性内容
    watch demo.MathGame primeFactors 'target'
    
    • 1
    • 2
    触发指定方法后,调用当前对象的属性
    watch demo.MathGame primeFactors 'target.illegalArgumentCount'
    
    • 1
    • 2

    4.trace命令

    作用:能输出方法内部调用路径,并输出方法路径上的每个节点上耗时
    场景:当出现耗时方法时,可通过此命令查看调用的其他方法耗时时间
    捕捉到函数被调用了一次就退出监控

    监控指定函数调用链路及耗时
    trace com.hqhp.jwt.filter.JwtFilter isAccessAllowed
    
    • 1
    • 2
    捕捉到函数被调用了一次就退出监控
    trace com.hqhp.jwt.filter.JwtFilter isAccessAllowed -n 1
    
    • 1
    • 2
    输入调用JDK内部函数信息
    trace --skipJDKMethod false com.hqhp.jwt.filter.JwtFilter isAccessAllowed -n 1
    
    • 1
    • 2
    只会展示耗时大于 10ms 的调用路径,有助于在只关注异常情况
    trace com.hqhp.jwt.filter.JwtFilter isAccessAllowed '#cost > 10'
    
    • 1
    • 2
    trace 多个类或者多个函数
    trace -E com.test.ClassA|org.test.ClassB method1|method2|method3
    
    • 1
    • 2
    排除掉指定的类
    trace javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter
    
    • 1
    • 2

    5.ognl命令

    执行 ognl 表达式

    获取静态变量
    ognl '@demo.MathGame@random'
    
    • 1
    • 2
    从spring容器中获取class中的变量
    ognl '@com.zqh.bean.ApplicationUtil@getBean("classBean").str'
    
    • 1
    • 2
    动态修改非静态属性值
    ognl --classLoaderClass org.apache.catalina.loader.WebappClassLoader
     '#instence=@cn.com.maxtech.util.Maxtech@me.getBean("LedgerTimer"),
    #fieldObj=@cn.com.maxtech.jswyj.ledger.timer.LedgerTimer@class.getDeclaredField("isOpen"),
    #fieldObj.setAccessible(true),
    #fieldObj.set(#instence,true)'
    
    1、--classLoaderClass org.apache.catalina.loader.WebappClassLoader 指定classload为tomcat的webappClassLoader(因为我们的springboot项目使用的外置tomcat)
    2、#instence=@cn.com.maxtech.util.Maxtech@me.getBean("LedgerTimer") 从spring容器中拿到LedgerTimer类的实例放入一个变量instence中
    3、#fieldObj=@cn.com.maxtech.jswyj.ledger.timer.LedgerTimer@class.getDeclaredField("isOpen") 使用反射获取LedgerTimer类的isOpen字段对象放入fieldObj变量中
    4、#fieldObj.setAccessible(true)  由于isOpen字段没有设置public访问权限,所以需要执行此段代码放开访问权限
    5、#fieldObj.set(#instence,true)   修改字段值
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
  • 相关阅读:
    大理大理!
    distroless 镜像介绍及 基于cbl-mariner的.NET distroless 镜像的容器
    【云原生】Minio on k8s 讲解与实战操作
    虚拟运营商与实体运营商的apn匹配逻辑
    使用Gstreamer+OpenCV实现两路图像数据混合拉流推流
    canvas基础简单易懂教程(完结,多图)
    央媒发稿不能改?媒体发布新闻稿有哪些注意点
    【嵌入式】将PDF转成PNG
    一道前端面试题:验证回文子串
    Qt学习05 Qt Creator工程介绍
  • 原文地址:https://blog.csdn.net/qq_15076569/article/details/128145197