歡迎您光臨本站 註冊首頁

Arthas 3.1.2 增加 logger/heapdump 命令,支持 tunnel server

←手機掃碼閱讀     admin @ 2019-09-09 , reply:0

Arthas

Arthas是Alibaba開源的Java診斷工具,Arthas 3.1.2版本持續增加新特性,下面重點介紹:

  • logger/heapdump/vmoption/stop命令

  • 通過tunnel server連接不同網路的arthas,方便統一管控

  • 易用性持續提升:提示符修改為 arthas@pid形式,支持 ctrl+k清屏快捷鍵

logger/heapdump/vmoption/stop命令

logger命令

查看logger信息,更新logger level

  • https://alibaba.github.io/arthas/logger.html

查看所有logger信息

以下面的 logback.xml為例:

app.logmylog-%d{yyyy-MM-dd}.%i.txt100MB602GB%logger{35} - %msg%n%-4relative [%thread] %-5level %logger{35} - %msg %nutf8

使用 logger命令列印的結果是:

[arthas@2062]$ logger
 name                                   ROOT
 class                                  ch.qos.logback.classic.Logger
 classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55
 classLoaderHash                        2a139a55
 level                                  INFO
 effectiveLevel                         INFO
 additivity                             true
 codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
 appenders                              name            CONSOLE
                                        class           ch.qos.logback.core.ConsoleAppender
                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55
                                        classLoaderHash 2a139a55
                                        target          System.out
                                        name            APPLICATION
                                        class           ch.qos.logback.core.rolling.RollingFileAppender
                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55
                                        classLoaderHash 2a139a55
                                        file            app.log
                                        name            ASYNC
                                        class           ch.qos.logback.classic.AsyncAppender
                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55
                                        classLoaderHash 2a139a55
                                        appenderRef     [APPLICATION]

appenders的信息里,可以看到

  • CONSOLE logger的target是 System.out

  • APPLICATION logger是 RollingFileAppender,它的file是 app.log

  • ASYNC它的 appenderRef是 APPLICATION,即非同步輸出到文件里

查看指定名字的logger信息

[arthas@2062]$ logger -n org.springframework.web
 name                                   org.springframework.web
 class                                  ch.qos.logback.classic.Logger
 classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55
 classLoaderHash                        2a139a55
 level                                  null
 effectiveLevel                         INFO
 additivity                             true
 codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar

更新logger level

[arthas@2062]$ logger --name ROOT --level debug
update logger level success.

heapdump命令

dump java heap, 類似jmap命令的heap dump功能。

  • https://alibaba.github.io/arthas/heapdump.html

dump到指定文件

[arthas@58205]$ heapdump /tmp/dump.hprof
Dumping heap to /tmp/dump.hprof...
Heap dump file created

只dump live對象

[arthas@58205]$ heapdump --live /tmp/dump.hprof
Dumping heap to /tmp/dump.hprof...
Heap dump file created

vmoption命令

查看,更新VM診斷相關的參數

  • https://alibaba.github.io/arthas/vmoption.html

查看所有的option

[arthas@56963]$ vmoption
 KEY                    VALUE                   ORIGIN                 WRITEABLE
---------------------------------------------------------------------------------------------
 HeapDumpBeforeFullGC   false                   DEFAULT                true
 HeapDumpAfterFullGC    false                   DEFAULT                true
 HeapDumpOnOutOfMemory  false                   DEFAULT                true
 Error
 HeapDumpPath                                   DEFAULT                true
 CMSAbortablePrecleanW  100                     DEFAULT                true
 aitMillis
 CMSWaitDuration        2000                    DEFAULT                true
 CMSTriggerInterval     -1                      DEFAULT                true
 PrintGC                false                   DEFAULT                true
 PrintGCDetails         true                    MANAGEMENT             true
 PrintGCDateStamps      false                   DEFAULT                true
 PrintGCTimeStamps      false                   DEFAULT                true
 PrintGCID              false                   DEFAULT                true
 PrintClassHistogramBe  false                   DEFAULT                true
 foreFullGC
 PrintClassHistogramAf  false                   DEFAULT                true
 terFullGC
 PrintClassHistogram    false                   DEFAULT                true
 MinHeapFreeRatio       0                       DEFAULT                true
 MaxHeapFreeRatio       100                     DEFAULT                true
 PrintConcurrentLocks   false                   DEFAULT                true

查看指定的option

[arthas@56963]$ vmoption PrintGCDetails
 KEY                    VALUE                   ORIGIN                 WRITEABLE
---------------------------------------------------------------------------------------------
 PrintGCDetails         false                   MANAGEMENT             true

更新指定的option

[arthas@56963]$ vmoption PrintGCDetails true
Successfully updated the vm option.
PrintGCDetails=true

stop命令

之前有用戶吐槽,不小心退出Arthas console之後, shutdown會關閉系統,因些增加了 stop命令來退出arthas,功能和 shutdown命令一致。

通過tunnel server連接不同網路的arthas

  • https://alibaba.github.io/arthas/web-console.html

在新版本里,增加了arthas tunnel server的功能,用戶可以通過tunnel server很方便連接不同網路里的arthas agent,適合做統一管控。

啟動arthas時連接到tunnel server

在啟動arthas,可以傳遞 --tunnel-server參數,比如:

as.sh --tunnel-server 'ws://47.75.156.201:7777/ws'
  1. as.sh --tunnel-server 'ws://47.75.156.201:7777/ws'

目前 47.75.156.201是一個測試伺服器,用戶可以自己搭建arthas tunnel server

  • 如果有特殊需求,可以通過 --agent-id參數里指定agentId。默認情況下,會生成隨機ID。

attach成功之後,會列印出agentId,比如:

  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'


wiki      https://alibaba.github.io/arthas
tutorials https://alibaba.github.io/arthas/arthas-tutorials
version   3.1.2
pid       86183
time      2019-08-30 15:40:53
id        URJZ5L48RPBR2ALI5K4V

如果是啟動時沒有連接到 tunnel server,也可以在後續自動重連成功之後,通過 session命令來獲取 agentId: 

[arthas@86183]$ session
 Name           Value
-----------------------------------------------------
 JAVA_PID       86183
 SESSION_ID     f7273eb5-e7b0-4a00-bc5b-3fe55d741882
 AGENT_ID       URJZ5L48RPBR2ALI5K4V
 TUNNEL_SERVER  ws://47.75.156.201:7777/ws

以上面的為例,在瀏覽器里訪問 http://47.75.156.201:8080/ ,輸入 agentId,就可以連接到本機上的arthas了。

Arthas tunnel server的工作原理 

browser  arthas tunnel server  arthas tunnel client  arthas agent

https://github.com/alibaba/arthas/blob/master/tunnel-server/README.md

易用性持續提升

  • 提示符修改為 arthas@pid形式,用戶可以確定當前進程ID,避免多個進程時誤操作

[arthas@86183]$ help
  • 增加 ctrl+k清屏快捷鍵

總結

總之, 3.1.2版本的Arthas新增加了 logger/heapdump/vmoption/stop命令,增加了tunnel server,方便統一管控。另外還有一些bug修復等,可以參考

  • Release Note: https://github.com/alibaba/arthas/releases/tag/3.1.2

最後,Arthas的在線教程考慮重新組織,歡迎大家參與,提出建議:

  • https://github.com/alibaba/arthas/issues/847


[admin ]

來源:OsChina
連結:https://www.oschina.net/news/109728/arthas-3-1-2-released
Arthas 3.1.2 增加 logger/heapdump 命令,支持 tunnel server已經有182次圍觀

http://coctec.com/news/soft/show-post-214179.html