Arthas

ReZero lol

下载启动

curl -L https://arthas.aliyun.com/install.sh | sh && ./as.sh

如何查看一个map里指定的key

getstatic com.bj58.bic.ep.rankreview.web.common.Constant MAP_EMP_INFO 'entrySet().iterator.{? #this.key=="userName"}'

坑: ognl '@com.envisioniot.enos.iot_log_sdk.core.ESClient@defaultESClient' 不生效

ognl命令默认只会去 SystemClassLoader 里找类。 getstatic 命令会直接找所有JVM里加载的类,而tomcat的classloader是自己的, 所以只有 getstatic 命令能找到。 ognl 命令要显式指定classloader 。

获取 context 的 classloader

getstatic com.bj58.bic.ep.rankreview.web.component.SpringContextConfig applicationContext

翻到最下面可以看到是 org.apache.catalina.loader.ParallelWebappClassLoader

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$ getstatic com.bj58.bic.ep.rankreview.web.component.SpringContextConfig applicationContext
field: applicationContext
@FileSystemXmlApplicationContext[
validating=@Boolean[true],
configLocations=@String[][isEmpty=false;size=1],
setIdCalled=@Boolean[false],
allowBeanDefinitionOverriding=null, allowCircularReferences=null,
beanFactory=@DefaultListableBeanFactory[org.springframework.beans.factory.support.DefaultListableBeanFactory@4b599b1a: defining beans [caffeineLocalCacheClient,initParams,operateLogAspect,appConfig,kmsClient,springContextConfig,wosClient,synEmployeeLocalCacheJob,judgeHRLeaderReviewsEmailServiceImpl,matchRuleTryCalcMatchServiceImpl,matchRuleTryCalcServiceImpl,ruleLimitCountMatchService,ruleLimitGroupMatchService,reviewsAllocService,AbstractReviewsAutoAllocP,AbstractReviewsAutoAllocT,agentServiceImpl,basicAttendSettingServiceImpl,basicConfigServiceImpl,basicJudgeGroupServiceImpl,constantValServiceImpl,contributionServiceImpl,departmentServiceImpl,directionAdminServiceImpl,emailNoticeTimingServiceImpl,evaluationJudgeServiceImpl,evaluationStatusServiceImpl,eventTriggerServiceImpl,finalResultServiceImpl,HRBPAuthServiceImpl,judgeGroupDirectionServiceImpl,judgeGroupMetaServiceImpl,judgePlacementServiceImpl,matchRuleServiceImpl,myTourServiceImpl,OAProcessServiceImpl,participantOperateServiceImpl,participantScheduleServiceImpl,plusParticipantServiceImpl,rankInfoServiceImpl,rankMetaServiceImpl,reportContentServiceImpl,reportReceiverServiceImpl,reportServiceImpl,reviewCalendarServiceImpl,reviewSessionHrServiceImpl,reviewsDirectionServiceImpl,reviewsEvaluateServiceImpl,reviewsJudgeManageServiceImpl,reviewsJudgeServiceImpl,reviewsJudgeStatementVersionServiceImpl,reviewsLessonServiceImpl,reviewsRuleServiceImpl,reviewsSessionAllocConfigServiceImpl,reviewsSessionCheckServiceImpl,reviewsSessionJudgeRelServiceImpl,reviewsSessionParticipantRelServiceImpl,reviewsSessionServiceImpl,reviewsSessionV2ServiceImpl,reviewsSessionWaiterServiceImpl,reviewsVersionServiceImpl,ruleDictServiceImpl,scoreBakServiceImpl,scoreCriteriaServiceImpl,scoreDescServiceImpl,sendEmailServiceImpl,siteMessageServiceImpl,staffEncryptDecryptServiceImpl,staffEvaluationServiceImpl,staffManageServiceimpl,staffStatisticsServiceImpl,staffStatusServiceImpl,syncInfoServiceImpl,sysPermissionServiceImpl,sysRolePermissionServiceImpl,sysRoleServiceImpl,sysUserRoleServiceImpl,userOccupiedBlockServiceImpl,userSiteMessageServiceImpl,valueObjectService,versionAuthRangeImpl,versionRuleServiceImpl,exportTemplate,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,org.springframework.context.annotation.internalAsyncAnnotationProcessor,org.springframework.context.annotation.internalScheduledAnnotationProcessor,placeholderConfigurer,beatContext,validator,bindAndValidate,org.springframework.aop.config.internalAutoProxyCreator,jedisPoolConfig,jedisPool,jedisHelper,org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration,org.springframework.transaction.config.internalTransactionAdvisor,transactionAttributeSource,transactionInterceptor,org.springframework.transaction.config.internalTransactionalEventListenerFactory,sqlSessionFactory,transactionManager,getDataSource,agentMapper,baseMapper,basicAttendSettingMapper,basicConfigJudgeGroupMapper,basicConfigJudgeParticipantMapper,basicConfigJudgeSchemaMapper,basicConfigOrgSubjectMapper,basicConfigReviewTimeMapper,basicConfigRoomMapper,basicConfigSpecialApplyMapper,contributionMapper,departmentMapper,directionAdminMapper,emailNoticeTimingMapper,evaluationJudgeMapper,evaluationStatusMapper,eventTriggerMapper,finalResultMapper,HRBPAuthMapper,judgeGroupDirectionMapper,judgeGroupMetaMapper,languageMapper,matchRuleGroupMapper,matchRuleMetaMapper,participantFlowMapper,participantMapper,plusParticipantMapper,rankInfoMapper,rankMetaMapper,rankReviewYearsRuleMapper,reportContentMapper,reportReceiverMapper,reviewCalendarMapper,reviewDirectionMapper,reviewRuleMapper,reviewSessionHrMapper,reviewsJudgeManageMapper,reviewsJudgeMapper,reviewsJudgeStatementVersionMapper,reviewsLessonMapper,reviewsSessionAllocConfigMapper,reviewsSessionJudgeRelMapper,reviewsSessionMapper,reviewsSessionParticipantRelMapper,reviewsVersionMapper,ruleDictMapper,scoreBakMapper,scoreDescriptionMapper,scoreElementMapper,siteMessageMapper,staffCountMapper,staffEvaluationMapper,staffStatisticsMapper,staffStatusMapper,syncInfoMapper,sysPermissionMapper,sysRoleMapper,sysRolePermissionMapper,sysUserRoleMapper,userOccupiedBlockMapper,userSiteMessageMapper,valueObjectMapper,versionAuthRangeMapper,versionRuleMapper,org.springframework.scheduling.annotation.SchedulingConfiguration]; root of factory hierarchy],
beanFactoryMonitor=@Object[java.lang.Object@2d19c93f],
MESSAGE_SOURCE_BEAN_NAME=@String[messageSource],
LIFECYCLE_PROCESSOR_BEAN_NAME=@String[lifecycleProcessor],
APPLICATION_EVENT_MULTICASTER_BEAN_NAME=@String[applicationEventMulticaster],
logger=@Log4JLogger[org.apache.commons.logging.impl.Log4JLogger@52743f1f],
id=@String[org.springframework.context.support.FileSystemXmlApplicationContext@48ed680],
displayName=@String[org.springframework.context.support.FileSystemXmlApplicationContext@48ed680],
parent=null,
environment=@StandardEnvironment[StandardEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[MapPropertySource {name='systemProperties'}, SystemEnvironmentPropertySource {name='systemEnvironment'}]}],
beanFactoryPostProcessors=@ArrayList[isEmpty=true;size=0],
startupDate=@Long[1636450003372],
active=@AtomicBoolean[true],
closed=@AtomicBoolean[false],
startupShutdownMonitor=@Object[java.lang.Object@4838b5cd],
shutdownHook=null,
resourcePatternResolver=@PathMatchingResourcePatternResolver[org.springframework.core.io.support.PathMatchingResourcePatternResolver@7adbd17c],
lifecycleProcessor=@DefaultLifecycleProcessor[org.springframework.context.support.DefaultLifecycleProcessor@19e8bf29],
messageSource=@DelegatingMessageSource[org.springframework.context.support.DelegatingMessageSource@6a97f7cc],
applicationEventMulticaster=@SimpleApplicationEventMulticaster[org.springframework.context.event.SimpleApplicationEventMulticaster@678ca18e],
applicationListeners=@LinkedHashSet[isEmpty=false;size=1],
earlyApplicationEvents=null,
classLoader=@ParallelWebappClassLoader[ParallelWebappClassLoader
context: ROOT
delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@5b2133b1
],
protocolResolvers=@LinkedHashSet[isEmpty=true;size=0],
resourceCaches=@ConcurrentHashMap[isEmpty=true;size=0],
]
Affect(row-cnt:1) cost in 9 ms.

