【问题标题】:How to get the global health status actuator springboot 1.5.3如何获取全局健康状态执行器spring boot 1.5.3
【发布时间】:2020-10-30 12:24:15
【问题描述】:

我在我的应用程序中使用 SpringBoot v 1.5.3,并添加了执行器 health、信息和指标,它们使用可用的端点运行良好。 我需要获取我的应用程序的全局运行状况

这是我的代码:

package com.test.health.indicator;


import java.util.Collections;
import org.springframework.boot.actuate.endpoint.HealthEndpoint;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;
import org.springframework.boot.actuate.health.Status;

@Component
public class healthContributorToInfo implements InfoContributor {
     private HealthEndpoint healthEndpoint;
    
    
    @Override
    public void contribute(Info.Builder builder) {
        
        Health health = ((HealthIndicator) this.healthEndpoint).health();
        Status status = health.getStatus();

        
        builder.withDetail("Health Indicator",
                Collections.singletonMap("Global Satatus", Health.status(status.getCode())));
    }
}

不幸的是,我的代码返回 null 异常,因为我没有得到健康状态对象。 有人可以知道如何做到这一点。 谢谢!

【问题讨论】:

  • 您希望如何为healthEndpoint 赋值?
  • 是的,我想做的是获取健康执行器的状态,是的,对于您的问题,我除了获取此信息外..但我不知道该怎么做..在下面这段代码中,我得到了空异常,这意味着我没有得到我想要的。

标签: java spring spring-boot spring-boot-actuator spring-actuator


【解决方案1】:

private HealthEndpoint healthEndpoint; 可能为空?它是如何在组件中设置/注入的?我没有看到任何可以为其设置值的构造函数。

【讨论】:

    【解决方案2】:

    我认为以下行给出了 NPE,因为您没有注入 HealthEndPoint 的依赖项。

        Health health = ((HealthIndicator) this.healthEndpoint).health();
    

    您能否尝试自动装配或为 HealthEndPoint 进行构造函数注入,看看是否可行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      • 1970-01-01
      • 2018-03-03
      相关资源
      最近更新 更多