Sub topic 3
Reading and Configuring the Health Endpoint
This chapter assumes you have a Spring Boot application with spring-boot-starter-actuator on the classpath. It also assumes you know how to expose endpoints over HTTP with management.endpoints.web.exposure.include, and that you can read basic YAML configuration and JSON. The chapter covers how the health endpoint builds its answer, how to control the detail it reveals, and the common mistakes teams make with it.
What the health endpoint reports
The health endpoint answers one question: is this application able to do its job? Load balancers, orchestrators, and monitoring systems call it to decide whether to send traffic, restart a process, or raise an alert.
By default, GET /actuator/health returns a minimal body:
{
"status": "UP"
}That single field is an aggregate. Spring Boot collects many smaller checks, called health contributors, and combines their results into one overall status. Each contributor is usually a HealthIndicator bean. Boot registers indicators automatically when the matching infrastructure is present. For example, a DataSource bean produces a db component, a Redis connection produces redis, and the file system produces diskSpace.
Configuring how much detail is shown
The default response hides the components, because details can leak information such as database product names, disk sizes, or hostnames. Two properties control this behavior.
management:
endpoint:
health:
show-details: when-authorized
show-components: when-authorized
roles: ACTUATORThe show-details property accepts three values:
| Value | Behavior |
|---|---|
| `never` | Details are never shown. This is the default. |
| `when-authorized` | Details are shown only to authenticated users who have one of the configured roles. |
| `always` | Details are shown to every caller, including anonymous ones. |
The roles property lists the roles that count as authorized. If you leave it empty, any authenticated user qualifies. The show-components property works the same way but only shows component names and statuses, without the detail maps. If it is not set, it follows show-details.
With show-details: always, the response looks like this:
{
"status": "UP",
"components": {
"db": {
"status": "UP",
"details": {
"database": "PostgreSQL",
"validationQuery": "isValid()"
}
},
"diskSpace": {
"status": "UP",
"details": {
"total": 250685575168,
"free": 98234187776,
"threshold": 10485760,
"path": "/app/.",
"exists": true
}
},
"ping": {
"status": "UP"
}
}
}How the overall status is computed
Every contributor reports a Status. Boot ships with four built-in values: UP, DOWN, OUT_OF_SERVICE, and UNKNOWN. A StatusAggregator merges the component statuses into the top-level one. The default aggregator picks the most severe status using this order, from most to least severe:
DOWNOUT_OF_SERVICEUPUNKNOWN
So one failing component turns the whole response to DOWN. A single UP is enough to outrank an UNKNOWN, which is why a component that cannot determine its state does not by itself fail the application.
HTTP status codes
Monitoring tools rarely parse JSON. Most check the HTTP status code first. Boot maps the overall status to a code:
| Status | HTTP code |
|---|---|
| `UP` | 200 |
| `UNKNOWN` | 200 |
| `DOWN` | 503 |
| `OUT_OF_SERVICE` | 503 |
You can change this mapping if a tool requires it. The property takes a status name and a code:
management:
endpoint:
health:
status:
http-mapping:
DOWN: 500
OUT_OF_SERVICE: 503You can also change the severity order, which is useful if you define a custom status such as DEGRADED:
management:
endpoint:
health:
status:
order: DOWN,OUT_OF_SERVICE,DEGRADED,UP,UNKNOWNA custom status name must appear in order, otherwise the aggregator cannot rank it. If you define one, add an http-mapping entry as well, or it falls back to 200.
Enabling and disabling individual indicators
Auto-configured indicators can be switched off one at a time. The property name uses the indicator's key, which is the bean name without the HealthIndicator suffix.
management:
health:
redis:
enabled: false
diskspace:
enabled: falseTo turn them all off and enable only the ones you want, set the default first:
management:
health:
defaults:
enabled: false
db:
enabled: trueDisabling an indicator removes it from the aggregate. This is the correct fix when a non-critical dependency keeps marking the whole application DOWN.
Reading a single component
Each contributor is also addressable by path. This lets a monitor target one dependency:
curl -s http://localhost:8080/actuator/health/dbThe response contains only that component:
{
"status": "UP",
"details": {
"database": "PostgreSQL",
"validationQuery": "isValid()"
}
}The same show-details rules apply. An unauthorized caller receives only the status.
Time and caching behavior
Health indicators run on every request. A slow indicator therefore makes the endpoint slow, and a monitoring system that polls every few seconds can multiply the load on the dependency being checked. Two defenses exist.
First, keep indicator work cheap. Use a lightweight query such as a validation call, not a business query.
Second, the endpoint caches results for a short period. The management.endpoint.health.cache.time-to-live property sets how long a computed result is reused, and it defaults to 0ms, meaning no caching. Raising it protects the dependency from frequent polling:
management:
endpoint:
health:
cache:
time-to-live: 10sThe trade-off is staleness. With a ten second time to live, a failure can go unnoticed for up to ten seconds.
Reactive applications
In a WebFlux application, Boot uses ReactiveHealthIndicator and returns a Mono<Health>. The aggregation, properties, and status codes behave the same. Reactive and blocking indicators can coexist, and Boot adapts them so both appear in the same response.
Common mistakes
- Treating a disk or cache warning as a reason to restart.
diskSpaceturningDOWNreturns 503. If an orchestrator restarts the application on that signal, a full disk causes a restart loop that does not fix the disk. Keep restart decisions separate from dependency checks. The next chapters on health groups and probes cover how. - Exposing details publicly. Anonymous
show-details: alwaysleaks internal information, as the warning above explains. - Heavy indicators. A check that runs a large query turns every poll into load on the database.
- Forgetting that the status order matters. A custom status that is not listed in
orderis not ranked, so the aggregate may not behave as you expect. - Assuming
UNKNOWNmeans failure. It maps to 200 by default. If you want unknown states to fail checks, change thehttp-mapping.
Checking your configuration
A quick way to verify the effect of each setting is to call the endpoint with and without credentials.
# Anonymous caller: status only when show-details is when-authorized
curl -i http://localhost:8080/actuator/health
# Authenticated caller with the ACTUATOR role: full details
curl -i -u monitor:secret http://localhost:8080/actuator/healthCompare the bodies and the status line. Then stop a dependency, such as the database, and confirm the response changes to DOWN with HTTP 503. This failure test is worth running once for every dependency you rely on, because it proves the check is actually wired in.
Exercise
Your application shows "status": "UP" to anonymous users and a full components tree to users with the ACTUATOR role. Which two properties produce this behavior, and what values do they need? Then explain what the overall HTTP status will be if the redis component reports DOWN while db and diskSpace report UP.
Show answer
Set management.endpoint.health.show-details to when-authorized and management.endpoint.health.roles to ACTUATOR. Anonymous callers then see only the aggregate status, while authenticated users with that role see the components and details. When redis reports DOWN, the aggregator picks the most severe status, so the overall status is DOWN and the HTTP status code is 503, even though db and diskSpace are UP.
Exercise
A non-critical recommendation service is checked by a custom indicator. When it fails, your load balancer removes the whole application from rotation because the health endpoint returns 503. Name two ways to stop this from happening using the settings in this chapter.
Show answer
Disable the indicator with management.health.<key>.enabled: false so it no longer feeds the aggregate, or change the status the indicator reports to a custom status such as DEGRADED, add it to management.endpoint.health.status.order, and map it to 200 with management.endpoint.health.status.http-mapping.DEGRADED: 200. In both cases a failure of that service no longer produces a 503 for the whole application.