Preface
Spring Boot Admin is a visual representation of the endpoint information provided in the Spring Boot Actuator and can send alert messages via mail, Telegram, Hipchat, and so on.
Integrate
Be aware that versions must match, otherwise unexpected problems may occur. Srping Boot Admin version 2.0+ or above is recommended for multilingual switching.
Parent Project
Introduction of pom.xml:
<modules> <module>admin-server</module> <module>admin-client</module></modules><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.2.RELEASE</version> <relativePath/></parent><dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency></dependencies>
Monitoring Server
Introduction of pom.xml:
<artifactId>admin-server</artifactId><dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.2.1</version> </dependency> <!--Logon Authentication--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!--Send mail notification offline--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency></dependencies>
application.properties configuration file:
#Java Notes: https://blog.52itstyle.vipserver.port=9000spring.application.name=SpringBootAdminspring.security.user.name=adminspring.security.user.password=adminspring.boot.admin.monitor.status-interval=10000spring.boot.admin.monitor.info-interval=10000spring.mail.host=smtp.163.comspring.mail.user name=131888888@163.commail.pass.com.mail.user name=131888888Word = 2020spring.boot.admin.notify.mail.from = 131888888@163.comspring.boot.admin.notify.mail.to = 88888888@q.com
Startup class:
/** * System Monitoring*Java Notes: https://blog.52itstyle.vip */@Configuration@EnableAutoConfiguration@EnableAdminServerpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Configuration public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter { private final AdminServerProperties adminServer; public SecuritySecureConfig(AdminServerProperties adminServer) { this.adminServer = adminServer; } @Override protected void configure(HttpSecurity http) throws Exception { SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter("redirectTo"); successHandler.setDefaultTargetUrl(this.adminServer.path("/")); http.authorizeRequests() .antMatchers(this.adminServer.path("/assets/**")).permitAll() .antMatchers(this.adminServer.path("/login")).permitAll() .anyRequest().authenticated() .and() .formLogin().loginPage(this.adminServer.path("/login")).successHandler(successHandler).and() .logout().logoutUrl(this.adminServer.path("/logout")).and() .httpBasic().and() .csrf() .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .ignoringRequestMatchers( new AntPathRequestMatcher(this.adminServer.path("/instances"), HttpMethod.POST.toString()), new AntPathRequestMatcher(this.adminServer.path("/instances/*"), HttpMethod.DELETE.toString()), new AntPathRequestMatcher(this.adminServer.path("/actuator/**")) ) .and() .rememberMe().key(UUID.randomUUID().toString()).tokenValiditySeconds(1209600); } }}
Monitoring Client
Introduction of pom.xml:
<artifactId>admin-client</artifactId><dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.2.1</version> </dependency></dependencies>
application.properties configuration file:
#Java Notes: https://blog.52itstyle.vipspring.boot.admin.client.instance.name = 007spring.boot.admin.client.url= http://localhost:9000management.endpoints.web.exposure.include=*spring.boot.admin.client.username = admin spring.boot.client.password = prinnsg.boot.n.client.period = 10000spring.admin.client.connection-out = 50000Spring.boot.admin.client.read-timeout = 5000spring.boot.admin.client.instance.service-url = http://localhost:8080
Monitoring interface
Summary
It must be said that version 2.X is still beautiful and classy, and has a full monitoring and alarm function.