Spring Boot Actuator Health Returning DOWN

后端 未结 12 1052
面向向阳花
面向向阳花 2021-01-31 02:49

When I access the /health endpoint from my Spring Boot application (1.2.4.RELEASE) it is returning a status of DOWN:

{
    status: \"DO         


        
12条回答
  •  野的像风
    2021-01-31 03:04

    I built a filter to log the health response when it fails.

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

提交回复
热议问题