Javaアプリケーションの監視(8) - アリ診断ツールのArthasは

タグ:javaの、トラブルシューティング、監視、Arthasは


:一つの文章にまとめArthasアリババオープンソースのJava診断ツールは、オンライン分析と診断javaアプリケーションのためである、それはJavaの監視ツールのマスターとみなされ、それが導入されますこの記事。

1はじめに

上の記事「Javaアプリケーションの監視(7) - BTraceがラインダイナミック診断アーティファクト」私たちは、あなたがノンストップサービスが必要な場合は、オンラインでアプリケーションを監視するために、動的トラッキング技術を使用する必要性に言及したBTrace良好な動的追跡ツールですが、使用はまだ少し複雑ではありません(スクリプトを記述する必要があります)、そしてシンプルなツール、それがあることをこれ以上ありArthas、そして動的トラッキング技術を簡素化するために、オープンソースのJavaアリ診断ツールであり、それを、あなたが直接クラスローディングの情報を表示することができます、JVM情報、スレッドスタック情報は、メソッドの実装を追跡する、前述のjavaコマンドラインツールと機能覆う、などクラスファイルをコンパイルBTrace機能を。あまりにも多くの余分な作業をせずに、単に使い慣れたArthasコマンドを提供することができ、それが便利です。実際には、Arthasと底部はBTrace、計算されjvm Agent使用方法をInstrumentation、出力を変更してバイトコードの実施例を実行します。この記事はなりますArthas使用公式文書の観点から、導入された、非常に詳細な書かれている、それだけで議論を開始することができ、あなたが学ぶために公式ドキュメントに直接移動することを示唆しています。公式ウェブサイトのアドレスhttps://alibaba.github.io/arthas

2 Arthasはインストールと操作

2.1ダウンロードArthasは

公式には直接ダウンロードジャーの実行をお勧めします

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

Arthasはを実行している2.2

ダウンロード置きarthas-boot.jar、あなたと、モニターにパックしたいJavaアプリケーションサーバSpring Bootのjavaコマンドの実行などのアプリケーションを直接。

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

注意:

  • あなたが最初に実行するときは、あなたが遅いのダウンロードを使用することができます--repo-mirror aliyun --use-http
  • スタート後は、現在のJavaアプリケーションリスト(ビットなどが一覧表示されますjps -l監視したいアプリケーションを選択し、出力数を)。

開始後に行うArthasコマンドラインインタフェースを使用することができますArthas提供に必要な監視機能のコマンドを達成するために。以下は、Javaアプリケーションを監視する必要は例示的なものですjava-monitor-example

Arthasは

2.3番出口

唯一の現在の接続を終了する場合は、使用することができますquitまたはexitコマンド。次回接続時に、あなたが直接接続することができます開いているポートをままになり、ターゲットプロセスを実行し続けますArthasはこれをつけます。

あなたは完全にArthasはを撤回したい場合は、実行できるshutdownコマンドを。

3 Arthasは使用

Arthas使用するコマンドは、主にいくつかのカテゴリに分けられ、それが提供する機能を使用することを学ぶ必要があるということです。

  • 基本的なhelpコマンド:catpwdhistory、、quitというように、ほとんどのLinuxコマンドで。
  • JVM関連:dashboardthreadjvmsysenvというように、主の前でのjavaコマンドラインツールを学び、JVMの情報を監視するためにjinfojmapjstackなど同じ目的を持っています。
  • クラス/クラスローダーsc関連:smjaddump、、classloaderなどなど。
  • モニタ/時計/トレースに関連する:monitorwatchtracestackなど、カバーこれらの機能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 Tomcatの状況や情報。(図の公式文書の一例)以下に示すように。

デフォルト5秒程度の情報の概要は、メモリの変更、スレッド占有、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、他のスレッドを(ブロッキング現在のスレッドを見つけるために)-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@OnMethodwatch-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まとめ

ArthasJavaアプリケーションの包括的なモニタリングを行うことができる強力な機能は、紙がするのは比較的簡単です、良いヘルパーのオンラインアプリケーション監視でArthasインストールして実行するエントリの交渉を使用し、開始し、私たちができることを願っArthasてきた更なる学習、公式ウェブサイトJava技術の彼らの監視がより強固になるように、それは、詳細な説明と、各コマンドの例を示しています。

データシート

  • Arthas公式サイト:https://alibaba.github.io/arthas/

関連読書

おすすめ

転載: juejin.im/post/5d6a909af265da03bf0f5a23