Don't worry about what to do when the online Java business goes wrong, Arthas
help you solve the following common problems:
- Which jar package is this class loaded from? Why are various class-related Exceptions reported?
- Why is the code I changed not executed? Is it because I didn't commit? Branch wrong?
- If you encounter a problem and cannot debug it online, can you only republish it by adding a log?
- There is a problem with the data processing of a user online, but it is also impossible to debug online, and it cannot be reproduced offline!
- Is there a global view to see the health of the system?
- Is there any way to monitor the real-time running status of the JVM?
- How to quickly locate the hot spots of the application and generate a flame graph?
- How to find an instance of a class directly from within the JVM?
Arthas (Alsace) is an online monitoring and diagnosis product, which can view the status information of application load, memory, gc and thread in real time through a global perspective, and can diagnose business problems without modifying the application code, including View the input and output parameters and exceptions of method calls, monitor method execution time, class loading information, etc., which greatly improves the efficiency of online troubleshooting.
Arthas adopts the command line interactive mode, and also provides rich Tab
auto-completion function, which further facilitates problem location and diagnosis.
At the same time, Arthas also supports entering command line interactive mode through Web Console, which is suitable for diagnosing business through Arthas Web Console when developers do not have server permissions.
Arthas integration on Rainbond
1. Plugin integration
Through the Rainbond plug-in mechanism, install the Arthas plug-in from the Rainbond open source application store with one click and activate it in the component. When the component starts, it will automatically download arthas-agent.jar
combined with the environment variable configuration and use javaagent
to start.
2. Arthas Tunnel Integration
When our microservice business has 10+, it will be more troublesome to diagnose through Arthas. If the developer does not have server permissions and accesses through the Web Console, it will be particularly confusing due to too many access addresses. At this time, it is necessary to remotely manage/connect multiple Agents through Arthas Tunnel Server/Client.
Arthas Agent will be registered in Arthas Tunnel through WS to realize unified management.
Arthas Tunnel is one-click installable from the Rainbond open source app store.
3. Arthas Web Console
For Spring Boot applications, there is no need to access the Web Console through Arthas Tunnel, and you can access the Web Console by adding port 8563 to the component. (Note: Domain name access needs to enable Websocket support
Diagnosing Spring Boot applications on Rainbond with Arthas
This section uses Ruoyi SpringBoot as an example.
First, you need to install the Rainbond cloud native application management platform, you can refer to the documentation to install Rainbond Allinone
1. Deploy the Spring Boot application
Team -> Add New -> Create Component Based on App Store -> Search in App Store 若依SpringBoot
for one-click deployment.
2. Install Arthas Java Agent plugin and configure
2.1 Install the plugin
Team -> Plugins -> Install Plugins from App Store -> Search in App Store Arthas-Agent
for one-click deployment.
2.2 Activating the plug-in
To activate Arthas Agent plugin for ruoyi-admin
, go to Component->Plugins->Not Activated->Activate Plugin.
2.3 Environment variable configuration
To configure environment variables for the ruoyi-admin
component, go to the component->environment variables->add variables.
variable name | variable |
---|---|
JAVA_OPTS | -javaagent:/arthas/arthas-agent.jar |
ARTHAS_APP_NAME | ruoyi-admin |
ARTHAS_AGENT_ID | ruoyi-admin |
2.4 Add port and update
Add port 8563 for the ruoyi-admin
component and open the external service. After updating the component, you can access the Web Console through the default domain name.
Diagnosing SpringCloud applications on Rainbond with Arthas
Use Arthas to diagnose the microservice Spring Cloud Pig deployed on Rainbond, and manage Arthas agent uniformly through Arthas Tunnel. This section will use Spring Cloud Pig as an example.
First, you need to install the Rainbond cloud native application management platform, you can refer to the documentation to install Rainbond Allinone
1. Deploy Spring Cloud Pig
Team -> New -> Create Component Based on App Store -> Search in App Store SpringCloud-Pig
for one-click deployment.
2. Deploy Arthas Tunnel
Team -> Add New -> Create Component Based on App Store -> Search in App Store Arthas-Tunnel
for one-click deployment.
3. Install Arthas Agent plugin and configure
1. Install the plugin
Team -> Plugins -> Install Plugins from App Store -> Search in App Store Arthas-Agent
for one-click deployment.
2. Activate the plugin
To activate a plugin for each microservice component, go to Microservice Components -> Plugins -> Activate Plugins Arthas-Agent
.
3. Configure environment variables
Configure environment variables for each microservice component, in component -> environment variables -> add variables.
variable name | variable | illustrate |
---|---|---|
JAVA_OPTS | -javaagent:/arthas/arthas-agent.jar | JAVA startup parameters |
ARTHAS_APP_NAME | register | arthas app name, modify according to the actual situation |
ARTHAS_AGENT_ID | register | arthas agent ID cannot be the same as other IDs, it is unique |
4. Configure dependencies
Depends all microservice components on arthas tunnel
, and switch the application view to the orchestration mode to drag and drop.
5. Batch update
Update/restart all microservice related components. Batch operations are available in 列表
.
4. Connect to other agents through Arthas Tunnel for diagnosis
1. You can access the Web Console through the domain name generated by default on Port 8080 of Arthas Tunnel.
2. Fill in the external service port of Arthas Tunnel 7777 in IP:PORT in the Web Console. Port 7777 is where the Agent connects to the Tunnel. So you can connect by modifying the AgentId when connecting to other services remotely through the Web
Getting Started with Arthas
1. Arthas command usage
Arthas adopts the command line interactive mode, and provides a rich Tab
auto-completion function, which further facilitates problem location and diagnosis. The following are some commands. For details, please refer to the document Arthas command list
- dashboard - the real-time data panel for the current system
- getstatic - view static properties of a class
- heapdump - dump java heap, similar to the heap dump function of the jmap command
- jvm - View information about the current JVM
- logger - view and modify logger
- mbean - view Mbean information
- memory - View JVM memory information
- ognl - execute ognl expression
- perfcounter - View the Perf Counter information of the current JVM
- sysenv - View JVM environment variables
- sysprop - View and modify JVM system properties
- thread - View the thread stack information of the current JVM
- vmoption - View and modify diagnostic-related options in the JVM
- vmtool - query objects from jvm, execute forceGc
The following are screenshots of some commands in use:
2. Generate a flame graph
profiler
command supports generating flame graphs of application hotspots. In essence, it is through continuous sampling, and then the collected sampling results are generated into a flame graph.
The following commands are all executed in Arthas Tunnel Web Console.
1. Start the profiler
$ profiler start
Started [cpu] profiling
2. Stop the profiler and generate a flame graph
By default, the result file is in html
format, or it can be specified with the --format
parameter:
$ profiler stop --format html
OK
profiler output file: /app/arthas-output/20220907-214802.html
3. View the flame graph through the browser
The html file generated in the previous step is in the specified microservice component, so you need to view the flame graph in this microservice component.
Enter the microservice component, for example: pig-auth, add 3658
port to the component port and open the external service and access http://domain/arthas-output
at last
Arthas is a very good diagnostic tool for Java, but it is more complicated to use in Kubernetes. The bottom layer of Rainbond is based on Kubernetes, on which the application model is abstracted, making it easier for users to deploy and manage applications in Kubernetes, and through Rainbond's plug-in mechanism, users can more easily use Arthas to diagnose services, reducing the cost of using Arthas in Kubernetes. Threshold, users only need to pay attention to the business.
Original link: https://mp.weixin.qq.com/s/soEhi5oQn2p1h7xDL68hlg
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。