当前,我们正在使用Spring Boot作动器vr 1.5.10,并且可以使用/ health端点成功访问我们的健康页面。但是,在访问健康端点时,我们还需要将该健康状态记录在应用程序的日志文件中,以便稍后我们可以根据状态创建Kibana观察者警报。

我看到我们可以使用“ @EndpointWebExtension”扩展运行状况端点,并按照here中的建议在该处记录状态。但是似乎1.5.10版不支持该功能。

任何方向将不胜感激!

最佳答案

您可以编写自己的HealthAggregator并在其中设置Default Spring Aggregator并使用它。

public class OwnHealthAggregator implements HealthAggregator {

private final HealthAggregator defaultHealth;

public OwnHealthAggregator(HealthAggregator defaultHealth) {
    this.defaultHealth = defaultHealth;
}

@Override
public Health aggregate(Map<String, Health> healths) {
    Health result = this.defaultHealth.aggregate(healths);
    // LOG Result here
    return result;
}

}


定义一个bean并使用默认的bean:

@Bean
public HealthAggregator health() {
    return new OwnHealthAggregator(new OrderedHealthAggregator());
}




在此版本中使用执行器时,请注意,因为默认情况下启用了许多端点(例如/ beans,/ env,/ dump),因此请务必小心。

09-25 20:41