• Spring Boot Admin is open source software that manages and monitors Spring Boot applications. Each application is treated as a client and presented via HTTP or using Eureka registered with the Admin server. The Spring Boot Admin UI part uses AngularJs to present data at the front end.
  • Spring Boot Admin is a monitoring tool for Spring-boot interface interface landscaping and encapsulation. It can: browse the basic information of all monitored Spring-Boot projects, detailed Health information, memory information, JVM information, garbage collection information, various configuration information (such as data source, cache list, hit ratio), and directly modify logger level.

Example Set the Spring Boot Admin Server

  • Create a new Spring Boot2.x project and add the Spring Boot Admin Server initiator to pom.xml
  • Using the IDE for new projects, you can choose to introduce Spring Boot Admin directly
  <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
   </dependency>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
   </dependency>
Copy the code

Add the following annotations to the startup class

@SpringBootApplication @EnableAdminServer public class SpringbootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringbootAdminApplication.class, args); }}Copy the code

Add authentication and authorization

@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {



    private final String adminContextPath;

    public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/"); Http.authorizerequests () // Grants public access to all static assets and login pages. .antMatchers(adminContextPath +"/assets/**").permitAll()
                .antMatchers(adminContextPath + "/login").permitall () // must authenticate every other request.anyRequest().authenticated(). .formLogin().loginPage(adminContextPath +"/login").successHandler(successHandler).and()
                .logout().logoutUrl(adminContextPath + "/logout").and() // Enable HTTP-basic support. This is required for Spring Boot Admin Client registration.httpbasic ().and().csrf() // use cookies to enable CSRF protection .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .ignoringAntMatchers( adminContextPath +"/instances", // disable crsf-protection Spring Boot Admin Client for registration endpoints. adminContextPath +"/actuator/**" //
                );
        // @formatter:on
    }
}

Copy the code

Application.properties configuration file

server.port=8088
server.tomcat.uri-encoding=UTF-8
server.tomcat.max-threads=1000
server.tomcat.min-spare-threads=30
# Account password
spring.security.user.name=gzpflm
spring.security.user.password=gzpflm
Project access name
spring.boot.admin.context-path=/szq-monitoring
#UI interface title
spring.boot.admin.ui.title=szq-Monitpring

Copy the code

Is up and running: http://localhost:8088/szq-monitoring/login login screen indicates success

Screenshot. PNG

Spring Boot client configuration monitoring

  • The account password must be configured on the client; otherwise, the client cannot register with springBoot Admin
  • Each application to register must contain the Spring Boot Admin Client configuration as follows
   <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
  </dependency>
Copy the code

Application.properties configuration file

server.port=8081
spring.application.name=Spring Boot Client
spring.boot.admin.client.url=http://localhost:8088/szq-monitoring
management.endpoints.web.exposure.include=*
spring.boot.admin.client.username=gzpflm
spring.boot.admin.client.password=gzpflm
spring.boot.admin.client.enabled=true
# Enable IP display
spring.boot.admin.client.instance.prefer-ip=true
Copy the code

After startup: The monitored server will receive notification to refresh the page to see the monitored service

Screenshot. PNG

Screenshot. PNG

Project address: gitee.com/qinxuewu/Sp…

Spring Boot Admin Client configuration option

spring.boot.admin.client.enabled    Boot Admin Client. The default value is true
spring.boot.admin.client.url  # comma separates the ordered list of urls for the Spring Boot Admin server for registration
spring.boot.admin.client.api-path # instances of the default Http path for registered endpoints on the server
#SBA Server API user name and password when protected by HTTP basic authentication.
spring.boot.admin.client.username 
spring.boot.admin.client.password
spring.boot.admin.client.period The default interval for repeated registrations is 10,000 ms
spring.boot.admin.client.connect-timeout  Register for connection timeout (in ms) # default 5,000
Copy the code

The official configuration

Codecentric. Making. IO/spring – the boot…