Spring 引导执行器运行状况正在恢复 DOWN

Spring Boot Actuator Health Returning DOWN

当我从 Spring 引导应用程序 (1.2.4.RELEASE) 访问 /health 端点时,它 return 处于 DOWN 状态:

{
    status: "DOWN"
}

是否有任何已知会覆盖状态的起始项目或库?还有其他原因(除了编写自定义的)为什么会 return DOWN?

在您的 Spring 属性中,设置 endpoints.health.sensitive = false/health 端点将 return 各种健康指标列表,您可以从那里进行调试。

对于生产环境,您应该围绕 /health 端点启用安全性。

编辑

正如文森特在下面指出的那样,如果健康端点是安全的,您还需要 management.security.enabled = false,这似乎是 Spring Boot 的最新版本中的默认设置。

我在开箱即用 Spring 时看到的一个常见问题是它会自动配置 Solr,并且在没有额外配置的情况下 /health 端点表明 Solr 是 DOWN.解决此问题的一种简单方法是使用此注释在 Application.java 中禁用 Solr 自动配置: @SpringBootApplication(exclude={SolrAutoConfiguration.class})

在我的例子中,我需要这两个属性来获取更多详细信息:

endpoints.health.sensitive: false
management.security.enabled: false

否则,我得到的只是一个 DOWN 状态。

我遇到了 RabbitMQ 连接问题:我的应用程序尚未使用它,但我们已经开始连接一些与之相关的代码。该应用程序运行良好,但我们的运行状况为 DOWN,这非常令人费解:Spring 日志中的引导出奇地安静,因为启动时没有显示任何错误(我可能需要更改我的配置才能做到这一点更详细)

你们可能正在使用 Consul 1.0。 Spring Could Consul 1.1.0 或 Consul 1.0 中存在一个已知问题。看到这个 - https://github.com/spring-cloud/spring-cloud-consul/issues/365 and this - https://github.com/hashicorp/consul/issues/3635

您必须升级到 Spring Could Consul 1.3。0.RELEASE。

根据这个 link : https://github.com/indrabasak/spring-consul-example/blob/master/client/README.md,我们应该严格使用下面的属性来避免下面的错误。

management.security.enabled=false
management.health.consul.enabled=false

我使用以下代码解决了这个问题。

编写了一个接受“/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();
  }
}

以下class可选。除了在上面的控制器中 returning HealthStatusDto 之外,您还可以 return 任何其他消息作为字符串。

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

希望对您有所帮助

如果运行状况 url 显示 "DOWN" 或 HTTP 503 - 服务不可用错误,请尝试在 [= 中添加以下 属性 33=]

URL - http://localhost:8080/actuator/health

management.endpoint.health.show-details=always

现在 url 应该显示的不仅仅是向下。 如果无法访问 Solr 主机,则使用以下排除项忽略 Solr 检查 -

@SpringBootApplication(exclude = { SolrAutoConfiguration.class })

现在健康应该出现了。健康检查基本上在内部验证预定义的健康检查(示例 - DataSourceHealthIndicator, DiskSpaceHealthIndicator, CassandraHealthIndicator 等)。

如果其中一个健康指标下降,则健康状况将下降,您可以在将上述 属性 添加到 [ 后看到错误作为响应=33=].

我构建了一个过滤器来记录失败时的健康响应。

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() {
  }
}

我在 Springboot 2.1.0 中遇到了同样的问题,其中 /actuator/health 返回了 { status: "DOWN" } 即使应用程序已启动。 添加 management.health.defaults.enabled=false 属性文件解决了这个问题。

如果您刚刚添加了端点并且它已关闭,请检查可能某些默认检查已关闭,请参阅 link 查看默认检查的内容。在我的例子中,我忘记了 运行 elastic,所以健康检查报告 "down" 正如 Rashmi 指出的那样,你可以通过 management.health.defaults.enabled=false 禁用默认值,但最好找到 [=] 的实际原因12=]

management.endpoint.health.show-details=,它总是有助于调试健康状况下降的原因,它帮助我解决了我的问题。

我将应用程序从 spring boot 1.5 升级到 2.3 时遇到了同样的问题。5.RELEASE。

添加 endpoints.health.sensitiveapplication.properties 的其他答案中提到的其他属性对我不起作用。

我通过排除 RabbitAutoConfiguration 解决了这个问题。

@EnableAutoConfiguration(exclude = { RabbitAutoConfiguration.class })

对于Spring Boot 2.3.2 及更高版本只需添加

  1. management.health.defaults.enabled=false 解决了我的问题。
  2. 现在 /management/health 击中相同的 API return“UP”

就我而言,Spring (v2.1.5.RELEASE)

endpoints.actuator.enabled=真 management.health.defaults.enabled=假

添加以上属性解决了我的问题。

给出状态“UP”