Arthas使用说明

Arthas 是Alibaba开源的Java诊断工具。可使用范围:

  1. 某一个接口返回值错误,需要打日志埋点时,可直接通过arthas查看入参和出参;
  2. 某一个接口耗时严重,需排查对应的耗时操作;
  3. 确定某一个接口的调用路径;
  4. jvm监控;
  5. 确定某一个接口的可靠性;
  6. 确定现场代码内容,可进行反编译代码;
  7. 动态替换某一个类

使用

将arthas包复制到服务器;
查找对应java服务的进程号;

[root@host-10-19-141-49 test]# lsof -i:8041
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Jsvc 60164 root 398u IPv4 2662812937 0t0 TCP *:8041 (LISTEN)

Arthas 命令使用

help确认命令;

$
help
NAME DESCRIPTION
help Display Arthas Help
keymap Display all the available keymap for the specified connection.
sc Search all the classes loaded by JVM
sm Search the method of classes loaded by JVMclassloader Show classloader info
jad Decompile class
getstatic Show the static field of a class
monitor Monitor method execution statistics, e.g. total/success/failure count,
average rt, fail rate, etc.
stack Display the stack trace for the specified class and method
thread Display thread info, thread stack
trace Trace the execution time of specified method invocation.
watch Display the input/output parameter, return object, and thrown exception
of specified method invocation
tt Time Tunnel
jvm Display the target JVM information
ognl Execute ognl expression.
mc Memory compiler, compiles java files into bytecode and class files in
memory.
redefine Redefine classes. @see
Instrumentation#redefineClasses(ClassDefinition...)
dashboard Overview of target jvm's thread, memory, gc, vm, tomcat info.
dump Dump class byte array from JVM
options View and change various Arthas options
cls Clear the screen使用案例说明
查找某一个接口的耗时情况
reset Reset all the enhanced classes
version Display Arthas version
shutdown Shutdown Arthas server and exit the console
session Display current session information
sysprop Display, and change the system properties.
sysenv Display the system env.
history Display command history
cat Concatenate and print files

trace查找某一个接口的耗时情况

trace
com.weining.ga.xalarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace

$ trace
com.weining.ga.xalarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo
Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 213 ms.
`---ts=2019-08-19 19:53:16;thread_name=XNIO-2 task-
101;id=e6;is_daemon=false;priority=5;TCCL=org.springframework.boot.loader.LaunchedURLC
lassLoader@55183b20
`---[4886.503487ms]
com.weining.ga.xalarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl:saveDeployFaceDetailInfo()
+---[4884.877971ms]
com.weining.ga.xalarm.acs.modules.deploy.service.DeployFaceService:saveDeployFaceDet
ailInfoRemote() #100
`---[0.018793ms] com.weining.ga.common.BaseResult:isSuccess() #104
`---ts=2019-08-19 19:55:35;thread_name=XNIO-2 task-
119;id=fa;is_daemon=false;priority=5;TCCL=org.springframework.boot.loader.LaunchedURLC
lassLoader@55183b20
`---[504.840996ms]
com.weining.ga.xalarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl:saveDeployFaceDetailInfo()
+---[504.602987ms]
com.weining.ga.xalarm.acs.modules.deploy.service.DeployFaceService:saveDeployFaceDet
ailInfoRemote() #100
`---[0.007976ms] com.weining.ga.common.BaseResult:isSuccess() #104

watch 查找某一个接口的返回值/传入参数

$ watch
com.weile.ga.xalarm.acs.modules.provider.clarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo returnObj
Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 110 ms.
ts=2019-08-19 19:58:13; [cost=421.794194ms] result=@BaseResult[
serialVersionUID=@Long[6803323956728517039],
SUCCESS_TYPE=@Integer[0],
ERROR_TYPE=@Integer[-1],
FAIL_TYPE=@Integer[-2],
NO_AUTH_TYPE=@Integer[-3],
type=@Integer[0],
code=null,
msg=null,
data=@String[115892589],
] $
watch
com.weile.ga.xalarm.acs.modules.provider.clarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo params
Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 96 ms.
ts=2019-08-19 19:59:28; [cost=360.739998ms] result=@Object[][查看方法的调用路径
@DeployFaceDTO[DeployFaceDTO(faceDeployType=1, endpointType=1, faceSubType=1,
namelist=[1565852642843], namelistId=1565852642843, namelistName=test2,
deployScope=null, deployScopeName=null, threshold=0.8-1-00:00-23:59,
whiteListThreshold=, idCard=null, realName=null, registerGender=null, bornTime=null,
certificateType=null, certificateNumber=null, selectedCapabilityZero=null,
picUrl=null, imageData=null, humanId=null, ruleNumber=null, taskId=null,
isScopehanded=true, singleNamelistCreated=0, oneKeyDeploy=false)],
]

stack 查看方法的调用路径

stack
com.clarm.ga.xalarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo
Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 147 ms.
ts=2019-08-20 09:14:29;thread_name=XNIO-2 task-
125;id=101;is_daemon=false;priority=5;TCCL=org.springframework.boot.loader.LaunchedURL
ClassLoader@55183b20
@com.hikvision.ga.xalarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFac
eXRestServiceImpl.saveDeployFaceDetailInfo()
at
sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
at
org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.jav
a:294)
at
org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:248)
at
org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:235)
at
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)
at
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:209)
at
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletCo
ntainerDispatcher.java:227)
at
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDis
patcher.java:56)
at
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDis
patcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)at
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java
:129)
at
org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(Ap
plicationContextHeaderFilter.java:55)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java
:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java
:131)
at
org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebReque
stTraceFilter.java:111)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java
:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java
:131)
at
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFil
ter.java:99)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java
:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java
:131)
at
org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormCo
ntentFilter.java:109)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java
:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java
:131)
at
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMetho
dFilter.java:93)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java
:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java
:131)
at
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncod
ingFilter.java:197)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java
:107)

monitor统计每个接口的运行情况

monitor -c 5
com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace

$ monitor -c 5
com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo
Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 156 ms.
timestamp class
method total success fail
avg-rt(ms) fail-rate
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
------------------------
2019-08-20 09:18:13
com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo 1 1 0 9.01 0.00%
timestamp class
method total success fail
avg-rt(ms) fail-rate
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
------------------------
2019-08-20 09:18:18
com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo 1 1 0 2.81 0.00%
timestamp class
method total success fail
avg-rt(ms) fail-rate
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
------------------------
2019-08-20 09:18:23
com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo 0 0 0 0.00 0.00%
timestamp class
method total success fail
avg-rt(ms) fail-rate
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
------------------------
2019-08-20 09:18:28
com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFace
XRestServiceImpl saveDeployFaceDetailInfo 1 1 0 2.54 0.00%

jad反编译具体类

jad com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFaceXRestServiceImpl

jad com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl.DeployFaceXRestServiceImpl
ClassLoader:
+-sun.misc.Launcher$AppClassLoader@c387f44
+-sun.misc.Launcher$ExtClassLoader@56de6d6b
Location:
/opt/opsmgr/web/components/alarm.1/bin/alarm-acs/lib/alarm-acs-provider-
1.1.1000.RELEASE.jar
/*
* Decompiled with CFR 0_132.
*/
package com.clarm.ga.alarm.acs.modules.provider.balarm.api.deploy.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.clarm.ga.common.BasePage;
import com.clarm.ga.common.BaseResult;
import com.clarm.ga.common.BusinessException;
import com.clarm.ga.logger.build.HikGaLoggerFactory;
import com.clarm.ga.logger.log.HikGaLogger;
import com.clarm.ga.alarm.acs.balarm.api.deploy.dto.DeployFaceDTO;
import com.clarm.ga.alarm.acs.balarm.api.deploy.dto.DeployFaceForm;
import com.clarm.ga.alarm.acs.balarm.api.deploy.dto.ResourceDto;
import com.clarm.ga.alarm.acs.balarm.api.deploy.mapper.entity.DeployFace;
import com.clarm.ga.alarm.acs.balarm.api.deploy.query.dto.CondiFaceLibDTO;
import com.clarm.ga.alarm.acs.balarm.api.deploy.res.dto.DynTreeNode;
import com.clarm.ga.alarm.acs.balarm.api.deploy.res.dto.FaceScopeCheck;
import com.clarm.ga.alarm.acs.balarm.api.deploy.res.dto.Result4FaceLibDTO;
import com.clarm.ga.alarm.acs.balarm.api.deploy.res.dto.TreeNodeParams;
import com.clarm.ga.alarm.acs.balarm.api.deploy.service.DeployFaceXRestService;
import com.clarm.ga.alarm.acs.modules.deploy.service.DeployFaceBackIacService;
import com.clarm.ga.alarm.acs.modules.deploy.service.DeployFaceService;
import com.clarm.ga.alarm.acs.modules.deploy.service.DeployFaceSuperBrainService;
import com.clarm.ga.alarm.acs.modules.deploy.service.DeployService;

dashboard查看整体线程/内存情况

dashboard

你可能感兴趣的:(java基础,linux,jvm)