Arthas is an open source Java diagnostic tool for Alibaba and is loved by developers.
Arthas 3.1.2 continues to add new features, highlighted below:
- logger/heapdump/vmoption/stop command
- Connect arthas from different networks via tunnel server for easy unified control
- Continuous usability improvement: prompt changed to arthas@pid form, support ctrl + k screen cleanup shortcut
logger/heapdump/vmoption/stop command
logger command
View logger information, update logger level
View all logger information
The following logback.xml is an example:
<?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>
The result printed using the logger command is:
[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]
From appenders'information, you can see
- The target of CONSOLE logger is System.out
- APPLICATION logger is RollingFileAppender, and its file is app.log
- ASYNC its appenderRef is APPLICATION, i.e. output asynchronously to a file
View logger information for the specified name
[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
Update logger level
[arthas@2062]$ logger --name ROOT --level debug update logger level success.
heapdump command
dump java heap, similar to the heap dump function of the jmap command.
dump to specified file
[arthas@58205]$ heapdump /tmp/dump.hprof Dumping heap to /tmp/dump.hprof... Heap dump file created
dump live object only
[arthas@58205]$ heapdump --live /tmp/dump.hprof Dumping heap to /tmp/dump.hprof... Heap dump file created
vmoption command
View, update parameters related to VM diagnostics
View all option s
[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
View the specified option
[arthas@56963]$ vmoption PrintGCDetails KEY VALUE ORIGIN WRITEABLE --------------------------------------------------------------------------------------------- PrintGCDetails false MANAGEMENT true
Update the specified option
[arthas@56963]$ vmoption PrintGCDetails true Successfully updated the vm option. PrintGCDetails=true
stop command
Previously, when a user threw a slot and accidentally exited Arthas console, shutdown would shut down the system, so the stop command was added to exit arthas with the same function as the shutdown command.
Connect arthas from different networks through tunnel server
In the new version, the function of arthas tunnel server has been added. Users can easily connect Arthas agents in different networks through tunnel server, which is suitable for unified control.
Connect to tunnel server when arthas starts
When arthas is started, the--tunnel-server parameter can be passed, for example:
as.sh --tunnel-server 'ws://47.75.156.201:7777/ws'
Currently 47.75.156.201 is a test server and users can set up their own arthas tunnel server
- If you have special requirements, you can specify the agentId in the --agent-id parameter.By default, a random ID is generated.
Once the attach succeeds, the agentId is printed, for example:
,---. ,------. ,--------.,--. ,--. ,---. ,---. / 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
If you are not connected to the tunnel server at startup, you can also obtain the agentId from the session command after a subsequent automatic reconnection is successful:
[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
For example, access it in a browser http://47.75.156.201:8080/ , enter agentId, and you can connect to arthas on your computer.
How Arthas tunnel server works
browser <-> arthas tunnel server <-> arthas tunnel client <-> arthas agent
https://github.com/alibaba/arthas/blob/master/tunnel-server/README.md
Continuous usability improvement
-
The prompt is modified to be arthas@pid so that the user can determine the current process ID and avoid misoperation by multiple processes
[arthas@86183]$ help
-
Add ctrl + k screen-clearing shortcut
summary
In summary, version 3.1.2 of Arthas adds logger/heapdump/vmoption/stop commands and tunnel server for unified control.There are also bug fixes to refer to
- Release Note: https://github.com/alibaba/arthas/releases/tag/3.1.2
Finally, Arthas's online tutorial is considering reorganizing, and we welcome your participation and suggestions:
Public Number
Welcome to the column on Hengyungduanling, focusing on Java, Spring Boot, Arthas, Dubbo.