java application monitoring (8) - Ali diagnostic tools arthas

tags: java, troubleshooting, monitor,arthas


Summarized in one sentence: Arthasis Alibaba open-source Java diagnostic tools for online analysis and diagnosis java application, it is regarded as a master of java monitoring tool, this article it will be introduced.

1 Introduction

An article on the "java application monitoring (7) - line dynamic diagnostic artifacts BTrace" we mentioned, to monitor the application online at if you need non-stop service, the need to use dynamic tracking technology, BTraceis a good dynamic tracking tools, but use is still a bit complicated (need to write script), then there is no more that a simple tool, that is Arthas, and it is open-source Java Ali diagnostic tools to simplify the dynamic tracking technology, and with it, you can view the class loading information directly , JVM information, thread stack information, tracking the implementation of the method, decompile class file, etc., covering the aforementioned java command-line tools and functionality BTracefeatures. Without too much extra work, just the familiar Arthascommands can be provided, it is convenient. In fact, Arthasthe bottom with BTrace, is based jvm Agentmanner using Instrumentationmodify and execute bytecode embodiment, output. This article will Arthasuse are introduced, in view of the official documents have been written very detailed, suggest that you go directly to the official documentation to learn, it can only make start a discussion. Official website address :https://alibaba.github.io/arthas

2 Arthas installation and operation

2.1 download Arthas

Official recommended direct download jar run

wget https://alibaba.github.io/arthas/arthas-boot.jar
复制代码

2.2 running Arthas

Place the downloaded arthas-boot.jarjava application server where you want to pack into the monitor, with the Spring Bootapplication directly like the java command run.

java -jar arthas-boot.jar
复制代码

note:

  • The first time you run, you can use slow download--repo-mirror aliyun --use-http
  • After the start, it will list the current java application list (a bit like jps -l), the output number to select the application you want to monitor.

Carried out after the start Arthascommand line interface can be used Arthasto achieve the required monitoring function commands provided. Below, the need to monitor the java application is exemplary java-monitor-example.

arthas

2.3 Exit

If only exit the current connection, you can use quitor exitcommand. Attach to arthas the target process will continue to run, will remain open port, you can connect directly when connecting next time.

If you want to completely withdraw arthas, you can execute shutdownthe command.

3 Arthas use

ArthasThe command to use is the need to learn to use the functionality it provides, mainly divided into several categories:

  • Basic helpcommands: cat, pwd, history, , quitand so on, almost with linux commands.
  • jvm Related: dashboard, thread, jvm, sysenvand so on, mainly to monitor JVM information, learn java command-line tool with before jinfo, jmap, jstacketc. have the same purpose.
  • class / classloader scRelated: sm, jad, dump, , classloaderand so on.
  • monitor / watch / trace related: monitor, watch, trace, stacketc., these functions covering the BTracefunctions implemented, includes a timing detecting process parameters, return values, call duration and so on.

The following are a few commonly used commands will be described in detail a list of commands, please refer to the official documentation.

3.1 Overview:dashboard

Start Arthasafter -hviewing use the help:

$ 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

复制代码

Equivalent overview, show threads, memory, gc situation, vm tomcat circumstances and information in a single interface. As shown below (the example of FIG official document):

The overview of information about the default five seconds to refresh, to memory changes, threads occupancy, GC frequency glance. Use ctrl+cexit.

3.2 Thread information:thread

Remember jstackit, we need to first identify the thread ID, use it to export thread stack, and then use the thread ID view. In Arthasthe much more convenient, like the above dashboard, there have been ID, direct use thread idcan be. -hOur help documentation:

$ 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
复制代码

As shown above EXAMPLES, use the threadcommand, you can find the highest first N threads occupied the CPU ( -n), you can print the specified thread running stack ( id) to find out the current thread blocking other threads ( -b), so the problem is to analyze thread Convenience.

3.3 JVM information:jvm

jvmCommand is very simple, no parameters, it outputs information including operating parameters, class loading information, memory, the system information, the number of threads of information, such as file descriptors. A bit like jvisualvmin 概述, but more detailed than it.

3.4 decompile:jad

Sometimes applications need to detect the line running, the new code whether they have used or if there are updates to be loaded to decompile the class out to see whether the latest source, then jadis useful. -hPrint Using Help:

$ 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

复制代码

As shown above EXAMPLES, JAD can decompile class ( class-pattern), a method is decompiled class ( method-name), if there are multiple classLoader, may also be used -cto select which display the like.

3.5 Monitoring execution method:monitor

monitorImplementation can be timed output method of monitoring, including the number of calls, the number of successes, failures, the average length of time, failure rate, a bit like BTracein @Timer, but more convenient. -hView use the help:

$ 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
复制代码

As shown above EXAMPLES, the implementation of the monitoring method can default 60s is output once, and use -ctime interval to modify the output.

3.6 method of performing data monitoring:watch

Similar to BTracethe @OnMethodapplication on-line if you want to perform in the parameters of the method, the return value, exception information, watchthe command is very appropriate. -hUsing help:

$ 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

复制代码

As shown above EXAMPLES, the timing of monitoring the implementation of the method are front ( -b), the method execution ends ( -fdefault value) method is successful ( -s). Monitoring includes: a parameter ( params), the return value ( returnObj), abnormal ( throwExp) and the like.

4 Summary

ArthasPowerful features, which can be carried out comprehensive monitoring of java application, is a good helper online application monitoring, the paper is relatively simple to Arthasinstall and use the carrying out entry talks, initiate, hope that we can on Arthasthe official website for further learning, which has been It has detailed explanations and examples of each command, so that their monitoring of java technology is more solid.

Data sheet

  • ArthasOfficial website:https://alibaba.github.io/arthas/

Related Reading

Guess you like

Origin juejin.im/post/5d6a909af265da03bf0f5a23