Introduction background

Last Wednesday morning, I received alarm messages, reminding XXX server disk is full, please deal with it as soon as possible!

Without further explanation, I took out my computer and analyzed the server logs. I found that there were more than 13 million such log entries

msgWorker - thread-16- xxxMessageListener ... Specific content omittedCopy the code

Since these message logs were not printed in the previous log, I guess the log level was set incorrectly. In addition, this message is not printed in the project source code, but in the dependent JAR package, the problem is probably known, should be the log dependent JAR package conflict.

Because the system runs online, knowing which logging framework to use and which logging level to use in a particular class can be a problem! However, ali’s Arthas makes it easy for you to solve these online problems.

Troubleshooting Process

1. First, question the level and framework of logging

Logger --name xxx.xxx.xxx // Fully qualified name of the classCopy the code

2. Determine which dependent JAR packages logBack comes from

sc -d ch.qos.logback.classic.Logger
Copy the code

  1. One is that XXX-client has been upgraded recently. Check the version before the upgrade and find that there is no logback-classic dependency.
  2. The other is this messageListener JAR, and our POM file only excludes logback-core dependencies.

The corresponding solution is also very simple, the newly upgraded XXX-Clieng package, remove logback-core,logback-classic dependency; The original messageListener JAR package, add logback-classic exclusion, problem solving, the whole problem location process does not exceed 30 minutes.

Return to the chase

As a Java development engineer, I often encounter online problems. The difficulty of many online problems is to say that the runtime state of the program is not clear.

  1. The disk write full problem caused by a log JAR package conflict at the beginning of this article
  2. Program logic error, online system cannot debug
  3. Machine GC frequently, system runtime details

Arthas can help you solve online problems step by step.

Arthas profile

The installation

There are two main installation methods

##1. Arthas-boot.jar is the first approach
curl -O https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar

## Github access is slow, you can use domestic Gitee
curl -O https://arthas.gitee.io/arthas-boot.jar

##2. The second method is as.sh
curl -L https://alibaba.github.io/arthas/install.sh | sh
#You can configure the path to an environment variable by running it
./as.sh
Copy the code

After the installation is complete, attach it to a Java process and you can see the interface after it starts

Arthas functional classification summary

1. System running indicators

## This command is mainly used to output real-time system data, including threads, memory, etc., to quickly understand the system status
dashboard

#Jvmclass commands can help troubleshoot JVM-related problems
## 1. System environment variables
sysprop 
## 2. JVM environment variables
sysenv 
## 3. JVM parameters
vmoption 
Copy the code

2. Code-level functionality

2.1 Intercept a method and obtain its input parameter, output parameter and exception information

## params, returnObj, and throwExp represent input, output, and exception information, respectively. N,x indicate the number of intercepts and the depth of parameter display"{params, returnObj, throwExp}" -n 10 -x 5Copy the code

trace

Trace class full name method name -n 5## orStack class full name Method name -n 5Copy the code

The above two methods can solve the online running logic check, very practical!

3. Functions related to class loading

Sometimes we need to know which class loader is loading a class, or how we know the source code of dynamically generated classes, etc. Arthas has some functionality for class loading.

## sc (search class), you can find which classes are loaded by which packagesSc-d class full name## sm (search method), similar to the command above
## jad Java Class Decompile, a Java class decompile tool that works great for dynamically brokered classesJad --source-only The full name of the class @hashcode#You can even modify the source code of a class dynamically and then reload that class!Re-define re-load the.class file. Re-define re-load the.class fileCopy the code

Arthas also has fire diagrams and OGNL expressions that give you a better idea of what methods are hot in your application, as well as a more detailed look at deep Java objects. For those interested, check out arthas.

The IDEA of the plugin

Plug-in name: arthas – idea plug-in address: plugins.jetbrains.com/search?sear…

You can install it offline or directly by searching for arthas-idea in plug-ins within the IDE.

Well, this is the end of this article, I hope that Java backend engineers can try this productivity tool, encounter online problems do not panic, step by step to solve the problem!