Spring Boot Actuator Health Returning DOWN

103.5k Views Asked by At

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

{
    status: "DOWN"
}

Are there any starter projects or libraries that are known to overwrite the status? Is there any other reason (besides writing a custom one) why it would return DOWN?

14

There are 14 best solutions below

2
Paul F On BEST ANSWER

In your Spring properties, set endpoints.health.sensitive = false. The /health endpoint will then return the list of various health indicators and you can debug from there.

For a production environment you should enable security around the /health endpoint.

Edit

As Vincent pointed out below, you'll also need management.security.enabled = false if the health endpoint is secured, which seems to be the default in more recent versions of Spring Boot.

A common issue that I've seen with Spring Boot out of the box is that it auto-configures Solr, and without additional configuration the /health endpoint indicates that Solr is DOWN. An easy way to fix this is to disable the Solr auto configuration in your Application.java with this annotation: @SpringBootApplication(exclude={SolrAutoConfiguration.class})

0
Vincent F On

in my case, I needed both these properties to get more details :

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

Otherwise, all I was getting was an DOWN status.

I had an issue with RabbitMQ connection : my application is not using it yet, but we've started wiring some code related to it. The application works fine, but we were getting DOWN health status, which was quite puzzling : Spring Boot is surprisingly silent in the logs, as no error shows at startup (I'll probably need to change my config to make it more verbose)

0
Jaime On

You guy are probably using Consul 1.0. There is a known issue in Spring Could Consul 1.1.0 or so with Consul 1.0. See this - https://github.com/spring-cloud/spring-cloud-consul/issues/365 and this - https://github.com/hashicorp/consul/issues/3635

You will have to upgrade to Spring Could Consul 1.3.0.RELEASE.

1
Jeff Cook On

As per this link : https://github.com/indrabasak/spring-consul-example/blob/master/client/README.md, we should strictly used below properties to avoid below error.

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

enter image description here

0
Vinayak Dornala On

I got this fixed using below code.

Wrote a controller which accepts "/private/health" mapping (You can use /health instead).

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

Below class is optional. Instead of returning HealthStatusDto in above controller you can return any other message as a String.

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@AllArgsConstructor
@Builder
public final class HealthStatusDto {
  private final String status;
}

Add below config in application.yml

# actuator
# Disable Spring security
management:
  security:
    enabled: false

# Disable actuators
endpoints:
  actuator:
    enabled: false
  enabled: false

Hope this helps

3
Arunchunaivendan On

If the health url shows "DOWN" or HTTP 503 - Service Unavailable error, then try adding the below property in application.properties

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

management.endpoint.health.show-details=always

Now the url should show more than just DOWN. If Solr host is not reachable, then ignore the Solr check using the below exclusion -

@SpringBootApplication(exclude = { SolrAutoConfiguration.class })

Now the health should come up. The health check basically validates predefined health check internally (Example - DataSourceHealthIndicator, DiskSpaceHealthIndicator, CassandraHealthIndicator, etc).

If one of the health indicator is down, the health will be down and you can see the error as a response after adding the property mentioned above to application.properties.

1
CelinHC On

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

I had the same issue with Springboot 2.1.0 where /actuator/health returned { status: "DOWN" } even though application was up. Adding management.health.defaults.enabled=false to properties file fixed the issue.

0
Atyoum Ustainof On

If you just added endpoint and it is down check maybe something of default checks is down see the link to see what is checked by default. in my case I forgot to run elastic, so health-check reported "down" as Rashmi pointed out you can disable defaults by management.health.defaults.enabled=false, but it is better to find the actual reason why

0
Ambuj Sinha On

management.endpoint.health.show-details=, it always help to debug why the Health is DOWN , it helped me resolve my issue.

0
Smile On

I got the same issue when I upgraded an application from spring boot 1.5 to 2.3.5.RELEASE.

Adding endpoints.health.sensitive and other properties as mentioned in other answers to application.properties didn't work for me.

I fixed the issue by excluding RabbitAutoConfiguration.

@EnableAutoConfiguration(exclude = { RabbitAutoConfiguration.class })

0
user3598906 On

For Spring Boot 2.3.2 and above just adding

  1. management.health.defaults.enabled=false solved my issue.
  2. Hitting the same API with /management/health now return "UP"
0
akash3699 On

In my case, Spring (v2.1.5.RELEASE)

endpoints.actuator.enabled=true management.health.defaults.enabled=false

adding above properties solved my issue .

giving status "UP"

0
Le Quang Nhan On

Setting the following configuration help me troubleshoot the problem

management.endpoint.health.show-details=always

In my case, the antivirus application is blocking connection to my mail server. Turn it off solved problem