调用context 执行方法

1
2
ognl '#context=@com.bj58.bic.ep.rankreview.web.component.SpringContextConfig@applicationContext,
#context.getBean(@com.bj58.bic.ep.rankreview.web.service.IParticipantOperateService@class).queryByOA(2021120612045375757L, "haoxiaofei")' --classLoaderClass org.apache.catalina.loader.ParallelWebappClassLoader

传复杂对象

构造器构造

1
ognl '#obj=new com.shirc.arthasexample.ognl.Shirc("jjdlmn",true),'

set 方法构造

1
2
3
4
ognl -x 3 '#obj=new com.bj58.bsp.v2.user.vo.LoginUserBaseInfo(), #obj.setUsername("rongjingjing"),
#springContext=@com.bj58.bic.ep.rankreview.web.component.SpringContextConfig@applicationContext,#springContext.getBean("staffManageServiceimpl")
.hrbpGetDpts(#obj)' --classLoaderClass org.apache.catalina.loader.ParallelWebappClassLoader

方法返回值作为参数

1
2
3
4
5
6
ognl -x 3 '#obj=new com.bj58.bsp.v2.user.vo.LoginUserBaseInfo(), #obj.setUsername("lvxiaoke"),
#springContext=@com.bj58.bic.ep.rankreview.web.component.SpringContextConfig@applicationContext,
#depts=#springContext.getBean("staffManageServiceimpl").hrbpGetDpts(#obj),
#insts=@com.bj58.bic.ep.rankreview.web.staffmanage.SMCacheUtil@getInstance(),
#insts.getAllUsersUnderOrgs(#depts)' --classLoaderClass org.apache.catalina.loader.ParallelWebappClassLoader

调用 集合投影 类似 stream().map(e -> e.dptId)

1
2
3
4
5
6
7
ognl -x 1 '#obj=new com.bj58.bsp.v2.user.vo.LoginUserBaseInfo(), #obj.setUsername("lvxiaoke"),
#springContext=@com.bj58.bic.ep.rankreview.web.component.SpringContextConfig@applicationContext,
#depts=#springContext.getBean("staffManageServiceimpl").hrbpGetDpts(#obj),
#deptids=#depts.{dptId},
#insts=@com.bj58.bic.ep.rankreview.web.staffmanage.SMCacheUtil@getInstance(),
#insts.getAllUsersUnderOrgs(#deptids)' --classLoaderClass org.apache.catalina.loader.ParallelWebappClassLoader

调用 静态方法

x 参数指定返回值的可见深度

1
ognl -x 3 '@com.bj58.bic.ep.rankreview.web.utils.BspHelper@getOrgByOrgId("201905291539077271da5c")'  --classLoaderClass   org.apache.catalina.loader.ParallelWebappClassLoader

监控方法调用 可加条件过滤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ watch com.bj58.bic.ep.rankreview.web.utils.BspHelper getOrgByOrgId '{params,returnObj,throwExp}' 'throwExp != null'  -n 5  -x 3 
2021-11-16 14:34:36; [cost=5.313401ms] result=@ArrayList[
@Object[][
@String[201706021923030c1a0853],
],
@Organization[
serialVersionUID=@Long[1],
id=@String[201706021923030c1a0853],
orgName=@String[华北一区直销部],
parentId=null,
status=@String[1],
description=@String[华北一区直销部(LongyuLi(李龙雨))],
creater=null,
city=@String[,1],
parentPath=null,
orderseq=null,
orgtype=null,
orglevel=null,
hrorgid=null,
issync=null,
lastUpdateTime=@Date[2021-05-14 12:31:56,000],
parentId201408=@String[201712052142005d9e2ab7],
parentPath201408=@String[2011010814223073b228a5,2014071618493421273d30,201712052142002cb3daad,201712052142005d9e2ab7,201706021923030c1a0853],
bizArea=null,
bizLine=null,
branchCode=@String[],
lockStatus=null,
wdOrgId=@String[WD_ORG_2177],
wdOrgPid=@String[WD_ORG_3492],
location=@String[北京-东升科技园-58],
orgSubtype=null,
managerIdList=null,
],
null,
]

cpu过高问题排查

https://github.com/alibaba/arthas/issues/1202

中文坑

找个网站,中文转unicode编码即可

  • Post title:Arthas
  • Post author:ReZero
  • Create time:2021-10-19 10:35:00
  • Post link:https://rezeros.github.io/2021/10/19/arthas/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments