Spring Boot Actuator
- 配置文件的读取
- 自动装配
Spring Boot Actuator
为生产准备的特性。当你发布应用的试试,Spring Boot 包含一堆特性来帮助你监控和管理应用。你选择通过Http
端点或者JMX
来管理和监控你的应用。审计、健康和度量收集自动装配到你的应用。
启用Spring Boot Actuator
加入maven依赖即可
1 |
|
端点
端点列表
JMX
和Web
是对应的ID默认启用状态
ID | 描述 | JMX |
Web |
---|---|---|---|
auditevents |
暴露当前应用的审计事件信息,需要AuditEventRepository 的Bean |
Yes | No |
beans |
显示当前应用的完整的Bean 列表 |
Yes | No |
caches |
暴露可获取的缓存 | Yes | No |
conditions |
显示装配或者自动装配成功或者失败的条件 | Yes | No |
configprops |
显示@ConfigurationProperties 的列表 |
Yes | No |
env |
暴露ConfigurableEnvironment 的配置信息 |
Yes | No |
flyway |
显示应用的任意数据库迁移,需要Flyway 的Bean |
Yes | No |
health |
显示应用的健康信息 | Yes | Yes |
httptrace |
显示Http 调用信息(默认显示最后100个http 请求响应),需要HttpTraceRepository 的bean |
Yes | No |
info |
显示任意应用信息 | Yes | Yes |
intergationgraph |
显示Spring 聚合图表,需要spring-integration-core 依赖 |
Yes | No |
loggers |
显示和修改应用的日志配置 | Yes | No |
liquibase |
显示应用的任意数据库迁移,需要Liquibase 的Bean |
Yes | No |
metrics |
显示当前的应用的度量指标 | Yes | No |
mappings |
显示@RequestMapping 列表 |
Yes | No |
scheduledtasks |
显示定时任务列表 | Yes | No |
shutdown |
优雅地关闭应用,默认是关闭的 | Yes | No |
theaddump |
执行线程转存 | Yes | No |
若是web应用的话,还有以下端点
ID | 秒速 | JMX |
Web |
---|---|---|---|
sessions |
允许检索和删除用户session信息,需要一个Servlet web应用 |
Yes | No |
heapdump |
返回一个hprof 的堆转存文件 |
N/A | No |
jolokia |
通过http 暴露JMX 的Bean ,需要jolokia-core ,在WebFlux 不可用 |
N/A | No |
logfile |
返回日志文件的内容(需要配置logging.file.name 和logging.file.path ),支持http 的Range 请求头来返回当前日志文件的部分信息 |
N/A | No |
promethueus |
暴露prometheus 的度量信息,需要micrometer-registry-prometheus 依赖 |
N/A | No |
启用端点
management.endpoint.<id>.enabled=true
启用对应的id的端点management.endpoints.enabled-by-default=false
默认都不启用management.endpoints.<type>.exposure.include=info,health
启用info和health端点,type
包含jms
以及web
management.endpoints.<type>.exposure.exclude=info,health
关闭info和health端点,type
包含jms
以及web
include
与exclude
所有的内容,使用*
,注意在yaml
配置*
的时候需要引号
1
2
3
4
5
management:
endpoints:
web:
exposure:
include: "*"
端点安全
Spring Boot 提供了RequestMatcher
对象联合Spring Security
使用
1 |
|
若是被Spring Security
阻止,可以设置所有放行
1 |
|
跨域配置
management.endpoints.web.cors.allowed-origins=https://example.com
跨域源management.endpoints.web.cors.allowed-methods=GET,POST
跨域访问方法
自定义实现
@Bean
上添加@EndPoint
注解,任意方法上添加@ReadOperation
、@WriteOperation
和@DeleteOperation
在JMX
以及Web
上都会暴露。若是只想暴露一种,使用@JmxEndpoint
或者@WebEndpoint
。使用@EndpointWebExtension
和@EndpointJmxExtension
在已经暴露的端点上添加参数。使用Servlet
或者Spring注解@Controller
和@RestController
来禁止JMX
或者其他的web
环境。
健康信息配置
management.endpoint.health.show-details=never
默认不显示详情信息when-authorized
认证信息,配置management.endpoint.health.roles
进行配置,默认的话所有认证的用户都有权限always
所有用户都显示
management.endpoint.health.show-components
management.health.defaults.enabled
关闭健康检查信息
自定义健康检查信息
Reative
健康检查信息
Spring Boot Actuator
http://example.com/2019/12/23/SpringBoot/SpringBoot Actuator/