Arthas
是Alibaba開源的Java診斷工具,深受開發者喜好。php
Arthas 3.1.2版本持續增長新特性,下面重點介紹:html
logger/heapdump/vmoption/stop
命令arthas@pid
形式,支持ctrl + k
清屏快捷鍵查看logger信息,更新logger leveljava
如下面的logback.xml
爲例:git
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="APPLICATION" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>60</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="APPLICATION" />
</appender>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n
</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="ASYNC" />
</root>
</configuration>
複製代碼
使用logger
命令打印的結果是:github
[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
的信息裏,能夠看到web
CONSOLE
logger的target是System.out
APPLICATION
logger是RollingFileAppender
,它的file是app.log
ASYNC
它的appenderRef
是APPLICATION
,即異步輸出到文件裏[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
複製代碼
[arthas@2062]$ logger --name ROOT --level debug
update logger level success.
複製代碼
dump java heap, 相似jmap命令的heap dump功能。spring
[arthas@58205]$ heapdump /tmp/dump.hprof
Dumping heap to /tmp/dump.hprof...
Heap dump file created
複製代碼
[arthas@58205]$ heapdump --live /tmp/dump.hprof
Dumping heap to /tmp/dump.hprof...
Heap dump file created
複製代碼
查看,更新VM診斷相關的參數瀏覽器
[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
複製代碼
[arthas@56963]$ vmoption PrintGCDetails
KEY VALUE ORIGIN WRITEABLE
---------------------------------------------------------------------------------------------
PrintGCDetails false MANAGEMENT true
複製代碼
[arthas@56963]$ vmoption PrintGCDetails true
Successfully updated the vm option.
PrintGCDetails=true
複製代碼
以前有用戶吐槽,不當心退出Arthas console以後,shutdown
會關閉系統,所以增長了stop
命令來退出arthas,功能和shutdown
命令一致。bash
在新版本里,增長了arthas tunnel server的功能,用戶能夠經過tunnel server很方便鏈接不一樣網絡裏的arthas agent,適合作統一管控。服務器
在啓動arthas,能夠傳遞--tunnel-server
參數,好比:
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了。
browser <-> arthas tunnel server <-> arthas tunnel client <-> arthas agent
複製代碼
提示符修改成arthas@pid
形式,用戶能夠肯定當前進程ID,避免多個進程時誤操做
[arthas@86183]$ help
複製代碼
增長ctrl + k
清屏快捷鍵
總之,3.1.2
版本的Arthas新增長了logger/heapdump/vmoption/stop
命令,增長了tunnel server,方便統一管控。另外還有一些bug修復等,能夠參考
最後,Arthas的在線教程考慮從新組織,歡迎你們參與,提出建議: