1. Introduction
GitHub: https://github.com/codecentric/spring-boot-admin
Official document: http://codecentric.github.io/spring-boot-admin/1.5.7/ (This document is a document with version 1.5.7)
The applications register with our Spring Boot Admin Client (via HTTP) or are discovered using Spring Cloud ® (eg Eureka, Consul).
The official document mentions that using Spring Boot Admin monitoring requires a Spring Boot Admin Server service, and the other monitored services are a Spring Boot Admin Client, or the monitoring service is conducted through the service registration and discovery components such as Eureak and Consul in Spring Cloud. In this way, there is no need to deliberately set up the relevant monitored services as a client, just register in Eureka or Consul.
Note: This article is based on Spring Cloud Eureka as a service registration discovery component to realize the monitoring of services. Eureka's service exists in advance. In addition: If you do not use eureka, you need to introduce client jars in the monitored service. For details, please refer to the official documentation above. *
2. Create Spring Boot Admin Server Service
First create a Spirng Boot project, which can be quickly built through http://start.spring.io/.
1. Add Spring Boot Admin Server dependencies
pom.xml
<dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>1.5.7</version> </dependency></dependencies>
2. Add @EnableAdminServer annotation to enable monitoring
@Configuration@EnableAutoConfiguration@EnableAdminServerpublic class SpringBootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminApplication.class, args); }}3. Register Spring Boot Admin Server to Eureka
Add Eureka dependencies
pom.xml
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency>
Add @EnableDiscoveryClient to enable service discovery
@Configuration@EnableAutoConfiguration@EnableDiscoveryClient@EnableAdminServerpublic class SpringBootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminApplication.class, args); }}Add Eureka service registration configuration
eureka: instance: leaseRenewalIntervalInSeconds: 10 client: registryFetchIntervalSeconds: 5 serviceUrl: defaultZone: http://10.1.3.54:8761/eureka/# Turn off the security of spring boot actuator, otherwise the sensitive path access is 401management: security: enabled: false
Start the project and visit ip:port to enter the managed page
As shown in the picture:
The items shown in the figure are all services registered with Eureka, and the items are monitored by registering Spring Boot Admin Server to Eureka.
3. Configuration settings
1. Log in to the UI
Admin management service does not have any security measures, and anyone can access it by knowing IP and port, which is very unsafe, and Spring Boot Admin also provides a login page. Need to be used with Spring Security.
Add Spring Boot Admin UI dependencies:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui-login</artifactId> <version>1.5.7</version></dependency>
Add Spring Security dependencies:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId></dependency>
Add configuration code to the project startup class:
package com.aspire.springbootadmin;import de.codecentric.boot.admin.config.EnableAdminServer;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.context.annotation.Configuration;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;@Configuration@EnableAutoConfiguration@EnableDiscoveryClient@EnableAdminServerpublic class SpringbootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringbootAdminApplication.class, args); } @Configuration public static class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { // Page with login form is served as /login.html and does a POST on /login http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll(); // The UI does a POST on /logout on logout http.logout().logoutUrl("/logout"); // The ui currently doesn't support csrf http.csrf().disable(); // Requests for the login page and the static assets are allowed http.authorizeRequests() .antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**") .permitAll(); // ... and any other request needs to be authorized http.authorizeRequests().antMatchers("/**").authenticated(); // Enable so that the clients can authenticate via HTTP basic for registering http.httpBasic(); } }}Add a configuration file
security: user: name: admin password: 123123 basic: enabled: false
A login page will appear when accessing again
Enter the username and password configured in the configuration and click Login to log in. After entering, there will be an extra exit button on the navigation bar. After clicking, you will return to the login page.
2. Client application version information
To display the version in the Application list, use maven's build-info plugin and add the plugin in the pom.xml file
<build> <plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>build-info</goal> </goals> </execution> </executions> </plugin> </plugin> </plugins></build>
As shown in the figure: If nothing is added, it will not be displayed.
3. Client application JMX bean management
To interact with JMX-beans in the admin interface, you must include Jolokia in your application. Add pom dependencies:
<dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId></dependency>
After adding it, you can see the JMX menu in the monitored application detial menu.
4. Client application adds log log
The configuration in the properties of the Client application is as follows:
logging: path: /xxx/xxx/xxx/
Specify the log output path, and then the log can be displayed:
5. Hystrix ui support
spring boot admin can also integrate hystrix display. The premise is that the client needs to enable hystrix.
Adding dependencies in Spring Boot Admin Server
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui-hystrix</artifactId> <version>1.4.6</version></dependency>
Add endpoints node in Server configuration file
Copy the code as follows: spring.boot.admin.routes.endpoints: env,metrics,trace, dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,activiti,hystrix.stream
Click to open Hystrix Client, click the Hystrix menu to see Hystrix information
6.Turbine UI support
spring boot admin can also integrate turbine display.
Join Dependencies:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui-turbine</artifactId> <version>1.5.7</version></dependency>
Configure the cluster and location of turbine. The clusters are the same clusters configured in the turbin service. The location needs to specify the Turbine service name registered in Eureka. For example, your Turbine service name is TURBINE-SERVER, and the configuration is as shown below. (In fact, Spring Boot Admin Server can be regarded as a Turbine service. If the Turbine service has existed before, it can be configured directly here. If the Turbine service does not exist, add Turbine-related dependencies and configurations to Spring Boot Admin Server, so that Spring Boot Admin Server becomes a Turbine service.)
spring.boot.admin.turbine: clusters: default location: TURBINE-SERVER
Finally add the endpoint of turbine.stream in the configuration file
Copy the code as follows: spring.boot.admin.routes.endpoints: env,metrics,trace, dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,activiti,hystrix.stream,turbine.stream
interface
There will be an additional TURBINE Tab in the navigation bar, and you can see the Turbine information by clicking.
7. Email notification
Spring Boot Admin also supports email notifications.
Add dependencies
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId></dependency>
Add Spring email configuration (I remember a small pit here. I started using QQ mailbox, but I couldn't connect to the SMTP server of the QQ mailbox. I checked the reason because Tencent banned the company's intranet IP, but there was no problem connecting to the 4G network.)
spring: mail: host: mmmail.aspire-tech.com password: xxxxx port: 25 username: xxxx
Add Spring Boot Admin mail configuration
boot: admin: notify: mail: to: [email protected] from: [email protected] enabled: true
The effect is as shown in the figure. There will be email notifications when the monitoring service is started or stopped.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.