Construction and impression of Spring Boot Admin ~ Tips for displaying Git commit information ~

Spring Boot Admin (Server) and Spring Boot Admin (Client) have been added to Spring Initializr, so I decided to touch them. Spring Boot Admin is a library that allows you to monitor Spring Boot applications.

Build

environment

OS: macOS Sierra 10.12.6 Java: 1.8.0_102 Spring Boot: 1.5.10.RELEASE Spring Boot Admin: 1.5.7

Construction procedure

Spring Boot Admin has a Server-Client configuration. The Server provides the monitoring screen, and the Client is the application to be monitored.

Spring Boot Admin Server

Select Spring Boot Admin (Server) from Spring Initializr to create an application.

OK if spring-boot-admin-starter-server is added to depenedency. (If you make it from Spring Initializr as above, it will be added naturally, so you should not need to edit pom.xml)

pom.xml


	<dependencies>
		<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>
	</dependencies>

After that, you need to delete the @SpringBootApplication annotation of the ʻApplication` class and add the annotation as shown below.

SpringBootAdminServerApplication.java


@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringBootAdminServerApplication.class, args);
	}
}

If you start it as an application with this, the Server side is OK. If you access http: // localhost: 8080, the monitoring web page will be displayed.

Spring Boot Admin Client

Select Spring Boot Admin (Client) from Spring Initializr to create an application. Since the Client itself should be started as an application, assuming a WEB application here, add Web as well.

If you create it as above, spring-boot-admin-starter-client (and spring-boot-starter-web) should be added to dependency.

pom.xml


	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>de.codecentric</groupId>
			<artifactId>spring-boot-admin-starter-client</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

Once you enter the connection information to the server in application.yml (I changed it because I personally like yml rather than properties), it's OK.

application.yml


server:
  port: 3000 # ①
spring:
  boot:
    admin:
      url: http://localhost:8080 # ②
management:
  security:
    enabled: false # ③

I will explain each property. (1): Spring Boot Admin Server starts on the default 8080 port (because it is not set in particular), so make sure that the boot port is not covered. 2: Connection information to Spring Boot Admin Server. ③: Because all endpoints have been secure since Spring Boot 1.5.x. Since it is disabled for confirmation, it is described in the security section in production. Need to be dealt with.

After that, it is better to add build-info to pom.xml so that the build time information (version, artifact, etc.) is displayed.

pom.xml


	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>build-info</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

All you have to do is start it.

Impressions

The screen looks like this.

スクリーンショット 2018-02-15 17.26.52.png

Demerit

What immediately made me feel uncomfortable was that the display was not over time. In other words, only the current snapshot status is displayed. Therefore, it is unknown whether the state is a state in which the load is higher than usual. I think this is the biggest disadvantage. To be honest, it's hard to see, and it's hard to use because I can't feel whether it's normal or not.

merit

I tried to pursue a little

Internal construction (Spring Boot Admin Client)

The main process is described in the de.codecentric.boot.admin.client.registration package. The Client side is just scheduling and registering to the Server side.

class Outline of processing
RegistrationApplicationListener Register and cancel scheduling. The method of ApplicationRegistrator class is called at startup or periodically.
ApplicationRegistrator HTTP communication is performed to Spring Boot Server Admin, and registration request is performed on the Server side.

Internal construction (Spring Boot Admin Server)

Roughly speaking, there is a process of receiving HTTP and registering, and a process of updating the status regularly. Click here for classes that are mainly related to the process of receiving and registering HTTP.

package class Outline of processing
de.codecentric.boot.admin.registry.web RegistryController Controller that receives API from Client side.
de.codecentric.boot.admin.registry ApplicationRegistry Register the Client information based on the information received from the Client side.

Click here for the process of updating the status on a regular basis.

package class Outline of processing
de.codecentric.boot.admin.registry StatusUpdateApplicationListener Register and cancel scheduling.
de.codecentric.boot.admin.registry StatusUpdater Access the Actuator API on the Client side and update the status.

Tips: View Git commit information

When I created it by default, Git's commit information (commit ID, branch, etc.) was not displayed, so I checked the settings.

Spring Boot Admin displays the information of / info of Spring Boot Actuator, so you can add the information of Git to / info. The method is as follows.

Add git-commit-id-plugin to pom.xml.

pom.xml


<build>
    <plugins>
        <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
        </plugin>
    </plugins>
</build>

This is all you need! The git-commit-id-plugin just creates a git.properties file, but the Spring Boot Actuator's GitInfoContributor class will automatically find the file and add it to / info.

Summary

After all it is bad that time has not passed. I wondered if I would bother to adopt it for the project. I hope that it will be improved so that it will be easier to use in the future.

Also, if you look at the contents of the library, it will be a learning experience. Sometimes I want to take the time to check the library like this.

GitHub

I uploaded it to my GitHub, so please refer to it. spring-boot-admin-sample

reference

Spring Boot Admin

View Git commit information

Recommended Posts

Construction and impression of Spring Boot Admin ~ Tips for displaying Git commit information ~
WebMvcConfigurer Memorandum of Understanding for Spring Boot 2.0 (Spring 5)
Various correspondence table of Spring Framework and Spring Boot
Plans to support JDK 11 for Eclipse and Spring Boot
[For beginners] DI ~ The basics of DI and DI in Spring ~
Get error information using DefaultErrorAttributes and ErrorAttributeOptions in Spring Boot 2.3
Introductory hands-on for beginners of Spring 5 & Spring Boot 2 has been released