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 to implement SpringBootAdmin micro-service application monitoring

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you how to achieve SpringBootAdmin micro-service application monitoring. I hope you will get something after reading this article. Let's discuss it together.

Introduction to Spring Boot Admin

SpringBoot applications can expose various indicators in the running process of applications through Actuator, and SpringBoot Admin monitors SpringBoot applications through these indicators, and then presents them through a graphical interface. Spring Boot Admin can not only monitor individual applications, but also can be combined with Spring Cloud's registry to monitor micro-service applications.

Spring Boot Admin can provide the following monitoring information for the application:

Monitor the overview information of the running process of the application; metric information, such as JVM, Tomcat and process information; environment variable information, such as system properties, system environment variables, and application configuration information; view all created Bean information; view all configuration information in the application; view application running log information; view JVM information; view accessible Web endpoints; view HTTP tracking information.

Here we create an admin-server module to demonstrate its function as a monitoring center.

Add related dependencies to pom.xml:

Org.springframework.boot spring-boot-starter-web de.codecentric spring-boot-admin-starter-server

Configure in application.yml:

Spring: application: name: admin-serverserver: port: 9301

Add @ EnableAdminServer to the startup class to enable the admin-server feature:

@ EnableAdminServer@SpringBootApplicationpublic class AdminServerApplication {public static void main (String [] args) {SpringApplication.run (AdminServerApplication.class, args);}}

Create an admin-client module

Here we create an admin-client module to register with admin-server as a client.

Add related dependencies to pom.xml:

Org.springframework.boot spring-boot-starter-web de.codecentric spring-boot-admin-starter-client

Configure in application.yml:

Spring: application: name: admin-client boot: admin: client: url: http://localhost:9301 # configure admin-server address server: port: 9305management: endpoints: web: exposure: include:'* 'endpoint: health: show-details: alwayslogging: file: admin-client.log # add log monitoring enabled by admin

Start the admin-server and admin-client services.

Demonstration of monitoring information

Visit the following address to open the home page of Spring Boot Admin: http://localhost:9301

Click the wallboard button and select admin-client to view monitoring information

Overview of monitoring information

Metric information, such as JVM, Tomcat, and process information

Environment variable information, such as system properties, system environment variables, and application configuration information

View all created Bean information

View all configuration information in the application

To view the log information, you need to add the following configuration to enable it.

Logging: file: admin-client.log # add log monitoring with admin enabled

View JVM information

View Web endpoints that can be accessed

View HTTP trace information

Used in conjunction with the registry

When Spring Boot Admin is used in conjunction with the Spring Cloud registry, you only need to integrate admin-server with the registry. Admin-server will automatically obtain a list of services from the registry, and then obtain monitoring information one by one. Take the Eureka registry as an example to introduce this function.

Modify admin-server to add related dependencies to pom.xml:

Org.springframework.cloud spring-cloud-starter-netflix-eureka-client

To configure in application-eureka.yml, simply add the registry configuration:

Spring: application: name: admin-serverserver: port: 9301eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8001/eureka/

Add @ EnableDiscoveryClient to the startup class to enable the service registration feature:

@ EnableDiscoveryClient@EnableAdminServer@SpringBootApplicationpublic class AdminServerApplication {public static void main (String [] args) {SpringApplication.run (AdminServerApplication.class, args);}}

Modify admin-client

Add related dependencies to pom.xml:

Org.springframework.cloud spring-cloud-starter-netflix-eureka-client

Configure in application-eureka.yml, delete the original admin-server address configuration, and add the registry configuration:

Spring: application: name: admin-clientserver: port: 9305management: endpoints: web: exposure: include:'* 'endpoint: health: show-details: alwayslogging: file: admin-client.log # add log monitoring eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8001/eureka/ with admin enabled

Add @ EnableDiscoveryClient to the startup class to enable the service registration feature:

@ EnableDiscoveryClient@SpringBootApplicationpublic class AdminClientApplication {public static void main (String [] args) {SpringApplication.run (AdminClientApplication.class, args);}}

Function demonstration

Start eureka-server, start admin-server,admin-client using application-eureka.yml configuration

Check that the registry discovery service is registered: http://localhost:8001/

Check the Spring Boot Admin home page and find that you can see the service information: http://localhost:9301

Add login authentication

We can get login authentication by adding Spring Security support to admin-server.

Create an admin-security-server module

Add related dependencies to pom.xml:

Org.springframework.cloud spring-cloud-starter-netflix-eureka-client de.codecentric spring-boot-admin-starter-server 2.1.5 org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-web

Configure the login user name and password in application.yml, and ignore the monitoring information of admin-security-server:

Spring: application: name: admin-security-server security: # configure login username and password user: name: macro password: 123456 boot: # do not display monitoring information of admin-security-server admin: discovery: ignored-services: ${spring.application.name} server: port: 9301eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8001/eureka/

Configure SpringSecurity so that admin-client can register:

/ * Created by macro on 2019-9-30 * / @ Configurationpublic class SecuritySecureConfig extends WebSecurityConfigurerAdapter {private final String adminContextPath; public SecuritySecureConfig (AdminServerProperties adminServerProperties) {this.adminContextPath = adminServerProperties.getContextPath ();} @ Override protected void configure (HttpSecurity http) throws Exception {SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler (); successHandler.setTargetUrlParameter ("redirectTo"); successHandler.setDefaultTargetUrl (adminContextPath + "/"); http.authorizeRequests () / / 1. Configure all static resources and login pages to access .antMatrices (adminContextPath + "/ assets/**"). PermitAll () .antMatrices (adminContextPath + "/ login"). PermitAll () .anyRequest (). Authenticated () .and () / / 2. Configure the login and logout path .formLogin () .formLogin (adminContextPath + "/ login") .formHandler (successHandler). And () .logout (). LogoutUrl (adminContextPath + "/ logout"). And () / / 3. Enable http basic support. You need to use .httpBasic () .and () .csrf () / / 4 when registering for admin-client. Open cookie-based csrf protection. CsrfTokenRepository (CookieCsrfTokenRepository.withHttpOnlyFalse ()) / / 5. Ignore the csrf protection of these paths so that admin-client can register. AdminContextPath + "/ instances", adminContextPath + "/ actuator/**");}}

Modify the startup class, enable AdminServer and registration discovery function:

@ EnableDiscoveryClient@EnableAdminServer@SpringBootApplicationpublic class AdminSecurityServerApplication {public static void main (String [] args) {SpringApplication.run (AdminSecurityServerApplication.class, args);}}

Start eureka-server,admin-security-server, visit the Spring Boot Admin home page and find that you need to log in to visit: http://localhost:9301

The module used

Springcloud-learning ├── eureka-server-- eureka registry ├── admin-server-- admin monitoring center service ├── admin-client-- admin monitoring center monitoring application service └── admin-security-server-- admin monitoring center service with login authentication

After reading this article, I believe you have a certain understanding of "how to implement SpringBootAdmin Micro Service Application Monitoring". If you want to know more about it, please follow the industry information channel. Thank you for reading!

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