Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Springboot Admin2.0 integrates Arthas

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to integrate Springboot Admin2.0 Arthas, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The project initially used Arthas for two main purposes:

The problem of realizing the performance problem analysis tool of test environment, performance test environment and production environment is solved by arthas.

The ability to hot update the node code in part of the production environment by using the combination of jad, mc and redefine functions.

Related to technology selection

Because the company has not been able to establish a more unified production micro-service configuration and state management capabilities, the R & D, operation and maintenance of their respective systems are relatively independent. Now the project uses the framework of Spring Cloud and Eureka, which matches the basic support capacity of SBA. At the same time, SBA can provide service awareness, log-level configuration management, and many management plug-ins for actuator-based JVM and Spring containers, which can meet the needs of basic use.

During the research period, the overall version of Arthas is 3.4.5, which provides a Webconsole-based Tunner Server model, which has been put into practice through the previous linked article, and can be integrated with SBA. Because the project itself has no historical baggage, SBA 2.0 version is adopted in the actual integration process to provide more management functions and graphical interface capabilities. Other benefits:

Web console interface embeds SBA overall password login and web page rights management, so that you can use the related arthas web console function only after logging in to SBA.

Based on the jmx management of jolokia-core open target service process that SBA client depends on, the requirement of front-end interface development ability is reduced by realizing jmx interface to reuse the relevant operation interface of SBA.

Whole structure

Several key points, the use of JVM built-in Arthas Spring Boot plug-in, reference to the ICBC model to establish a perfect client download and modify the script to achieve remote control. The amount of work and development of the built-in solution is small, and only the relevant open source components need to be integrated to achieve the relevant remote use patterns and take into account security. ICBC's plan is large and suitable for the city of proprietary R & D team after the overall structural planning. The built-in solution also includes the start and stop operation through JMX (the Spring Boot plug-in based on 3.4.5 cannot get the relevant handle and cannot be implemented for the time being), and does not start by default. After the remote JMX is enabled, 8 new threads are added to the JVM, and the virtual machine memory 30MB is added, which is the same as the SBA1.0 solution referred to in this document. You need to consider whether the JVM memory can be supported before enabling it online.

Realize the effect

The biggest convenience of SBA 2.0 is that it provides the ability to configure links to external web pages. At the same time, if the web pages are implemented in the current JVM process, you can achieve the local rights management of Spring-Security. In the production environment, you can use the relevant integrated arthas functions only after logging in to SBA.

Login Page

Embedded connection location

The use of JMX

Jump to arthas web console

Transformation plan 1. Integral engineering structure

The whole project is modified from the example project of the SBA open source project. The project link that uses custom-ui is as follows: [spring-boot-admin-sample-custom-ui] _, _ the red box is all the static files of arthas web console. Enter the specified directory through the specified configuration of Maven Resource to achieve custom loading when SBA starts. Maven resource configuration-the following:

Static ${project.build.directory} / classes/META-INF/spring-boot-admin-server-ui/extensions/arthas false 2. External link configuration

SBA 2.0 has been using vue family buckets since then, and it is easy to expand and integrate. Among them, the official document gives the configuration method of embedded connection: [Linking / Embedding External Pages].

You can refer to the application.yml configuration of sba example project:

# tag::customization-external-views [] spring: boot: admin: ui: external-views:-label: "Arthas Console" url: http://21.129.49.153:8080/ order: 1900 # end::customization-external-views [] 3. Corresponding Spring MVC controller implementation

Refer to the SBA integration part of the original implementation, which is mainly modified to implement the following functions:

Implement the refresh of the loaded instance list in tunnel server and display it to the AgentID box in the previous paragraph to select a link.

Implement the refresh of custom IP address (solve the problem of inconsistency between dual production IP and operation and maintenance segment IP in production environment).

4. Arthas Spring Boot plug-in modification and configuration

Refer to the plug-in modification in the original implementation of the SBA integration and the client configuration application.yml.

The main modification to the original Spring boot plug-in is that the original plug-in is automatically loaded through Spring's @ ConditionalOnMissingBean.

Modification is mainly achieved by modifying this part through the configuration file does not start by default, and then use to start the relevant agent thread remotely.

5. Implementation of JMX based on Spring Actuator

SBA client introduces jolokia-core.jar by default in the introduction of maven. If the package is not introduced by itself because of the SBA client dependency, you can open the http-based jmx operation capabilities through actuator and seamlessly cooperate with the related features of the SBA console.

Management-related configuration is open in application.yml, and Spring security authentication can also be enabled on the client side according to your own environment. SBA can also support password-protected access to actuator endpoints through service discovery.

