TExcelTAD
Home › Spring Boot › Actuator & Health Checks

Actuator & Health Checks

Once your API runs in production, operators need to know: Is it alive? Can it reach the database? How many requests fail? Which version is deployed? Spring Boot Actuator answers these questions with ready-made HTTP endpoints for health, metrics, info, loggers and more.

xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

The health endpoint

bash · try it yourself
curl -s localhost:8080/actuator/health
{"status":"UP"}

By default only health is exposed over HTTP. Expose more endpoints explicitly — never * on a public port:

properties
management.endpoints.web.exposure.include=health,info,metrics,loggers,prometheus
management.endpoint.health.show-details=when-authorized
management.endpoint.health.probes.enabled=true
management.info.env.enabled=true
info.app.description=Task tracker API

With details visible, the health response shows each health indicator. Boot adds indicators automatically for the things it finds: database, disk space, Redis, mail server and so on.

bash · try it yourself
curl -s -u admin:adm1n localhost:8080/actuator/health | jq
{
  "status": "UP",
  "components": {
    "db": {
      "status": "UP",
      "details": {
        "database": "PostgreSQL",
        "validationQuery": "isValid()"
      }
    },
    "diskSpace": {
      "status": "UP",
      "details": {
        "total": 107374182400,
        "free": 61534429184,
        "threshold": 10485760,
        "path": "/app/.",
        "exists": true
      }
    },
    "livenessState": {
      "status": "UP"
    },
    "ping": {
      "status": "UP"
    },
    "readinessState": {
      "status": "UP"
    }
  }
}

How the overall status is computed

The overall status is the "worst" status among the components, using the order DOWN > OUT_OF_SERVICE > UP > UNKNOWN. A DOWN status turns the HTTP response into 503 Service Unavailable, which load balancers understand. The aggregation in plain Java:

java · try it yourself
import java.util.*;

class Main {
    static final List<String> SEVERITY = List.of("DOWN", "OUT_OF_SERVICE", "UP", "UNKNOWN");

    static String aggregate(Map<String, String> components) {
        return components.values().stream()
                .min(Comparator.comparingInt(SEVERITY::indexOf))
                .orElse("UNKNOWN");
    }

    static int httpStatus(String status) {
        return switch (status) {
            case "DOWN", "OUT_OF_SERVICE" -> 503;
            default -> 200;
        };
    }

    public static void main(String[] args) {
        List<Map<String, String>> scenarios = List.of(
            new TreeMap<>(Map.of("db", "UP", "diskSpace", "UP", "ping", "UP")),
            new TreeMap<>(Map.of("db", "DOWN", "diskSpace", "UP", "ping", "UP")),
            new TreeMap<>(Map.of("db", "UP", "paymentApi", "OUT_OF_SERVICE")),
            new TreeMap<>(Map.of("db", "UP", "cache", "UNKNOWN")));
        for (Map<String, String> s : scenarios) {
            String overall = aggregate(s);
            System.out.printf("%-55s -> %-14s HTTP %d%n", s, overall, httpStatus(overall));
        }
    }
}
{db=UP, diskSpace=UP, ping=UP}                          -> UP             HTTP 200
{db=DOWN, diskSpace=UP, ping=UP}                        -> DOWN           HTTP 503
{db=UP, paymentApi=OUT_OF_SERVICE}                      -> OUT_OF_SERVICE HTTP 503
{cache=UNKNOWN, db=UP}                                  -> UP             HTTP 200

A custom health indicator

java
@Component
class PaymentApiHealthIndicator implements HealthIndicator {
    private final PaymentClient client;
    PaymentApiHealthIndicator(PaymentClient client) { this.client = client; }

    @Override
    public Health health() {
        try {
            long ms = client.ping();
            return Health.up().withDetail("latencyMs", ms).build();
        } catch (Exception e) {
            return Health.down(e).build();
        }
    }
}

The component appears as paymentApi (the class name minus HealthIndicator).

Liveness and readiness probes

Kubernetes asks two different questions, and Actuator provides a group for each:

Probe URL Question If it fails
liveness /actuator/health/liveness is the process healthy, or stuck? container is restarted
readiness /actuator/health/readiness can it accept traffic right now? removed from the load balancer

Don't put external dependencies (like the database) into the liveness check — a database outage would make Kubernetes restart every pod, which doesn't help.

Metrics

Actuator uses Micrometer, which records metrics such as request counts and latencies, JVM memory and connection pool usage:

bash · try it yourself
curl -s "localhost:8080/actuator/metrics/http.server.requests?tag=uri:/api/tasks&tag=status:200" | jq '.measurements'
[
  {
    "statistic": "COUNT",
    "value": 1284
  },
  {
    "statistic": "TOTAL_TIME",
    "value": 9.731
  },
  {
    "statistic": "MAX",
    "value": 0.052
  }
]

With micrometer-registry-prometheus on the classpath, /actuator/prometheus serves all metrics in Prometheus format for Grafana dashboards. Your own counters are one line:

java
meterRegistry.counter("tasks.completed", "priority", task.getPriority().name()).increment();

Info endpoint

bash · try it yourself
curl -s localhost:8080/actuator/info
{"app":{"description":"Task tracker API"},"build":{"artifact":"tasks","name":"tasks","time":"2025-10-16T04:55:02.117Z","version":"1.4.0","group":"com.example"},"git":{"branch":"main","commit":{"id":"a1b2c3d","time":"2025-10-15T16:20:44Z"}}}

build appears when the Spring Boot Maven plugin's build-info goal runs; git when the git-commit-id-maven-plugin is configured. Now you always know exactly which version is deployed.

Tip: Serve Actuator on a separate port (management.server.port=8081) that is reachable only from inside your network, and secure every endpoint except health.

Test yourself

Which Actuator endpoint is exposed over HTTP by default?

  1. All of them
  2. health only
  3. metrics and info
  4. None

The database health indicator reports DOWN. What does /actuator/health return?

  1. 200 with status UP
  2. 200 with status DOWN
  3. 503 with status DOWN
  4. 404

Which probe should NOT depend on external systems like the database?

  1. Readiness
  2. Liveness
  3. Both must
  4. Neither exists