最近偶尔有用户反馈某些 HTTP 接口出现超时问题,而 web 服务端的 Trace 监控没有出现 http 返回值为 503 等异常状况。出现这种状况通常是web容器出现问题,客户端连html
Arthas是Alibaba开源的Java诊断工具,深受开发者喜好。
Github:https://github.com/alibaba/arthas
文档:https://alibaba.github.io/arthasjava
Arthas 3.1.2版本持续增长新特性,下面重点介绍:git
查看logger信息,更新logger levelgithub
https://alibaba.github.io/arthas/logger.htmlweb
如下面的 logback.xml 为例:spring
<?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]$ 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的信息里,能够看到服务器
查看指定名字的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
[arthas@2062]$ logger --name ROOT --level debug update logger level success.
dump java heap, 相似jmap命令的heap dump功能。session
[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命令一致。
在新版本里,增长了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
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
最后,Arthas的在线教程考虑从新组织,欢迎你们参与,提出建议,详情参考这里。
本文为云栖社区原创内容,未经容许不得转载。