介绍
Spring boot Actuator 提供了一系列的端点来监控和度量应用,包括应用上下文全部Bean信息,自动化配置报告(显示自动配置条件是否通过),配置属性信息,显示应用健康状态等。
环境
Spring Boot 2.0.3
测试
1.初始化一个Spring boot工程,添加actuator依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.添加响应的配置信息(注意:Spring Boot 2和1.x版本相比,不少配置发生修改,废弃不少1.x版本中的属性)
server:
port: 8080
# actuator监控
management:
server:
# 设置监控服务端口
port: 8081
endpoints:
# 设置端点是否可用 默认只有shutdown可用
enabled-by-default: true
web:
# 设置是否暴露端点 默认只有health和info可见
exposure:
# 包括所有端点
include: "*" # 注意需要添加引号
# 排除端点
exclude: shutdown
Spring Boot内置端点(和1.x版本相比,不少端点名称发生改变)
Web应用额外的端点:
访问端点需添加前缀/actuator,例如访问beans端点地址为/actuator/beans
/beans:获取应用上下文所有的bean信息
{
contexts: {
application: {
beans: {
endpointCachingOperationInvokerAdvisor: {
aliases: [ ],
scope: "singleton",
type: "org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor",
resource: "class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]",
dependencies: [
"environment"
]
},
defaultServletHandlerMapping: {
aliases: [ ],
scope: "singleton",
type: "org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping",
resource: "class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]",
dependencies: [ ]
},
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration: {
aliases: [ ],
scope: "singleton",
type: "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration$$EnhancerBySpringCGLIB$$4337b2d4",
resource: null,
dependencies: [
"spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties"
]
}
}
}
}
}
- aliases:Bean的别名
- scope:Bean的作用域,默认单例
- type:Bean的Java类型
- reource:class文件的具体路径
- dependencies:依赖的Bean列表
/health:显示应用程序健康信息
{
status: "UP"
}
/conditions:获取自动化配置信息,以及是否满足条件的原因
{
contexts: {
application: {
positiveMatches: {
AuditAutoConfiguration#auditListener: [
{
condition: "OnBeanCondition",
message: "@ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.listener.AbstractAuditListener; SearchStrategy: all) did not find any beans"
}
],
AuditAutoConfiguration.AuditEventRepositoryConfiguration: [
{
condition: "OnBeanCondition",
message: "@ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.AuditEventRepository;
SearchStrategy: all) did not find any beans"
}
]
},
negativeMatches: {
RabbitHealthIndicatorAutoConfiguration: {
notMatched: [
{
condition: "OnClassCondition",
message: "@ConditionalOnClass did not find required class 'org.springframework.amqp.rabbit.core.RabbitTemplate'"
}
],
matched: [ ]
},
AuditAutoConfiguration#authenticationAuditListener: {
notMatched: [
{
condition: "OnClassCondition",
message: "@ConditionalOnClass did not find required class 'org.springframework.security.authentication.event.AbstractAuthenticationEvent'"