Arthas 3.1.2 Release | Add logger/heapdump/vmoption command

Keywords: Linux github Java xml Session

Recently, users occasionally reported that some HTTP interfaces had timeout problems, while Trace monitoring on the web service side did not have any abnormal situations such as HTTP return value 503. This usually happens when the web container has a problem and the client connects to it.

Arthas is an open source Java diagnostic tool for Alibaba, which is popular with developers.
Github: https://github.com/alibaba/arthas
File: https://alibaba.github.io/arthas

Arthas 3.1.2 continues to add new features, which are highlighted below:

  • logger/heapdump/vmoption/stop command
  • Connect arthas of different networks through tunnel server to facilitate unified management and control
  • Continuous improvement in ease of use: prompt changed to arthas@pid form, supporting ctrl+k screen clearing shortcut keys

logger/heapdump/vmoption/stop command

logger command

View logger information and update logger level

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

View all logger information

Take the following logback.xml as 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 that

  • The target of CONSOLE logger is System.out.
  • APPLICATION logger is Rolling File Appender and its file is app.log
  • ASYNC's appenderRef is APPLICATION, which asynchronously outputs to files.

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 jmap command heap dump Function.

dump to the 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 and 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

Before user tucking out, after accidentally exiting Arthas console, shutdown will shut down the system, so the stop command is added to quit the arthas, and the function is consistent with the shutdown command.

arthas connecting different networks through tunnel server

In the new version, the function of arthas tunnel server is 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 is started

When arthas is started, the -- tunnel-server parameter can be passed, such as:

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

At present, 47.75.156.201 is a test server. Users can build their own arthas tunnel server.

If you have special requirements, you can specify agent Id in the -- agent-id parameter. By default, a random ID is generated.

When attach succeeds, the agent Id is printed, such as:

  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  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 it is not connected to the tunnel server at startup, it is also possible to obtain the agent Id through the session command after the subsequent automatic reconnection succeeds:

[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 to connect to arthas on the local machine.

Principle of Arthas tunnel server

browser <-> arthas tunnel server <-> arthas tunnel client <-> arthas agent

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

Continuous improvement in ease of use

The prompt is changed to arthas@pid format so that the user can determine the current process ID to avoid misoperation of multiple processes.

[arthas@86183]$ help

Add ctrl + k screen clearing shortcut key

summary

In short, version 3.1.2 of Arthas added logger/heapdump/vmoption/stop command and tunnel server to facilitate unified control. In addition, there are some bug fixes and so on, you can refer to them.

Release Note 
Finally, Arthas's online tutorials are being reorganized. You are welcome to participate and make suggestions for further details. Here.


Author: Brother Middleware

Read the original text

This article is the original content of Yunqi Community, which can not be reproduced without permission.

Posted by franklyn on Tue, 17 Sep 2019 22:20:10 -0700