태그 : 자바, 문제 해결, 모니터, 아서스
한 문장으로 요약 :
Arthas
인 온라인 분석 및 진단 자바 응용 프로그램에 대한 알리바바 오픈 소스 자바 진단 도구는, 그것은, 자바 모니터링 도구의 마스터로 도입 될이 문서를 간주됩니다.
1 소개
온 기사 "자바 애플리케이션 모니터링 (7) - 라인 동적 진단 유물 BTrace는" 우리는 당신이 논스톱 서비스를 필요로하는 경우, 필요 동적 추적 기술을 사용하는 온라인 응용 프로그램을 모니터링, 언급 BTrace
, 좋은 동적 추적 도구이지만, 사용은 아직 조금 복잡 (스크립트를 작성해야합니다), 다음 간단한 도구, 즉 것을 더 이상 존재이며 Arthas
, 동적 추적 기술을 단순화하기 위해 오픈 소스 자바 알리 진단 도구이며, 그것으로, 당신이 직접 클래스 로딩 정보를 볼 수 있습니다 상기 방법의 구현을 추적 JVM 정보 스레드 스택 정보는 상기 자바 명령 행 도구 및 기능 덮는 등의 클래스 파일을 컴파일 BTrace
기능. 너무 많은 추가 작업, 단지 익숙하지 않고 Arthas
명령을 제공 할 수 있습니다, 그것은 편리합니다. 사실 Arthas
과 하단은 BTrace
, 기초 jvm Agent
사용 방식 Instrumentation
, 출력을 수정하여 실시 바이트 코드를 실행한다. 것이 문서 Arthas
공식 문서의 관점에서 소개 사용이 매우 상세한 기록 배우고 공식 문서로 직접 이동하는 것이 좋습니다되었습니다 만 토론을 시작 할 수 있습니다. 공식 웹 사이트 주소 :https://alibaba.github.io/arthas
2 아서스 설치 및 작동
2.1 다운로드 아서스
공식 추천 직접 다운로드 JAR 실행
wget https://alibaba.github.io/arthas/arthas-boot.jar
复制代码
2.2 아서스를 실행
다운로드 장소 arthas-boot.jar
당신이 함께 모니터로 포장 할 Java 응용 프로그램 서버 Spring Boot
에 직접 java 명령 실행 등의 응용 프로그램을.
java -jar arthas-boot.jar
复制代码
참고 :
- 당신이 처음 실행할 때, 당신은 느린 다운로드를 사용할 수 있습니다
--repo-mirror aliyun --use-http
- 시작 후에는 현재의 자바 응용 프로그램 목록 (같은 비트가 나열됩니다
jps -l
), 모니터링 할 응용 프로그램을 선택할 수있는 출력 번호를.
개시 후에 수행 Arthas
명령 라인 인터페이스가 사용될 수있다 Arthas
구비 필요한 감시 기능 명령을 달성했다. 이하, 자바 응용 프로그램을 모니터링 할 필요가 예시 java-monitor-example
.
2.3 종료
단지 현재 연결을 종료하면, 당신은 사용할 수 있습니다 quit
또는 exit
명령. 다음 번에 연결할 때, 직접 연결할 수있는 열린 포트로 유지됩니다, 대상 프로세스가 계속 실행됩니다 아서스을 연결합니다.
완전히 아서스를 철회하려는 경우, 당신은 실행할 수있는 shutdown
명령을.
3 아서스 사용
Arthas
사용하는 명령이 제공하는 기능을 사용하는 방법을 배우게 할 필요가있다, 주로 몇 가지 범주로 구분 :
- 기본
help
명령 :cat
,pwd
,history
,,quit
등, 거의 리눅스 명령. - JVM 관련 :
dashboard
,thread
,jvm
,sysenv
등, 주로 이전에 자바 명령 줄 도구를 배우고, JVM 정보를 모니터링하는jinfo
,jmap
,jstack
등 동일한 목적을 가지고있다. - 클래스 / 클래스 로더
sc
관련 :sm
,jad
,dump
,,classloader
등. - 관련 모니터 / 시계 / 추적 :
monitor
,watch
,trace
,stack
등이 피복 이러한 기능BTrace
구현되는 기능은 처리 변수를 검출하는 타이밍에, 리턴 값, 시간 등등과 통화를 포함한다.
다음은 몇 가지 일반적으로 사용되는 명령을 상세하게 설명 명령 목록을 것입니다 다음은 공식 문서를 참조하십시오.
3.1 개요 :dashboard
시작 Arthas
후 -h
도움을 사용하여보기 :
$ dashboard -h
USAGE:
dashboard [-b] [-h] [-i <value>] [-n <value>]
SUMMARY:
Overview of target jvm's thread, memory, gc, vm, tomcat info.
EXAMPLES:
dashboard
dashboard -n 10
dashboard -i 2000
复制代码
단일 인터페이스 등가 개요 보여 스레드 메모리 GC 상황 VM 톰캣 상황 정보. (도 공식 문서의 예) 다음과 같이 :
기본 오초에 대한 정보의 개요는 메모리 변경, 스레드 점유율, GC 주파수 한눈에, 새로 고칩니다. 사용 ctrl+c
종료.
3.2 스레드 정보 :thread
기억 jstack
을, 우리는 먼저, 스레드 ID를 식별 스레드 스택을 내보낼 사용하고 스레드 ID보기를 사용해야합니다. 에서 Arthas
훨씬 더 편리하고, 위처럼 dashboard
,이 있었다 ID, 직접 사용 thread id
할 수 있습니다. -h
우리의 도움말 문서 :
$ thread -h
USAGE:
thread [-h] [-b] [-i <value>] [-n <value>] [id]
SUMMARY:
Display thread info, thread stack
EXAMPLES:
thread
thread 51
thread -n -1
thread -n 5
thread -b
thread -i 2000
OPTIONS:
-h, --help this help
-b, --include-blocking-thread Find the thread who is holding a lock that blocks the most number of threads.
-i, --sample-interval <value> Specify the sampling interval (in ms) when calculating cpu usage.
-n, --top-n-threads <value> The number of thread(s) to show, ordered by cpu utilization, -1 to show all.
<id> Show thread stack
复制代码
위와 같이 EXAMPLES
, 사용 thread
명령을, 당신은 가장 높은 첫 번째 N 스레드가 CPU (점유 찾을 수 있습니다 -n
), 당신은 지정된 스레드 실행 스택 (인쇄 할 수있는 id
다른 스레드 (차단, 현재의 thread를 찾을를) -b
), 그래서 문제는 스레드를 분석하는 것입니다 편리합니다.
3.3 JVM 정보 :jvm
jvm
명령이 작동 매개 변수, 클래스 로딩 정보, 메모리, 시스템 정보, 같은 파일 기술자 등의 정보 스레드의 수를 포함하여 정보를 출력, 매개 변수 매우 간단합니다. 약간 좋아 jvisualvm
에 概述
있지만,보다 더 자세한.
3.4 디 컴파일 :jad
때로는 응용 프로그램은 라인의 실행, 그들이 사용 또는 최신의 소스 여부를 확인하기 위해 클래스를 디 컴파일로드 할 업데이트가있는 경우, 다음 여부를 새 코드 탐지 할 필요가 jad
유용합니다. -h
도움말을 사용하여 인쇄 :
$ jad -h
USAGE:
jad [-c <value>] [-h] [-E] [--source-only] class-pattern [method-name]
EXAMPLES:
jad java.lang.String
jad java.lang.String toString
jad --source-only java.lang.String
jad -c 39eb305e org/apache/log4j/Logger
jad -c 39eb305e -E org\\.apache\\.*\\.StringUtils
OPTIONS:
-c, --code <value> The hash code of the special class's classLoader
-h, --help this help
-E, --regex Enable regular expression to match (wildcard matching by default)
--source-only Output source code only
<class-pattern> Class name pattern, use either '.' or '/' as separator
<method-name> method name pattern, decompile a specific method instead of the whole class
复制代码
상술 한 바와 같이 EXAMPLES
,이 JAD (클래스를 컴파일 할 class-pattern
)하는 방법 (클래스 디 컴파일되는 method-name
복수 존재하는 경우) classLoader
도 사용될 수있다, -c
등을 표시하는 선택.
3.5 모니터링 실행 방법monitor
monitor
구현 호출의 수, 성공, 실패 횟수, 평균 시간, 고장율, 같은 비트를 포함하여, 모니터링 출력 방법을 초과 할 수 BTrace
있는 @Timer
, 그러나 더 편리. -h
보기 도움을 사용합니다 :
$ monitor -h
USAGE:
monitor [-c <value>] [-h] [-n <value>] [-E] class-pattern method-pattern
SUMMARY:
Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc.
Examples:
monitor org.apache.commons.lang.StringUtils isBlank
monitor org.apache.commons.lang.StringUtils isBlank -c 5
monitor -E org\.apache\.commons\.lang\.StringUtils isBlank
OPTIONS:
-c, --cycle <value> The monitor interval (in seconds), 60 seconds by default
-h, --help this help
-n, --limits <value> Threshold of execution times
-E, --regex Enable regular expression to match (wildcard matching by default)
<class-pattern> Path and classname of Pattern Matching
<method-pattern> Method of Pattern Matching
复制代码
상술 한 바와 같이 EXAMPLES
, 60 기본 수있는 모니터링 방법의 구현의 출력은 한 번이며, 사용 -c
시간 간격은 출력을 수정.
실적 데이터 모니터링 3.6있어서watch
유사 는 방법, 반환 값, 예외 정보의 매개 변수를 수행하려는 경우 온라인 응용 프로그램, 명령은 매우 적합합니다. 도움말 사용 :BTrace
@OnMethod
watch
-h
$ watch -h
USAGE:
watch [-b] [-e] [-x <value>] [-f] [-h] [-n <value>] [-E] [-M <value>] [-s] class-pattern method-pattern express [condition-express]
SUMMARY:
Display the input/output parameter, return object, and thrown exception of specified method invocation
The express may be one of the following expression (evaluated dynamically):
target : the object
clazz : the object's class
method : the constructor or method
params : the parameters array of method
params[0..n] : the element of parameters array
returnObj : the returned object of method
throwExp : the throw exception of method
isReturn : the method ended by return
isThrow : the method ended by throwing exception
#cost : the execution time in ms of method invocation
Examples:
watch -b org.apache.commons.lang.StringUtils isBlank params
watch -f org.apache.commons.lang.StringUtils isBlank returnObj
watch org.apache.commons.lang.StringUtils isBlank '{params, target, returnObj}' -x 2
watch -bf *StringUtils isBlank params
watch *StringUtils isBlank params[0]
watch *StringUtils isBlank params[0] params[0].length==1
watch *StringUtils isBlank params '#cost>100'
watch -E -b org\.apache\.commons\.lang\.StringUtils isBlank params[0]
OPTIONS:
-b, --before Watch before invocation
-e, --exception Watch after throw exception
-x, --expand <value> Expand level of object (1 by default)
-f, --finish Watch after invocation, enable by default
-h, --help this help
-n, --limits <value> Threshold of execution times
-E, --regex Enable regular expression to match (wildcard matching by default)
-M, --sizeLimit <value> Upper size limit in bytes for the result (10 * 1024 * 1024 by default)
-s, --success Watch after successful invocation
<class-pattern> The full qualified class name you want to watch
<method-pattern> The method name you want to watch
<express> the content you want to watch, written by ognl.
Examples:
params
params[0]
'params[0]+params[1]'
'{params[0], target, returnObj}'
returnObj
throwExp
target
clazz
method
复制代码
상술 한 바와 같이 EXAMPLES
, 상기 방법의 구현의 감시 타이밍 (앞이다 -b
)에있어서 실행 종료한다 ( -f
기본값) 방법이 성공 ( -s
). 모니터링을 포함하는 파라미터 ( params
), 리턴 값 ( returnObj
비정상), ( throwExp
) 등을 포함한다.
4 요약
Arthas
자바 응용 프로그램의 포괄적 인 모니터링을 수행 할 수있는 강력한 기능, 용지가 비교적 간단하다, 좋은 도우미 온라인 애플리케이션 모니터링입니다 Arthas
설치 및 수행 항목 회담를 사용하여 시작, 우리가 할 수있는 희망 Arthas
이었다 더 학습에 대한 공식 웹 사이트 자바 기술의 자신의 모니터링이 더 단단한 있도록 그것은, 상세한 설명과 각 명령의 예를 가지고있다.
데이터 시트
Arthas
공식 웹 사이트 :https://alibaba.github.io/arthas/