我正在使用 Spring Boot Actuator 来返回应用程序的运行状况。
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"
}
}
我想返回类似于下面的响应
{status: "Healthy"}
有办法做到吗?
要自定义状态消息,有一种方法,名为:withDetail()
。所以当你写作的时候return Health.up().build();
只需将其替换为
return Health.up().withDetail("My Application Status","Healthy")
所以这会给
{My Application Status: "Healthy"}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)