# release management management: endpoints: web: exposure: # here * means to expose all endpoints just to observe the effect. In practice, the endpoint exposure include: "*" exclude: env endpoint: health: # details are displayed to all users. Show-details: ALWAYS health: status: http-mapping: # the http status code corresponding to the returned status code of custom health check FATAL: 503

The implementation of JMX refers to the implementation of EnvironmentChangeListener in the original text, and the implementation of JMX annotation based on Spring can be done.

@ Component @ ManagedResource (objectName = "com.ArthasAgentManageMbean:name=ArthasMbean", description = "Arthas remote Administration Mbean") public class ArthasMbeanImpl {@ Autowired private Map arthasConfigMap; @ Autowired private ArthasProperties arthasProperties; @ Autowired private ApplicationContext applicationContext / * * initialize * * @ return * / private ArthasAgent arthasAgentInit () {arthasConfigMap = StringUtils.removeDashKey (arthasConfigMap); / / prefix the configuration with Map mapWithPrefix = new HashMap (arthasConfigMap.size ()) For (Map.Entry entry: arthasConfigMap.entrySet ()) {mapWithPrefix.put ("arthas." + entry.getKey (), entry.getValue ());} final ArthasAgent arthasAgent = new ArthasAgent (mapWithPrefix, arthasProperties.getHome (), arthasProperties.isSlientInit (), null); arthasAgent.init (); return arthasAgent } @ ManagedOperation (description = "get configuration ArthasTunnelServer address") public String getArthasTunnelServerUrl () {return arthasProperties.getTunnelServer () } @ ManagedOperation (description = "set ArthasTunnelServer address, effective after re-attach") @ ManagedOperationParameter (name = "tunnelServer", description = "example:ws://127.0.0.1:7777/ws") public Boolean setArthasTunnelServerUrl (String tunnelServer) {if (tunnelServer = = null | | tunnelServer.trim (). Equals (") | | tunnelServer.indexOf (" ws:// ") < 0) {return false } arthasProperties.setTunnelServer (tunnelServer); return true;} @ ManagedOperation (description = "get AgentID") public String getAgentId () {return arthasProperties.getAgentId ();} @ ManagedOperation (description = "get application name") public String getAppName () {return arthasProperties.getAppName () } @ ManagedOperation (description = "get ArthasConfigMap") public HashMap getArthasConfigMap () {return (HashMap) arthasConfigMap;} @ ManagedOperation (description = "return whether Arthas agent is loaded") public Boolean isArthasAttched () {DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory (); String bean = "arthasAgent" If (defaultListableBeanFactory.containsBean (bean)) {return true;} return false;} @ ManagedOperation (description = "start Arthas agent") public Boolean startArthasAgent () {DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory (); String bean = "arthasAgent" If (defaultListableBeanFactory.containsBean (bean)) {((ArthasAgent) defaultListableBeanFactory.getBean (bean)) .init (); return true;} defaultListableBeanFactory.registerSingleton (bean, arthasAgentInit ()); return true } @ ManagedOperation (description = "close Arthas agent, not implemented yet") public Boolean stopArthasAgent () {/ / TODO cannot get the classLoader loaded by the custom tmp folder, so it cannot get the com.taobao.arthas.core.server.ArthasBootstrap class and call the destroy method DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory (); String bean = "arthasAgent" If (defaultListableBeanFactory.containsBean (bean)) {defaultListableBeanFactory.destroySingleton (bean); return true;} else {return false;}} actual use

After the management project has been put into production, it has been used for problem troubleshooting and code thermal repair in the production environment for many times. Performance problems are mainly used for online verification and debug of performance flow control components and configuration parameters related to grayscale publishing.

At the initial stage of code hot loading, the operation is carried out through jad+mc. Later, it is found that the decompiled code of jad is inconsistent in some code due to environmental configuration and jvm problems. It is solved by packaging and deploying application source package through maven. It is more reliable to directly use and apply source built in the same version of jar for modification. The overall solution provides effective performance analysis and thermal repair capabilities in a more tightly managed production environment.

Remaining problems

The arthasClassLoader and bootstrapClass used by the client that launches arthas agent in the existing official com.taobao.arthas.agent.attach.ArthasAgent are temporary variables within the method, and the relevant handle cannot be obtained externally to close the arthas agent through bootstrapClass. The temporary solution is to use the stop command to shut down arthas agent in the target process after starting through JMX and after the use of the web console connection.

The existing bytecode loading tools can well implement internal classes, online hot deployment replacement of private classes, and can be compatible with the SkyWalk8.x version of the javaagent plug-in, but in the test environment because of the configuration of the jacoco coverage collection plug-in and Arthas bytecode is not compatible, in some environments, you need to close the corresponding agent before you can normally use the relevant functions of arthas.

Thank you for reading this article carefully. I hope the article "how to integrate Springboot Admin2.0 into Arthas" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report