整合Spring boot Actuator
2018-04-01 18:28
309 查看
执行器端点允许你监控应用及与应用进行交互。Spring Boot包含很多内置的端点,你也可以添加自己的。例如,health端点提供了应用的基本健康信息。
端点暴露的方式取决于你采用的技术类型。大部分应用选择HTTP监控,端点的ID映射到一个URL。例如,默认情况下,health端点将被映射到/health。
下面的端点都是可用的:
ID | 描述 | 敏感(Sensitive) |
---|---|---|
autoconfig | 显示一个auto-configuration的报告,该报告展示所有auto-configuration候选者及它们被应用或未被应用的原因 | true |
beans | 显示一个应用中所有Spring Beans的完整列表 | true |
configprops | 显示一个所有@ConfigurationProperties的整理列表 | true |
dump | 执行一个线程转储 | true |
env | 暴露来自Spring ConfigurableEnvironment的属性 | true |
health | 展示应用的健康信息(当使用一个未认证连接访问时显示一个简单的'status',使用认证连接访问则显示全部信息详情) | false |
info | 显示任意的应用信息 | false |
metrics | 展示当前应用的'指标'信息 | true |
mappings | 显示一个所有@RequestMapping路径的整理列表 | true |
shutdown | 允许应用以优雅的方式关闭(默认情况下不启用) | true |
trace | 显示trace信息(默认为最新的一些HTTP请求) | true |
注:根据一个端点暴露的方式,sensitive参数可能会被用做一个安全提示。例如,在使用HTTP访问sensitive端点时需要提供用户名/密码(如果没有启用web安全,可能会简化为禁止访问该端点)。
1、Enabling EndPoints
默认情况下,除了shutdown,其它所有端点都是开放开的。以下样例可放开shutdown端点:
management.endpoint.shutdown.enabled=true禁用默认端点,只要把management.endpoints.enabled-by-default的值设置为false则可,以下样例
启动info端点而禁用其它端点:
management.endpoints.enabled-by-default=false management.endpoint.info.enabled=true2、Exposing Endpoints
端点可能包含了一些敏感信息,在生产环境中谨慎暴露这些端点。
如下样例只暴露health和info端点:
management.endpoints.jmx.exposure.include=health,info
以下样例暴露了所有端点,但禁用env和beans两个端点:
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.exclude=env,beans3、端点安全性
典型的一个安全设置如下:
@Configuration public class ActuatorSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() .anyRequest().hasRole("ENDPOINT_ADMIN") .and() .httpBasic(); } }如果希望放开所有端点的访问,则在application.properties文件中增加如下配置 :
management.endpoints.web.exposure.include=*如果已增加安全访问限制,而希望不需要授权访问,则需要做如下配置 :
@Configuration public class ActuatorSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() .anyRequest().permitAll() } }4、Health信息
以下健康信息自动加载:
Name | Description |
DiskSpaceHealthIndicator | |
DataSourceHealthIndicator | |
ElasticsearchHealthIndicator | |
InfluxDbHealthIndicator | |
JmsHealthIndicator | |
MailHealthIndicator | |
MongoHealthIndicator | |
RabbitHealthIndicator | |
RedisHealthIndicator |
5、自定义HealthIndicators
@Component public class MyHealthIndicator implements HealthIndicator { @Override public Health health() { int errorCode = check(); // perform some specific health check if (errorCode != 0) { return Health.down().withDetail("Error Code", errorCode).build(); } return Health.up().build(); } }
6、自定义Info
@Component public class ExampleInfoContributor implements InfoContributor { @Override public void contribute(Info.Builder builder) { builder.withDetail("example", Collections.singletonMap("key", "value")); } }
阅读更多
相关文章推荐
- SpringBoot系列九:SpringBoot服务整合(整合邮件服务、定时调度、Actuator监控)
- springBoot整合actuator监控配置和使用
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- 文章标题Spring Boot干货系列:(十一)数据存储篇-Spring Boot整合Mybatis通用Mapper插件
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- redis学习系列(二)--spring boot整合Redis集群
- SpringBoot整合MyBatis
- 快速搭建springboot项目并整合easymybatis
- Spring Boot整合oauth2.0搭建统一授权服务(密码模式)
- SpringBoot~整合mybatis+微服务注册
- Spring Boot WebSocket整合及nginx配置
- Spring Boot 2.0官方文档之 Actuator
- springboot整合kaptcha验证码的示例代码
- springboot整合redis,实现session共享
- Springboot整合Elastic-Job
- spring boot 1.5.9 整合redis
- SpringBoot(十二):SpringBoot整合RabbitMQ
- springboot-actuator 401 无权限
- RabbitMQ与SpringBoot整合