Skip to content

Commit c5fd04b

Browse files
author
YunaiV
committed
增加 actuate 示例
1 parent 66ec3e1 commit c5fd04b

File tree

13 files changed

+193
-5
lines changed

13 files changed

+193
-5
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
* [《芋道 Spring Boot 安全框架 Spring Security 入门》](http://www.iocoder.cn/Spring-Boot/Spring-Security/?github) 对应 [lab-01](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-01)
3939
* [《芋道 Spring Boot 授权框架 Spring Security OAuth2 入门》](http://www.iocoder.cn/Spring-Security/OAuth2-learning/?github) 对应 [lab-02](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-02)
40-
* 《芋道 Spring Boot Shiro 入门》计划中...
40+
* [《芋道 Spring Boot 安全框架 Shiro 入门》](http://www.iocoder.cn/Spring-Boot/Shiro/?github) 对应 [lab-33](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-33)
4141

4242
## 定时任务与异步任务
4343

@@ -51,6 +51,10 @@
5151
* [《芋道 Spring Boot 消息队列 RabbitMQ 入门》](http://www.iocoder.cn/Spring-Boot/RabbitMQ/?github) 对应 [lab-04](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-04)
5252
* [《芋道 Spring Boot 消息队列 ActiveMQ 入门》](http://www.iocoder.cn/Spring-Boot/ActiveMQ/?github) 对应 [lab-32](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-32)
5353

54+
## 监控管理
55+
56+
57+
5458
## 性能测试
5559

5660
* [《性能测试 —— Tomcat、Jetty、Undertow 基准测试》](http://www.iocoder.cn/Performance-Testing/Tomcat-Jetty-Undertow-benchmark/?github) 对应 [lab-05](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-05)
@@ -65,10 +69,6 @@
6569

6670
如下是草稿目录,未来需要整理下
6771

68-
# lab-01
69-
70-
71-
7272
# lab-05
7373

7474
TODO
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.2.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>lab-34-actuator-demo-health</artifactId>
14+
15+
<dependencies>
16+
<!-- 实现对 Spring MVC 的自动化配置 -->
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
22+
<!-- 实现对 Actuator 的自动化配置 -->
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-actuator</artifactId>
26+
</dependency>
27+
</dependencies>
28+
29+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.iocoder.springboot.lab34.actuatordemo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cn.iocoder.springboot.lab34.actuatordemo.actuate;
2+
3+
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
4+
import org.springframework.boot.actuate.health.Health;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class DemoHealthIndicator extends AbstractHealthIndicator {
9+
10+
@Override
11+
protected void doHealthCheck(Health.Builder builder) {
12+
// 较差是否健康
13+
boolean success = checkSuccess();
14+
15+
// 如果健康,则标记状态为 UP
16+
if (success) {
17+
builder.up().build();
18+
return;
19+
}
20+
21+
// 如果不健康,则标记状态为 DOWN
22+
builder.down().withDetail("msg", "我就是做个示例而已");
23+
}
24+
25+
private boolean checkSuccess() {
26+
return false;
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
management:
2+
endpoint:
3+
# Health 端点配置项,对应 HealthProperties 配置类
4+
health:
5+
enabled: true # 是否开启。默认为 true 开启。
6+
show-details: ALWAYS # 何时显示完整的健康信息。默认为 NEVER 都不展示。可选 WHEN_AUTHORIZED 当经过授权的用户;可选 ALWAYS 总是展示。
7+
status:
8+
http-mapping: # 设置不同健康状态对应的响应状态码
9+
DOWN: 403
10+
health:
11+
# DiskSpaceHealthIndicator 配置项,对应 DiskSpaceHealthIndicatorProperties
12+
diskspace:
13+
enabled: true # 是否开启。默认为 true 开启。
14+
path: . # 目录。默认为 . 当前目录。
15+
threshold: # 剩余空间的阀值。默认为 10M 。
16+
endpoints:
17+
# Actuator HTTP 配置项,对应 WebEndpointProperties 配置类
18+
web:
19+
base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuator
20+
exposure:
21+
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
22+
exclude: # 在 include 的基础上,需要排除的端点。通过设置 * ,可以排除所有端点。
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
management:
2+
endpoint:
3+
# Health 端点配置项,对应 HealthProperties 配置类
4+
health:
5+
enabled: true # 是否开启。默认为 true 开启。
6+
show-details: ALWAYS # 何时显示完整的健康信息。默认为 NEVER 都不展示。可选 WHEN_AUTHORIZED 当经过授权的用户;可选 ALWAYS 总是展示。
7+
status:
8+
http-mapping: # 设置不同健康状态对应的响应状态码
9+
DOWN: 403
10+
health:
11+
# DiskSpaceHealthIndicator 配置项,对应 DiskSpaceHealthIndicatorProperties
12+
diskspace:
13+
enabled: true # 是否开启。默认为 true 开启。
14+
path: . # 目录。默认为 . 当前目录。
15+
threshold: # 剩余空间的阀值。默认为 10M 。
16+
endpoints:
17+
# Actuator HTTP 配置项,对应 WebEndpointProperties 配置类
18+
web:
19+
base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuator
20+
exposure:
21+
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
22+
exclude: # 在 include 的基础上,需要排除的端点。通过设置 * ,可以排除所有端点。
23+

lab-34/lab-34-actuator-demo/pom.xml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.2.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>lab-34-acturator-demo</artifactId>
14+
15+
<dependencies>
16+
<!-- 实现对 Spring MVC 的自动化配置 -->
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
22+
<!-- 实现对 Actuator 的自动化配置 -->
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-actuator</artifactId>
26+
</dependency>
27+
</dependencies>
28+
29+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.iocoder.springboot.lab34.actuatordemo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
management:
2+
endpoints:
3+
# Actuator HTTP 配置项,对应 WebEndpointProperties 配置类
4+
web:
5+
base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuator
6+
exposure:
7+
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
8+
exclude: # 在 include 的基础上,需要排除的端点。通过设置 * ,可以排除所有端点。

lab-34/pom.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>labs-parent</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-34</artifactId>
13+
<packaging>pom</packaging>
14+
<modules>
15+
<module>lab-34-actuator-demo</module>
16+
<module>lab-34-actuator-demo-health</module>
17+
</modules>
18+
19+
20+
</project>

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<module>lab-31</module>
4343
<module>lab-32</module>
4444
<module>lab-33</module>
45+
<module>lab-34</module>
4546
</modules>
4647

4748

0 commit comments

Comments
 (0)