Arthas

Arthas 是一款Java应用诊断利器,官方地址为:https://arthas.gitee.io/

启动:

# 指定端口启动
./as.sh --telnet-port 9998

监测方法的耗时:

# 监测单个方法执行时间
trace com.rhdk.contractservice.contract.service.AbstractContractService doHibernateValidate -n 10

# 监测多个方法执行时间
trace -n 10 -E com.rhdk.contractservice.contract.service.AbstractContractService|com.rhdk.contractservice.contract.service.impl.PurchaseBusinessService update
trace -n 10 -E com.rhdk.contractservice.contract.service.AbstractContractService|com.rhdk.contractservice.contract.service.impl.PurchaseBusinessService|com.rhdk.contractservice.feign.RemoteUserFeignResolver doUpdateContract|getOrgName 

# 监测不跳过jdk的方法
trace --skipJDKMethod false demo.MathGame run

# 监测大于10ms的方法
trace demo.MathGame run '#cost > 10'

# 监测排除指定的类
trace javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter

jprofiler 火焰图生成:

profiler start
profiler status
profiler stop --format html

配置nginx访问火焰图:

location /arthas {
    #arthas 生成资源路径
    proxy_pass http://127.0.0.1:3658/arthas-output;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

使用watch命令监控方法出入参:

# 监控DemoService的getUser方法 的 入参与出参
# -x 3 表示输出对象遍历深度为3,用于输出对象中含有对象的属性
watch com.demo.service.DemoService getUser '{params,returnObj}' -x 3

监控有参数的methodName方法的入参、返回值、异常信息:

watch packagename.ClassName methodName '{params,returnObj,throwExp}' -n 5 -x 3 'params.length >0'
watch packagename.ClassName methodName '{params,returnObj,throwExp}' -n 5 -x 3 'params.length >0 && params[0] instanceof java.lang.Integer'

watch com.spicrhdk.jupiter.auth.biz.service.impl.serviceutil.AppOrgTypeService checkOrgTypeIsInner '{params,returnObj,throwExp}' -n 5 -x 3 'params.length >0 && params[0] instanceof java.lang.Integer && params[1] instanceof java.lang.String'

最后更新于