Spring Boot Actuator - 自定义健康端点 [英] Spring Boot Actuator - Custom Health Endpoint
本文介绍了Spring Boot Actuator - 自定义健康端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 SpringBoot Actuator 来返回应用的运行状况.
I am using SpringBoot Actuator to return health of the app.
public class HealthMonitor implements HealthIndicator {
@Override
public Health health() {
int errorCode = check();
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
public int check() {
return 0;
}
}
我看到下面的回复
{
"status": "UP",
"diskSpace": {
"status": "UP",
"free": 55020113920,
"threshold": 10485760
},
"db": {
"status": "UP",
"database": "Oracle",
"hello": "Hello"
}
}
我想返回类似于下面的响应
I want to return a response similar to below
{status: "Healthy"}
有办法吗?
推荐答案
要自定义您的状态消息,有一种名为:withDetail()
的方法.因此,当您编写 return Health.up().build();
时,只需将其替换为
To customize your Status message there is one method named: withDetail()
. So when you are writing return Health.up().build();
just replace this with
return Health.up().withDetail("My Application Status","Healthy")
所以这会给
{My Application Status: "Healthy"}
这篇关于Spring Boot Actuator - 自定义健康端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文