21 How to Check the Health Status of Each Service System Application Monitoring

21 How to Check the Health Status of Each Service - System Application Monitoring #

The various microservice modules are basically in place, but what is the situation of the system running? Is there a way to check it? This article will show you how to view some information about the system at runtime.

The Actuator plugin #

Careful friends may have noticed that each microservice’s pom.xml file configuration has the following jar reference, which is a series of additional feature components provided by Spring Boot to help you monitor and manage running system applications.

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

In addition to the need to import the corresponding jar package, specific configuration is also required. By default, only health and info APIs are exposed. To use other APIs normally, you need to set the exposure configuration items to * to enable the interfaces exposed by Actuator to be used normally.

management.endpoints.web.exposure.include=*

The figure below shows all the external interfaces provided by Actuator, the top left four of which are exclusive to web applications.

img

After starting any application, you can view all the interface addresses by entering the URL http://localhost:10065/actuator/ in your browser. The response information is output in JSON format. For example, access http://localhost:10065/actuator/metrics, and the browser response information is as follows:

img

By accessing different addresses, you can obtain relevant information about the service. For more documentation on Actuator components, please refer to the official Spring Boot Actuator documentation. However, all the information returned by the plugin is in text format, which is not intuitive enough. Monitoring personnels need to spend a lot of effort to interpret the underlying information.

Spring Boot Admin #

Introducing Spring Boot Admin here, it is a web application with the official website address:

https://github.com/codecentric/spring-boot-admin,

It is based on Actuator and has a UI beautification. It greatly improves usability for users. Let’s have a visual experience below.

img

img

img

Creating a monitoring server #

Based on Spring Boot, quickly build a parking-admin submodule. Add the following dependencies in the pom.xml file:

<properties>
        <spring.boot.admin.version>2.1.2</spring.boot.admin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>${spring.boot.admin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

Configure the application.yml configuration file:

server: 
  port: 10090

management: 
  endpoints: 
    web: 
      exposure: 
        include: \*
  security: 
    enabled: false
  endpoint: 
    health: 
      show-details: ALWAYS

spring: 
  application: 
    name: parking-admin

The application class is also very simple, just add the @EnableAdminServer annotation:

@EnableAdminServer
@SpringBootApplication
public class BootAdminApplication {

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

}

After starting the application, the server is complete. Open localhost:8081 in your browser to view the main page of Spring Boot Admin:

img

The page will remain in the Loading state until an application being monitored is added.

Adding a monitored client application #

Simply introduce the corresponding client jar in the corresponding module that needs to be monitored. (It is recommended to keep the version consistent with spring-boot-admin-starter-server)

<dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>

Add the following configuration in the corresponding application.properties:

# Must be exposed, otherwise the admin-server cannot get health data
management.endpoints.web.exposure.include=*
management.security.enabled=false
management.endpoint.health.show-details=ALWAYS

# admin server address
spring.boot.admin.client.url=http://localhost:10090

With just these two steps, no other major changes are needed. Start the main program class. Taking the resource service as an example, return to the monitoring page and you will find that the resource service instance has been monitored and listed in the interface:

img

Click on the application instance to view more detailed information. At this point, the application monitoring implemented through Spring Boot Admin can be used normally.

Although monitoring has already extended beyond the scope of code development, with the prevalence of DevOps and SRE concepts, the boundaries between development and operations are becoming increasingly blurred, and they are collaborating more closely. It is necessary to have an understanding of some monitoring knowledge. In addition, monitoring is an indispensable part of any microservice architecture. However, Spring Boot Admin can only monitor the information of the application itself, and cannot monitor the information of the host where the application belongs. Do you know any methods to monitor it?