SpringBootDemoActuator
创建一个SpringBoot项目
pom.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<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.4.2</version>
<relativePath/>
</parent>
<groupId>com.spring.demo.actuator</groupId>
<artifactId>demo-actuator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-actuator</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- SpringBoot健康检查依赖包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- SpringBoot Web启动依赖包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 测试依赖包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- SpringBoot打包工具 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
SpringBoot启动类
package com.spring.demo.actuator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author ljty
*/
@SpringBootApplication
public class DemoActuatorApplication {
public static void main(String[] args) {
SpringApplication.run(DemoActuatorApplication.class, args);
}
}
application.yml配置文件
# health 健康检查
management:
# server:
# # 设置监控服务端口,如果没写默认就是服务器的端口
# port: 8081
endpoints:
# 设置端点是否可用 默认只有shutdown可用
enabled-by-default: true
web:
# 访问根路径
base-path: /actuator
# 设置是否暴露端点 默认只有health和info可见
exposure:
# 包括所有端点
include: health,info
# 排除端点
exclude: shutdown
endpoint:
health:
show-details: always
#可以关闭指定的端点
shutdown:
enabled: false
# 配置端口号
server:
port: 8888
浏览器访问
地址 - health
# GET请求
http://127.0.0.1:8888/actuator/health
返回结果
{
"status": "UP",
"components": {
"diskSpace": {
"status": "UP",
"details": {
"total": 499963174912,
"free": 296437084160,
"threshold": 10485760,
"exists": true
}
},
"ping": {
"status": "UP"
}
}
}