【发布时间】: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