【发布时间】:2021-09-24 15:45:12
【问题描述】:
我想知道如何调用自定义健康指标:
- 在同一个应用程序中
- 另一个 Spring Boot 应用程序
我的应用程序分为一个基本应用程序(而不是一个配置)A,它实现了几乎所有的功能(没有 main 方法)和另一个应用程序 B(有一个 main 方法;-))具有基本配置作为依赖项POM。
在 A 中,我实现了一个自定义 HealthIndicator:
@Component
@RequiredArgsConstructor
public class AdapterDownstreamHealthIndicator implements HealthIndicator {
private RestTemplate restTemplate;
private String downStreamUrl = "http://localhost:8081/actuator";
public AdapterDownstreamHealthIndicator(RestTemplate restTemplate, String downStreamUrl) {
this.restTemplate = restTemplate;
this.downStreamUrl = downStreamUrl;
}
@Override
public Health health() {
// try {
// JsonNode resp = restTemplate.getForObject(downStreamUrl + "/health", JsonNode.class);
// if (resp.get("status").asText().equalsIgnoreCase("UP")) {
// System.out.println("JUHUUUUUUUUUUU!!!!");
// return Health.up().build();
// }
// } catch (Exception ex) {
// return Health.down(ex).build();
// }
return Health.down().build();
}
}
在我的application.properties 中,我有一些执行器属性:
management.endpoints.web.exposure.include=health,info,prometheus,adapterDownstream
spring.jackson.serialization.INDENT_OUTPUT=true
management.endpoint.health.show-details=always
当我在浏览器中输入 http://localhost:9091/actuator/health/adapterDownstream 时,调试器不会在 health() 方法中停止,我只是显示一个空白页面。
我已经尝试扩展AbstractHealthIndicator,而不是实现HealthIndicator 接口。
自定义运行状况指示器无法识别,我做错了什么?
最后我想进行某种深度健康检查来测试我的应用程序中使用的所有组件。或许应该用CompositeHealthContributor???
【问题讨论】:
标签: spring-boot-actuator indicator contributor compositehealthcontributor