首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用自定义DiskSpaceHealthIndicator (Spring Boot Actuator)?

使用自定义DiskSpaceHealthIndicator (Spring Boot Actuator)?
EN

Stack Overflow用户
提问于 2020-08-11 00:19:35
回答 1查看 357关注 0票数 0

我的春季application.yaml:

代码语言:javascript
复制
management:
  ...
  endpoint:
    health:
      show-details: ALWAYS
    info:
      enabled: false
  health:
    diskspace:
      path: "some-path"
      threshold: 536870912

这将使用https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.html执行运行状况检查。

我想扩展/包装org.springframework.boot.actuate.system.DiskSpaceHealthIndicator以添加一些特定于应用程序的行为。有没有办法将我的应用程序配置为使用我自己的自定义版本,例如com.acme.myapp.CustomDiskSpaceHealthIndicator而不是org.springframework.boot.actuate.system.DiskSpaceHealthIndicator

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-11 02:48:10

可以,您只需提供一个名为diskSpaceHealthIndicator的自定义DiskSpaceHealthIndicator,它将替换缺省bean

代码语言:javascript
复制
@Configuration
public class DiskSpaceHealthIndicatorConfiguration {

    @Bean
    public DiskSpaceHealthIndicator diskSpaceHealthIndicator(DiskSpaceHealthIndicatorProperties properties) {
        return new MyDiskSpaceHealthIndicator(properties.getPath(), properties.getThreshold());
    }

    private static class MyDiskSpaceHealthIndicator extends DiskSpaceHealthIndicator {

        public MyDiskSpaceHealthIndicator(File path, DataSize threshold) {
            super(path, threshold);
        }

        @Override
        protected void doHealthCheck(Builder builder) throws Exception {
            // Do whatever you need here
            super.doHealthCheck(builder);
            builder.withDetail("custom details", "whatever");
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63344032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档