弹簧启动器执行器健康状况恢复正常

问题描述 投票:27回答:8

当我从Spring Boot应用程序(1.2.4.RELEASE)访问/health端点时,它返回的状态为DOWN

{
    status: "DOWN"
}

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

spring-boot
8个回答
26
投票

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

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

编辑

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

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


16
投票

在我的情况下,我需要这两个属性来获取更多细节:

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

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

我遇到了RabbitMQ连接的问题:我的应用程序还没有使用它,但我们已经开始连接一些与之相关的代码。该应用程序工作正常,但我们得到DOWN健康状态,这是非常令人费解的:Spring Boot在日志中出乎意料地保持沉默,因为在启动时没有显示错误(我可能需要更改我的配置以使其更加冗长)


12
投票

如果运行状况URL显示“DOWN”或HTTP 503 - Service Unavailable错误,请尝试在application.properties中添加以下属性

网址 - http://localhost:8080/actuator/health

management.endpoint.health.show-details=always

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

@SpringBootApplication(exclude = { SolrAutoConfiguration.class })

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

如果其中一个运行状况指示器已关闭,则运行状况将关闭,您可以在将上述属性添加到application.properties后将错误视为响应。


4
投票

我有与Springboot 2.1.0相同的问题,即使应用程序启动了/ actuator / health { status: "DOWN" }。将management.health.defaults.enabled=false添加到属性文件修复了该问题。


3
投票

你的家伙可能正在使用Consul 1.0。在使用Consul 1.0的Spring Can Consul 1.1.0中有一个已知问题。看到这个 - https://github.com/spring-cloud/spring-cloud-consul/issues/365和这个 - https://github.com/hashicorp/consul/issues/3635

您将不得不升级到Spring Cloud Consul 1.3.0.RELEASE。


1
投票

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

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

enter image description here


0
投票

我使用下面的代码修复了这个问题。

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

下面的类是可选的。您可以将任何其他消息作为String返回,而不是在上面的控制器中返回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

希望这可以帮助


0
投票

我构建了一个过滤器,用于在失败时记录健康响应。

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() {
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.