Actuator
引入依赖spring-boot-starter-actuator
,通过endpoint
来暴露HTTP或JMX来监管应用
通过http://localhost:8080/actuator
,可以查看所有endpoints,eg:
/actuator/health, /actuator/info, /actuator/metrics, /actuator/loggers
/health:健康指数检查
通过management.endpoint.health.show-details=always
可以显示详细的健康信息。
实现HealthIndicator
接口,或继承AbstractHealthIndicator
类自定义健康指标
@Component
public class CustomerHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
builder.up().withDetail("xxx", "xxx xxx");
}
}
/info:应用基本信息
通过META-INF/build-info.properties
获得编译信息,通过git.properties
获得git信息
# INFO ENDPOINT CONFIGURATION
info:
app:
name: @project.name@
description: @project.description@
version: @project.version@
encoding: @project.build.sourceEncoding@
java:
version: @java.version@
Automatic Property Expansion:扩展maven工程的properties
授权访问
通过HTTP认证保护Actuator Endpoints的安全:spring-boot-starter-security