【发布时间】:2015-08-24 12:50:29
【问题描述】:
当我从 Spring Boot 应用程序 (1.2.4.RELEASE) 访问 /health 端点时,它返回的状态为 DOWN:
{
status: "DOWN"
}
是否有任何已知会覆盖状态的启动项目或库?是否有任何其他原因(除了编写自定义的)为什么会返回DOWN?
【问题讨论】:
标签: spring-boot
当我从 Spring Boot 应用程序 (1.2.4.RELEASE) 访问 /health 端点时,它返回的状态为 DOWN:
{
status: "DOWN"
}
是否有任何已知会覆盖状态的启动项目或库?是否有任何其他原因(除了编写自定义的)为什么会返回DOWN?
【问题讨论】:
标签: spring-boot
在您的 Spring 属性中,设置 endpoints.health.sensitive = false。然后,/health 端点将返回各种健康指标的列表,您可以从那里进行调试。
对于生产环境,您应该围绕/health 端点启用安全性。
编辑
正如文森特在下面指出的,如果健康端点是安全的,您还需要management.security.enabled = false,这似乎是最新版本的 Spring Boot 中的默认设置。
我看到的 Spring Boot 开箱即用的一个常见问题是它自动配置 Solr,并且在没有额外配置的情况下,/health 端点表明 Solr 是 DOWN。解决此问题的一种简单方法是使用以下注释禁用 Application.java 中的 Solr 自动配置:
@SpringBootApplication(exclude={SolrAutoConfiguration.class})
【讨论】:
如果健康 url 显示“DOWN”或 HTTP 503 - Service Unavailable 错误,请尝试在 application.properties
中添加以下属性网址 - http://localhost:8080/actuator/health
management.endpoint.health.show-details=always
现在 url 应该显示的不仅仅是 DOWN。 如果 Solr 主机不可访问,则使用以下排除项忽略 Solr 检查 -
@SpringBootApplication(exclude = { SolrAutoConfiguration.class })
现在应该恢复健康了。运行状况检查基本上在内部验证预定义的运行状况检查(例如 - DataSourceHealthIndicator, DiskSpaceHealthIndicator, CassandraHealthIndicator 等)。
如果其中一个运行状况指标下降,则运行状况将下降,您可以在将上述属性添加到 application.properties 后看到错误作为响应。
【讨论】:
就我而言,我需要两个这些属性来获取更多详细信息:
endpoints.health.sensitive: false
management.security.enabled: false
否则,我得到的只是 DOWN 状态。
我遇到了 RabbitMQ 连接问题:我的应用程序尚未使用它,但我们已经开始连接一些与它相关的代码。该应用程序运行良好,但我们的健康状态为 DOWN,这非常令人费解:Spring Boot 在日志中出奇地安静,因为启动时没有显示错误(我可能需要更改我的配置以使其更详细)
【讨论】:
我在 Springboot 2.1.0 中遇到了同样的问题,其中 /actuator/health 返回
{
status: "DOWN"
}
即使应用程序已启动。
添加
management.health.defaults.enabled=false
到属性文件修复了这个问题。
【讨论】:
你们可能正在使用 Consul 1.0。在 Spring 中,Consul 1.0 可能存在一个已知问题 Consul 1.1.0 左右。看到这个 - https://github.com/spring-cloud/spring-cloud-consul/issues/365 和这个 - https://github.com/hashicorp/consul/issues/3635
您必须升级到 Spring 可以 Consul 1.3.0.RELEASE。
【讨论】:
根据这个链接:https://github.com/indrabasak/spring-consul-example/blob/master/client/README.md,我们应该严格使用下面的属性以避免下面的错误。
management.security.enabled=false
management.health.consul.enabled=false
【讨论】:
对于springboot 2.3.2及以上版本只需添加
【讨论】:
我使用下面的代码解决了这个问题。
编写了一个接受“/private/health”映射的控制器(您可以改用/health)。
import io.swagger.annotations.Api;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
@Api(value = "Heath Service Health", description = "Heath Service Health")
public class HeathController {
@GetMapping(value = "/private/health")
@ResponseStatus(HttpStatus.OK)
HealthStatusDto healthCheck() {
return HealthStatusDto.builder().status("UP").build();
}
}
以下等级是可选的。您可以将任何其他消息作为字符串返回,而不是在上面的控制器中返回 HealthStatusDto。
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@AllArgsConstructor
@Builder
public final class HealthStatusDto {
private final String status;
}
在 application.yml 中添加下面的配置
# actuator
# Disable Spring security
management:
security:
enabled: false
# Disable actuators
endpoints:
actuator:
enabled: false
enabled: false
希望对你有帮助
【讨论】:
我构建了一个过滤器来记录失败时的健康响应。
package br.gov.go.sspj.k9.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class BadHealthCheckLogFilter implements Filter {
private @Autowired HealthMvcEndpoint hme;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if (req.getRequestURI().endsWith("/health") && res.getStatus() != 200)
log.error(hme.invoke(req, null).toString());
}
@Override
public void init(FilterConfig filterConfig) {
}
@Override
public void destroy() {
}
}
【讨论】:
如果您刚刚添加了端点并且它已关闭,则可能某些默认检查已关闭,请参阅link 以查看默认检查的内容。在我的情况下,我忘记运行弹性,所以运行状况检查报告“down”,正如 Rashmi 指出的,您可以通过 management.health.defaults.enabled=false 禁用默认值,但最好找到真正的原因
【讨论】:
management.endpoint.health.show-details=,它总是有助于调试 Health is DOWN 的原因,它帮助我解决了我的问题。
【讨论】:
当我将应用程序从 spring boot 1.5 升级到 2.3.5.RELEASE 时,我遇到了同样的问题。
添加endpoints.health.sensitive 和application.properties 的其他答案中提到的其他属性对我不起作用。
我通过排除 RabbitAutoConfiguration 解决了这个问题。
@EnableAutoConfiguration(exclude = { RabbitAutoConfiguration.class })
【讨论】:
就我而言,Spring (v2.1.5.RELEASE)
endpoints.actuator.enabled=true management.health.defaults.enabled=false
添加上述属性解决了我的问题。
给予状态“UP”
【讨论】: