Spring Boot indicator monitoring and health check
Bloggers communicate with Jun Sheep; 723749901 [code 67]
Actuator
Spring Boot Actuator helps you monitor and manage Spring Boot applications, such as health checks, auditing, statistics, and HTTP tracking. All of these features are available via JMX or HTTP endPoints.
Create a project
Create a Spring Boot project and select the Spring Boot Actuator component.
POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2. RELEASE</version>
<relativePath/> <! -- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo-actuator</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<name>demo-actuator</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<! -- Spring boot actuator dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<! Spring Boot Web dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<! -- Spring Boot test dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Copy the code
Monitor setting
An executor endpoint allows you to monitor and interact with your application. Spring Boot includes a number of built-in endpoints that allow you to add your own. For example, Health provides basic application health information.
Each endpoint can be enabled or disabled. This controls whether the created endpoint and its beans exist in the application context. To enable remote access, the endpoint must also be exposed through JMX or HTTP. Most applications choose HTTP, where the ID of the endpoints and the prefix /actuator are mapped to a URL. For example, by default, health endpoint health maps to /actuator/ Health.
The following endpoints are technology-independent:
ID | Description |
---|---|
auditevents |
Exposes audit events information for the current application. Requires an AuditEventRepository bean. |
beans |
Displays a complete list of all the Spring beans in your application. Displays a complete list of all Spring beans in the application. |
caches |
Exposes available caches. Expose available caches. |
conditions |
Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match. |
configprops |
Displays a collated list of all @ConfigurationProperties .All configuration information is displayed. |
env |
Exposes the properties from the Spring ‘sConfigurableEnvironment .Display all environment variables. |
flyway |
Shows any Flyway database migrations that have been applied. Requires one or more Flyway beans. |
health |
Shows application health information. Displays health information for the application. |
httptrace |
Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). Requires an HttpTraceRepository bean.Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). You need an HttpTraceRepository bean. |
info |
Displays arbitrary application info. Displays application information. |
integrationgraph |
Shows the Spring Integration graph. Requires a dependency on spring-integration-core . |
loggers |
Shows and modifies the configuration of loggers in the application. Displays and modifies loggers configurations in the application. |
liquibase |
Shows any Liquibase database migrations that have been applied. Requires one or more Liquibase beans. |
metrics |
Show ‘metrics’ information for the current application. Displays metrics information about the current application. |
mappings |
Displays a collated list of all @RequestMapping paths.Show all @RequestMapping Collated list of urls. |
scheduledtasks |
Displays the scheduled tasks in your application. |
sessions |
Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a Servlet-based web application using Spring Session. |
shutdown |
Lets the application be gracefully shutdown. Disabled by default. Close the application (not enabled by default). |
threaddump |
Performs a thread dump. |
If your application is a Web application (Spring MVC, Spring WebFlux, or Jersey), you can also use the following additional endpoints:
ID | Description |
---|---|
heapdump |
Returns an hprof heap dump file. |
jolokia |
Exposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux). Requires a dependency on jolokia-core . |
logfile |
Returns the contents of the logfile (if logging.file.name or logging.file.path properties have been set). Supports the use of the HTTP Range Header to Retrieve part of the log file’s content. |
prometheus |
Exposes metrics in a format that can be scraped by a Prometheus server. Requires a dependency on micrometer-registry-prometheus . |
The configuration file
Metrics monitoring and health check
management:
endpoints:
web:
base-path: /actuator # access the root path of the endpoints. The default is /actuator
exposure:
include: The '*' The shutdown endpoint is not enabled even if '*' is configured. Additional configuration is required
exclude: env,caches # endpoints that do not need to be opened
endpoint:
shutdown:
enabled: true # open shutdown
Copy the code
Start the class
package com.example.demoactuator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoActuatorApplication {
public static void main(String[] args) { SpringApplication.run(DemoActuatorApplication.class, args); }}Copy the code
Startup information
The console prints information to show how many access endpoints are open.
access
POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2. RELEASE</version>
<relativePath/> <! -- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo-admin-server</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<name>demo-admin-server</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.2.1</spring-boot-admin.version>
</properties>
<dependencies>
<! -- Spring Boot admin server dependencies -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<! Spring Boot Web dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<! -- Spring Boot test dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Copy the code
The configuration file
server:
port: 8769
Copy the code
Start the class
The @enableadMinServer annotation is required to start the class.
package com.example.demoadminserver;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableAdminServer
public class DemoAdminServerApplication {
public static void main(String[] args) { SpringApplication.run(DemoAdminServerApplication.class, args); }}Copy the code
Setting up the client
Create a project
To create a Spring Boot project, select the Spring Boot Admin Client component.
In this article, use the same Actuator project as the client.
POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2. RELEASE</version>
<relativePath/> <! -- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo-actuator</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<name>demo-actuator</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.2.1</spring-boot-admin.version>
</properties>
<dependencies>
<! -- Spring Boot admin client dependencies -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<! -- Spring boot actuator dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<! Spring Boot Web dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<! -- Spring Boot test dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Copy the code
The configuration file
Metrics monitoring and health check
management:
endpoints:
web:
base-path: /actuator # access the root path of the endpoints. The default is /actuator
exposure:
include: The '*' The shutdown endpoint is not enabled even if '*' is configured. Additional configuration is required
exclude: env,caches # endpoints that do not need to be opened
endpoint:
shutdown:
enabled: true # open shutdown
# specify the server access address
spring:
boot:
admin:
client:
url: http://localhost:8769
Copy the code
Bloggers communicate with Jun Sheep; 723749901 [code 67]