英文:
Is there a standard way in Spring Boot Actuators of checking the health of child services?
问题
以下是要翻译的内容:
假设我有一个依赖(调用)Spring Boot服务B的Spring Boot服务A。
A -> B
Spring Boot Actuators可以告诉我A是否正常运行。
https://A/health
我想知道的是通过调用A来检查B是否正常运行。
https://A/integratedhealth
我的问题是:在Spring Boot Actuators中,是否有标准的方法来检查子服务的健康状态?
(还是我必须构建一个自定义的执行器服务?)
英文:
Suppose I have Spring Boot service A which depends on (calls) Spring Boot service B.
A -> B
Spring Boot Actuators can tell me if A is up.
https://A/health
What I want to know is if B is up, by calling A.
https://A/integratedhealth
My question is: Is there a standard way in Spring Boot Actuators of checking the health of child services?
(or do I just have to build a custom actuator service?)
答案1
得分: 1
Spring Boot提供了许多开箱即用的健康指标。但是,您可以通过实现HealthIndicator
接口(对于响应式应用程序,使用ReactiveHealthIndicator
)来添加自定义健康指标:
@Component
public class ServiceBHealthIndicator implements HealthIndicator {
private final String message_key = "Service B";
@Override
public Health health() {
if (!isRunningServiceB()) {
return Health.down().withDetail(message_key, "Not Available").build();
}
return Health.up().withDetail(message_key, "Available").build();
}
private Boolean isRunningServiceB() {
Boolean isRunning = true;
// 在这里添加您的逻辑
return isRunning;
}
}
如果将其与之前的健康指标等组合,您可以获得类似以下方式的健康端点响应:
{
"status":"DOWN",
"details":{
"serviceB":{
"status":"UP",
"details":{
"Service B":"Available"
}
},
"serviceC":{
"status":"DOWN",
"details":{
"Service C":"Not Available"
}
}
}
}
您可以在Spring Boot文档中找到有关自定义健康检查和端点的更多信息。
英文:
Spring boot provides a lot of Health Indicators out of the box. However, you can add your own custom health indicator by implementing HealthIndicator
interface (ReactiveHealthIndicator
for reactive apps):
@Component
public class ServiceBHealthIndicator implements HealthIndicator {
private final String message_key = "Service B";
@Override
public Health health() {
if (!isRunningServiceB()) {
return Health.down().withDetail(message_key, "Not Available").build();
}
return Health.up().withDetail(message_key, "Available").build();
}
private Boolean isRunningServiceB() {
Boolean isRunning = true;
// Your logic here
return isRunning;
}
}
If you combine it with other health indicators like the one before, you can get a health endpoint response in a way like this:
{
"status":"DOWN",
"details":{
"serviceB":{
"status":"UP",
"details":{
"Service B":"Available"
}
},
"serviceC":{
"status":"DOWN",
"details":{
"Service C":"Not Available"
}
}
}
}
You can find more information about custom health checks and endpoints in the spring boot documentation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论