Arthas 3.1.2 版本发布 | 增加 logger/heapdump/vmoption 命令
最近偶爾有用戶反饋某些 HTTP 接口出現超時問題,而 web 服務端的 Trace 監控沒有出現 http 返回值為 503 等異常情況。出現這種情況一般是web容器出現問題,客戶端連
Arthas是Alibaba開源的Java診斷工具,深受開發者喜愛。
Github:https://github.com/alibaba/arthas
文檔:https://alibaba.github.io/arthas
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 為例:
<?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 命令打印的結果是:
[arthas@2062]$ loggername ROOTclass ch.qos.logback.classic.LoggerclassLoader sun.misc.Launcher$AppClassLoader@2a139a55classLoaderHash 2a139a55level INFOeffectiveLevel INFOadditivity truecodeSource file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jarappenders name CONSOLEclass ch.qos.logback.core.ConsoleAppenderclassLoader sun.misc.Launcher$AppClassLoader@2a139a55classLoaderHash 2a139a55target System.outname APPLICATIONclass ch.qos.logback.core.rolling.RollingFileAppenderclassLoader sun.misc.Launcher$AppClassLoader@2a139a55classLoaderHash 2a139a55file app.logname ASYNCclass ch.qos.logback.classic.AsyncAppenderclassLoader sun.misc.Launcher$AppClassLoader@2a139a55classLoaderHash 2a139a55appenderRef [APPLICATION]從appenders的信息里,可以看到
- CONSOLE logger的target是System.out
- APPLICATION logger是RollingFileAppender,它的file是app.log
- ASYNC它的appenderRef是APPLICATION,即異步輸出到文件里
查看指定名字的logger信息
[arthas@2062]$ logger -n org.springframework.webname org.springframework.webclass ch.qos.logback.classic.LoggerclassLoader sun.misc.Launcher$AppClassLoader@2a139a55classLoaderHash 2a139a55level nulleffectiveLevel INFOadditivity truecodeSource 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功能。
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 createdvmoption命令
查看,更新VM診斷相關的參數
- https://alibaba.github.io/arthas/vmoption.html
查看所有的option
[arthas@56963]$ vmoptionKEY VALUE ORIGIN WRITEABLE ---------------------------------------------------------------------------------------------HeapDumpBeforeFullGC false DEFAULT trueHeapDumpAfterFullGC false DEFAULT trueHeapDumpOnOutOfMemory false DEFAULT trueErrorHeapDumpPath DEFAULT trueCMSAbortablePrecleanW 100 DEFAULT trueaitMillisCMSWaitDuration 2000 DEFAULT trueCMSTriggerInterval -1 DEFAULT truePrintGC false DEFAULT truePrintGCDetails true MANAGEMENT truePrintGCDateStamps false DEFAULT truePrintGCTimeStamps false DEFAULT truePrintGCID false DEFAULT truePrintClassHistogramBe false DEFAULT trueforeFullGCPrintClassHistogramAf false DEFAULT trueterFullGCPrintClassHistogram false DEFAULT trueMinHeapFreeRatio 0 DEFAULT trueMaxHeapFreeRatio 100 DEFAULT truePrintConcurrentLocks false DEFAULT true查看指定的option
[arthas@56963]$ vmoption PrintGCDetailsKEY VALUE ORIGIN WRITEABLE ---------------------------------------------------------------------------------------------PrintGCDetails false MANAGEMENT true更新指定的option
[arthas@56963]$ vmoption PrintGCDetails true Successfully updated the vm option. PrintGCDetails=truestop命令
之前有用戶吐槽,不小心退出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'目前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]$ sessionName Value -----------------------------------------------------JAVA_PID 86183SESSION_ID f7273eb5-e7b0-4a00-bc5b-3fe55d741882AGENT_ID URJZ5L48RPBR2ALI5K4VTUNNEL_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 agenthttps://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,方便統一管控。
原文鏈接
本文為云棲社區原創內容,未經允許不得轉載。
總結
以上是生活随笔為你收集整理的Arthas 3.1.2 版本发布 | 增加 logger/heapdump/vmoption 命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 当60亿次攻击来袭,人机联合打了一场漂亮
- 下一篇: 同学,要不要来挑战双11零点流量洪峰?