skip to content

Built-in Health Indicators

Boot auto-registers indicators for the datasource, disk space, Redis and more, each individually disableable. Knowing they are on by default explains why your health endpoint goes down when a cache does.

part ofSpring Frameworkoverview, primer and where to startread it →
on this pageshow

questions

6

What are Spring Boot's built-in health indicators, and which ones does Actuator auto-register out of the box?

level: juniorimportance: must knowfreq 70%

answer

  1. ping = always UP
  2. diskSpace default 10MB threshold
  3. db = DataSourceHealthIndicator
  4. show-details defaults to never
  5. overall = worst status

basics

~10 s

Built-in health indicators are checks Actuator adds automatically to the /actuator/health endpoint. Common ones: PingHealthIndicator (always up), DiskSpaceHealthIndicator (free disk), DataSourceHealthIndicator (database), and RedisHealthIndicator when those libraries are present.

solid answer

~30 s

Spring Boot Actuator auto-configures a set of HealthIndicator beans that report component health at /actuator/health. Always present is PingHealthIndicator (a trivial 'app is alive' check) and DiskSpaceHealthIndicator (fails when free space drops below a threshold). Others are conditional on what's on the classpath and configured: DataSourceHealthIndicator (registered under the name 'db') runs a validation query against your DataSource; RedisHealthIndicator issues an INFO command to Redis. Each contributes a status (UP/DOWN/etc.) plus optional details. The overall endpoint status is the worst of all contributors. By default the endpoint shows only the top-level status; you enable per-component detail with management.endpoint.health.show-details=always (or when-authorized).

code

java · 14 lines
java
// application.properties
// Reveal per-component health in the endpoint body
// management.endpoint.health.show-details=always

// Example /actuator/health response with details on:
// {
//   "status": "UP",
//   "components": {
//     "db":        { "status": "UP", "details": { "database": "PostgreSQL", "validationQuery": "isValid()" } },
//     "diskSpace": { "status": "UP", "details": { "total": 500107862016, "free": 250053931008, "threshold": 10485760 } },
//     "ping":      { "status": "UP" },
//     "redis":     { "status": "UP", "details": { "version": "7.2.4" } }
//   }
// }

go deeper

for a junior

Know the four named indicators exist and that /health aggregates them; know show-details must be enabled to see components.

for a middle

Explain conditional registration by classpath, the naming scheme (db, diskSpace, ping, redis), and worst-status aggregation.

for a senior

Discuss show-details security tradeoffs (when-authorized), HTTP status mapping to 503, and how indicators feed probes.

for a principal

Frame health as an operational contract for orchestrators/LBs; reason about which checks belong in liveness vs readiness and blast radius of a DOWN dependency.

## What a health indicator is Spring Boot **Actuator** exposes an operational endpoint at `/actuator/health`. Its job is to answer 'is this application and its dependencies healthy?' The endpoint aggregates many **HealthIndicator** beans, each of which checks one thing (the database, disk, Redis, etc.) and returns a **Health** object carrying a **Status** (`UP`, `DOWN`, `OUT_OF_SERVICE`, `UNKNOWN`) plus an optional map of details. ## Which ones are auto-registered Actuator auto-configures indicators based on what's on the classpath (this is the whole point of Spring Boot auto-configuration — beans appear only when their supporting libraries and beans exist): - **PingHealthIndicator** — always registered. It does nothing but return `UP`. It's a cheap 'the web layer and Actuator are responding' signal. - **DiskSpaceHealthIndicator** — always registered. Checks free space on a configured path (default: the app's working directory) against a threshold (default **10 MB**). Returns `DOWN` when free space is below the threshold. - **DataSourceHealthIndicator** — registered when a `javax.sql.DataSource` bean exists. Its contributor name is **`db`**. It borrows a connection and runs a driver-appropriate validation query (e.g. `SELECT 1`). - **RedisHealthIndicator** — registered when Spring Data Redis and a `RedisConnectionFactory` are present. Issues Redis `INFO` and reports the server version. - Many more follow the same pattern: `MongoHealthIndicator`, `CassandraHealthIndicator`, `ElasticsearchHealthIndicator`, `RabbitHealthIndicator`, `MailHealthIndicator`, `LivenessStateHealthIndicator`/`ReadinessStateHealthIndicator`, etc. ## Naming Each indicator is registered under a **name** derived from its bean name with the `HealthIndicator` suffix stripped — `ping`, `diskSpace`, `db`, `redis`. That name is both the JSON key under `components` and the key used in the toggle properties (`management.health.<name>.enabled`). ## Seeing the details By default `/actuator/health` returns only `{"status":"UP"}` — no component breakdown — because `management.endpoint.health.show-details` defaults to `never`. Set it to `always` (or `when-authorized`, which only reveals details to authenticated/authorized users) to see per-indicator status and details. ## Overall status The endpoint's aggregate status is the **worst** individual status, ordered by a `StatusAggregator` (default worst→best: `DOWN`, `OUT_OF_SERVICE`, `UP`, `UNKNOWN`). A single `DOWN` component makes the whole endpoint `DOWN`, which by default maps to HTTP **503**. ## When to use Health indicators feed load balancers, container orchestrators (Kubernetes liveness/readiness probes), and monitoring. Understanding which are auto-registered tells you what your `/health` will report before you write any custom code.

  • Why does /actuator/health show only {"status":"UP"} by default with no components?
    Because management.endpoint.health.show-details defaults to 'never' to avoid leaking infrastructure detail to anonymous callers. Set it to 'always' or 'when-authorized' to expose the component breakdown.
  • If the database is down but ping is up, what does the overall endpoint report?
    DOWN. The aggregate status is the worst of all contributors, so one DOWN component (db) makes the whole endpoint DOWN, mapping to HTTP 503 by default.

saying these in an interview costs you the question

  • Thinking all health indicators (Mongo, Redis, DB) are always present regardless of classpath
  • Believing /actuator/health shows component details by default
  • Assuming overall status is 'UP' unless every check fails (it's actually the worst single status)

context

open as a page

How do you disable one built-in health indicator versus all of them, using the management.health.* properties?

level: middleimportance: must knowfreq 55%

basics

~10 s

Disable a single indicator with management.health.<name>.enabled=false (e.g. management.health.db.enabled=false, management.health.redis.enabled=false). Disable all built-ins at once with management.health.defaults.enabled=false, then selectively re-enable the ones you want.

open as a page

How does DiskSpaceHealthIndicator decide UP vs DOWN, and how do you configure its threshold and path?

level: middleimportance: should knowfreq 45%

basics

~10 s

It reports the free space on a directory and returns DOWN when free space falls below a threshold (default 10 MB). You change it with management.health.diskspace.threshold and management.health.diskspace.path.

open as a page

How does DataSourceHealthIndicator actually verify the database, and what happens with multiple DataSources?

level: seniorimportance: should knowfreq 40%

basics

~20 s

It borrows a connection from the pool and runs a lightweight validation query (a driver-specific query like SELECT 1, or Connection.isValid() if none is known). Success is UP, an exception is DOWN. With several DataSources it groups them into a composite.

open as a page

How does RedisHealthIndicator work, and how does one built-in indicator's status roll up into the overall /health status and HTTP code?

level: seniorimportance: should knowfreq 35%

basics

~20 s

RedisHealthIndicator asks Redis for its INFO (server version) via the connection factory; success is UP, a connection error is DOWN. The overall /health status is the worst of all indicators, and DOWN/OUT_OF_SERVICE map to HTTP 503 by default.

open as a page

Architecturally, how does Actuator wire up these built-in indicators, and how does HealthContributor relate to HealthIndicator and readiness/liveness probes?

level: principalimportance: nice to knowfreq 22%

basics

~20 s

Each built-in indicator has its own auto-configuration (e.g. DataSourceHealthContributorAutoConfiguration) that conditionally registers a HealthContributor. HealthIndicator is a single HealthContributor; a CompositeHealthContributor groups several. Kubernetes probes are served via health groups (liveness/readiness) built on the same registry.

open as a page