This is the 11th day of my participation in Gwen Challenge
What is Spring Boot Admin
The spring Boot Actuator can monitor all kinds of information of applications. The only disadvantage is that the monitoring information returned is in JSON format. Another thing is that in the microservice architecture, there are many instances of services, so it seems impossible to watch the monitoring information one by one. In addition, so much address information can only be found in Eureka. Is there a function that can centrally manage the service information in Eureka and use the interface to view the monitoring information provided by the actuator? It is Spring Boot Admin.
Spring Boot Admin is a community project for managing and monitoring Spring Boot applications. Client applications are registered via an administrative server (over Http), using Spring Cloud discovery servers such as Eureka, Consul for discovery.
Every client application needs to have the Spring Actuator JAR. The Spring Cloud Admin server polls the endpoints provided by the Actuator JAR to get metrics for that particular application.
SBA(Spring Boot Admin) is a tool for managing and monitoring Spring Boot projects, including threads, memory, Spring bean loading, logging and a series of visual interfaces.
Meaning of using Spring Boot Admin
With the needs of the project business scenario, we currently have more and more boot services, tending to the horizontal expansion mode, especially in the future project, safe and stable operation is our current core focus and primary task, but how can we quickly and conveniently know the current health status of our micro-service project? In fact, those who are familiar with Spring Boot know that Spring Boot Actuator uses HTTP endpoints or JMX to manage and monitor applications. However, it does not provide a graphical interface and only provides DATA in JSON format. Meanwhile, it cannot manage applications centrally and is unfriendly to operation and maintenance. SBA(Spring Boot Admin) -based actuator not only solves these pain points, but also achieves many powerful functions through expansion, such as dynamically changing log level, viewing real-time logs, viewing URL mapping, etc., which is very meaningful for managing micro-services.
How to integrate with microservices
The following is an example: The boot version is 1.x. If the boot version is 2.x, the admin server and client need to find the corresponding 2.x version.
- The Server side
Add the following dependencies to the boot-admin-server POM file:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.56.</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.56.</version>
</dependency>
</dependencies>
Copy the code
Added support for Eureka
server:
port: 8000Spring: application: name: admin-server boot: admin: username: amdin ----> Admin server username password: Amdin -- - > the admin server password eureka: instance: leaseRenewalIntervalInSeconds:10
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management.security.enabled: false
Copy the code
Start the class
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class ServerApplication {
public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); }}Copy the code
After the above steps are complete, start the Server side.
- The Client side
Project depend on
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>1.56.</version>
</dependency>
</dependencies>
Copy the code
The configuration file
server:
port: 9000
spring:
application:
name: project_name
boot:
admin:
url: http://127.0.0.1:8000 ----> HTTP server registration service addressUsername: admin Password: admin Logging: file: /xxx.log ----> This parameter must be configured. Otherwise, real-time log logs cannot be viewed on the admin server. Eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/
management:
security:
enabled: false----> This parameter must be set. Otherwise, an authentication dialog box is displayed when you view health detail detailsCopy the code
The admin Client starts the class
@SpringBootApplication
@EnableDiscoveryClient
public class ProducerApplication {
public static void main(String[] args) { SpringApplication.run(ProducerApplication.class, args); }}Copy the code
After the configuration is complete, start the server and client projects respectively. Visit http://localhost:8000 and you can see the following interface:
By clicking Detail, we can see the current microservice’s memory, stack, interface access, threads, environment configuration, interface access status, and so on.
Now that our setup is over, we should learn how to learn from the console and view the value of our own monitoring services.
Q&A
- How do I adjust the Memory information in the Detail? How to scale up?
A: You can add JVM heap memory and non-heap memory parameters to spring Boot, such as: Java -xMS2048m -XMx2048m -xx :PermSize2048 -jar xxx.jar –server.port =8088 Where: -xMS2048m heap maximum limit -xmx heap maximum limit -xMS initial heap size -xx :PermSize: Sets the initial perm gen value.
- Where are my logs stored in the Admin server
A: View logs in admin Server. Click the log TAB page to view logs Polling mechanism, the server will be invoked http:// {admin server – host} / API/applications/ca72fbcf logfile (ps: the path of ca72fbcf for specific admin server The client registers the random instance ID assigned by the server) to perform log viewing, and the Admin server uses the monitoring interface provided by our specific client-integrated ACTUATOR
- Where do the metrics interface statistics in admin Server come from? Will the reboot disappear?
Answer: the metrics in the admin server statistics from http:// {admin server – host} / API/applications/ca72fbcf/metrics interface, and the specific admin interface will call us Interface monitoring provided by the client http://{admin-client-host}/actuator/metrics Indicator information. This indicator information is recalculated and collected after the admin client restarts services.
Problems encountered
-
Click Detail to view the real-time log information of microservices. The prerequisite is that the logging. File property must be configured on the client; otherwise, real-time log information will not be displayed in the monitoring information. By default, log files are not accessible through the executor endpoint and therefore are not visible in Spring Boot Admin. To enable the log file executor endpoint, you need to configure Spring Boot to write to the log file by setting the logging.path or logging.file configuration properties.
-
An admin client of an earlier version cannot be registered with an admin server of an earlier version, resulting in compatibility problems. However, you can use an admin client of an earlier version to register an admin server of an earlier version. Monitoring Spring Boot 1.5.x However, it is concluded that the client of a lower version may not be fully compatible with the admin server of a higher version if it is registered with the client of a higher version. Some indicator information may not be displayed, and the following information will be displayed: