日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Alibaba Arthas快速入门 简单易懂

發布時間:2024/1/8 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Alibaba Arthas快速入门 简单易懂 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡介

Arthas 是一款線上監控診斷產品,通過全局視角實時查看應用 load、內存、gc、線程的狀態信息,并能在不修改應用代碼的情況下,對業務問題進行診斷,包括查看方法調用的出入參、異常,監測方法執行耗時,類加載信息等,大大提升線上問題排查效率。

#Arthas(阿爾薩斯)能為你做什么?

Arthas?是 Alibaba 開源的 Java 診斷工具,深受開發者喜愛。

當你遇到以下類似問題而束手無策時,Arthas可以幫助你解決:

  • 這個類從哪個 jar 包加載的?為什么會報各種類相關的 Exception?
  • 我改的代碼為什么沒有執行到?難道是我沒 commit?分支搞錯了?
  • 遇到問題無法在線上 debug,難道只能通過加日志再重新發布嗎?
  • 線上遇到某個用戶的數據處理有問題,但線上同樣無法 debug,線下無法重現!
  • 是否有一個全局視角來查看系統的運行狀況?
  • 有什么辦法可以監控到 JVM 的實時運行狀態?
  • 怎么快速定位應用的熱點,生成火焰圖?
  • 怎樣直接從 JVM 內查找某個類的實例?
  • Arthas?支持 JDK 6+,支持 Linux/Mac/Windows,采用命令行交互模式,同時提供豐富的?Tab?自動補全功能,進一步方便進行問題的定位和診斷。

    快速入門

    #1. 啟動 math-game

    curl -O https://arthas.aliyun.com/math-game.jar java -jar math-game.jar

    math-game是一個簡單的程序,每隔一秒生成一個隨機數,再執行質因數分解,并打印出分解結果。

    math-game源代碼:查看在新窗口打開

    #2. 啟動 arthas

    在命令行下面執行(使用和目標進程一致的用戶啟動,否則可能 attach 失敗):

    curl -O https://arthas.aliyun.com/arthas-boot.jar java -jar arthas-boot.jar
    • 執行該程序的用戶需要和目標進程具有相同的權限。比如以admin用戶來執行:sudo su admin && java -jar arthas-boot.jar?或?sudo -u admin -EH java -jar arthas-boot.jar。
    • 如果 attach 不上目標進程,可以查看~/logs/arthas/?目錄下的日志。
    • 如果下載速度比較慢,可以使用 aliyun 的鏡像:java -jar arthas-boot.jar --repo-mirror aliyun --use-http
    • java -jar arthas-boot.jar -h?打印更多參數信息。

    選擇應用 java 進程:

    $ $ java -jar arthas-boot.jar * [1]: 35542[2]: 71560 math-game.jar

    math-game進程是第 2 個,則輸入 2,再輸入回車/enter。Arthas 會 attach 到目標進程上,并輸出日志:

    [INFO] Try to attach process 71560 [INFO] Attach process 71560 success. [INFO] arthas-client connect 127.0.0.1 3658,---. ,------. ,--------.,--. ,--. ,---. ,---./ O \ | .--. ''--. .--'| '--' | / O \ ' .-' | .-. || '--'.' | | | .--. || .-. |`. `-. | | | || |\ \ | | | | | || | | |.-' | `--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'wiki: https://arthas.aliyun.com/doc version: 3.0.5.20181127201536 pid: 71560 time: 2018-11-28 19:16:24$

    #3. 查看 dashboard

    輸入dashboard,按回車/enter,會展示當前進程的信息,按ctrl+c可以中斷執行。

    $ dashboard ID NAME GROUP PRIORI STATE %CPU TIME INTERRU DAEMON 17 pool-2-thread-1 system 5 WAITIN 67 0:0 false false 27 Timer-for-arthas-dashb system 10 RUNNAB 32 0:0 false true 11 AsyncAppender-Worker-a system 9 WAITIN 0 0:0 false true 9 Attach Listener system 9 RUNNAB 0 0:0 false true 3 Finalizer system 8 WAITIN 0 0:0 false true 2 Reference Handler system 10 WAITIN 0 0:0 false true 4 Signal Dispatcher system 9 RUNNAB 0 0:0 false true 26 as-command-execute-dae system 10 TIMED_ 0 0:0 false true 13 job-timeout system 9 TIMED_ 0 0:0 false true 1 main main 5 TIMED_ 0 0:0 false false 14 nioEventLoopGroup-2-1 system 10 RUNNAB 0 0:0 false false 18 nioEventLoopGroup-2-2 system 10 RUNNAB 0 0:0 false false 23 nioEventLoopGroup-2-3 system 10 RUNNAB 0 0:0 false false 15 nioEventLoopGroup-3-1 system 10 RUNNAB 0 0:0 false false Memory used total max usage GC heap 32M 155M 1820M 1.77% gc.ps_scavenge.count 4 ps_eden_space 14M 65M 672M 2.21% gc.ps_scavenge.time(m 166 ps_survivor_space 4M 5M 5M s) ps_old_gen 12M 85M 1365M 0.91% gc.ps_marksweep.count 0 nonheap 20M 23M -1 gc.ps_marksweep.time( 0 code_cache 3M 5M 240M 1.32% ms) Runtime os.name Mac OS X os.version 10.13.4 java.version 1.8.0_162 java.home /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/jre

    #4. 通過 thread 命令來獲取到math-game進程的 Main Class

    thread 1會打印線程 ID 1 的棧,通常是 main 函數的線程。

    $ thread 1 | grep 'main('at demo.MathGame.main(MathGame.java:17)

    #5. 通過 jad 來反編譯 Main Class

    $ jad demo.MathGameClassLoader: +-sun.misc.Launcher$AppClassLoader@3d4eac69+-sun.misc.Launcher$ExtClassLoader@66350f69Location: /tmp/math-game.jar/** Decompiled with CFR 0_132.*/ package demo;import java.io.PrintStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Random; import java.util.concurrent.TimeUnit;public class MathGame {private static Random random = new Random();private int illegalArgumentCount = 0;public static void main(String[] args) throws InterruptedException {MathGame game = new MathGame();do {game.run();TimeUnit.SECONDS.sleep(1L);} while (true);}public void run() throws InterruptedException {try {int number = random.nextInt();List<Integer> primeFactors = this.primeFactors(number);MathGame.print(number, primeFactors);}catch (Exception e) {System.out.println(String.format("illegalArgumentCount:%3d, ", this.illegalArgumentCount) + e.getMessage());}}public static void print(int number, List<Integer> primeFactors) {StringBuffer sb = new StringBuffer("" + number + "=");Iterator<Integer> iterator = primeFactors.iterator();while (iterator.hasNext()) {int factor = iterator.next();sb.append(factor).append('*');}if (sb.charAt(sb.length() - 1) == '*') {sb.deleteCharAt(sb.length() - 1);}System.out.println(sb);}public List<Integer> primeFactors(int number) {if (number < 2) {++this.illegalArgumentCount;throw new IllegalArgumentException("number is: " + number + ", need >= 2");}ArrayList<Integer> result = new ArrayList<Integer>();int i = 2;while (i <= number) {if (number % i == 0) {result.add(i);number /= i;i = 2;continue;}++i;}return result;} }Affect(row-cnt:1) cost in 970 ms.

    #6. watch

    通過watch命令來查看demo.MathGame#primeFactors函數的返回值:

    $ watch demo.MathGame primeFactors returnObj Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 107 ms. ts=2018-11-28 19:22:30; [cost=1.715367ms] result=null ts=2018-11-28 19:22:31; [cost=0.185203ms] result=null ts=2018-11-28 19:22:32; [cost=19.012416ms] result=@ArrayList[@Integer[5],@Integer[47],@Integer[2675531], ] ts=2018-11-28 19:22:33; [cost=0.311395ms] result=@ArrayList[@Integer[2],@Integer[5],@Integer[317],@Integer[503],@Integer[887], ] ts=2018-11-28 19:22:34; [cost=10.136007ms] result=@ArrayList[@Integer[2],@Integer[2],@Integer[3],@Integer[3],@Integer[31],@Integer[717593], ] ts=2018-11-28 19:22:35; [cost=29.969732ms] result=@ArrayList[@Integer[5],@Integer[29],@Integer[7651739], ]

    更多的功能可以查看進階使用。

    #7. 退出 arthas

    如果只是退出當前的連接,可以用quit或者exit命令。Attach 到目標進程上的 arthas 還會繼續運行,端口會保持開放,下次連接時可以直接連接上。

    如果想完全退出 arthas,可以執行stop命令。

    官方文檔:快速入門 | arthas

    總結

    以上是生活随笔為你收集整理的Alibaba Arthas快速入门 简单易懂的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。