0
如何在彈簧啓動執行器中禁用默認的mongo運行狀況檢查並創建像../manage/mongo這樣的自定義mongo運行狀況檢查url?如何在春季開機創建自定義mongo健康檢查?
如何在彈簧啓動執行器中禁用默認的mongo運行狀況檢查並創建像../manage/mongo這樣的自定義mongo運行狀況檢查url?如何在春季開機創建自定義mongo健康檢查?
application.properties
management.health.mongo.enabled =假
endpoints.mongo.enabled =真
MongoDBHealthCheckEndPoint.java
@ConfigurationProperties(prefix = "endpoints.mongo", ignoreUnknownFields = true)
@Component
public class MongoDBHealthCheckEndPoint extends AbstractEndpoint<Map<String, String>>
{
@Inject
MongoTemplate mongoTemplate;
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final Map<String, String> UP = new HashMap<String, String>() {{
put("mongo.status", "UP");
}};
private static final Map<String, String> DOWN = new HashMap<String, String>() {{
put("mongo.status", "DOWN");
}};
public MongoDBHealthCheckEndPoint() {
super("mongo", false);
}
public MongoDBHealthCheckEndPoint(Map<String, ? extends Object> mongo) {
super("mongo", false);
}
public Map<String, String> invoke() {
try {
return (new MongoHealthIndicator(mongoTemplate).health().getStatus().equals(Status.UP)) ? UP : DOWN;
} catch (Exception e) {
log.error("mongo database is down", e);
return DOWN;
}
}
}