Skip to content

Commit e5295c0

Browse files
committed
Update HealthInformation reference documentation
Clean and align with changes in Spring Boot 1.2 Fixes gh-2104
1 parent 71fd3b3 commit e5295c0

File tree

1 file changed

+85
-25
lines changed

1 file changed

+85
-25
lines changed

spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ The following endpoints are available:
8686
|true
8787

8888
|`health`
89-
|Shows application health information (defaulting to a simple '`OK`' message).
90-
|false
89+
|Shows full application health information when accessed securely or a simple '`status`'
90+
message when accessed over an insecure HTTP connection.
91+
|true
9192

9293
|`info`
9394
|Displays arbitrary application info.
@@ -137,13 +138,67 @@ that is being configured.
137138

138139

139140
[[production-ready-health]]
140-
=== Custom health information
141-
The default information exposed by the `health` endpoint is a simple '`OK`' message. It
142-
is often useful to perform some additional health checks, for example you might check
143-
that a database connection works, or that a remote REST endpoint is functioning.
141+
=== Health information
142+
Health information can be used to check the status of your running application. It is
143+
often used by monitoring software to alert someone if a production system goes down.
144+
The default information exposed by the `health` endpoint depends on how it is accessed.
145+
For an insecure unauthenticated connection a simple '`status`' message is returned, for a
146+
secure or authenticated connection additional details are also displayed (see
147+
<<production-ready-health-access-restrictions>> for HTTP details).
148+
149+
Heath information is collected from all
150+
{sc-spring-boot-actuator}/health/HealthIndicator.{sc-ext}[`HealthIndicator`] beans defined
151+
in your `ApplicationContext`. Spring Boot includes a number of auto-configured
152+
`HealthIndicators` and you can also write your own.
153+
154+
155+
156+
=== Security with HealthIndicators
157+
Information returned by `HealthIndicators` is often somewhat sensitive in nature. For
158+
example and you probably don't want to publish details of your database server to the
159+
world. For this reason, by default, only the health status is exposed on an insecure HTTP
160+
connection. If you are happy for complete heath information to always be exposed you can
161+
set `endpoints.health.sensitive` to `false`.
162+
163+
Heath responses are also cached to prevent "`denial of service`" attacks. Use the
164+
`endpoints.health.time-to-live` property if you want to change the default cache period
165+
of 1000 milliseconds.
166+
167+
168+
169+
==== Auto-configured HealthIndicators
170+
The following `HealthIndicators` are auto-configured by Spring Boot when appropriate:
171+
172+
|===
173+
|Name |Description
174+
175+
|{sc-spring-boot-actuator}/health/DiskSpaceHealthIndicator.{sc-ext}[`DiskSpaceHealthIndicator`]
176+
|Checks for low disk space.
144177

145-
To provide custom health information you can register a Spring bean that implements the
178+
|{sc-spring-boot-actuator}/health/DataSourceHealthIndicator.{sc-ext}[`DataSourceHealthIndicator`]
179+
|Checks that a connection to `DataSource` can be obtained.
180+
181+
|{sc-spring-boot-actuator}/health/MongoHealthIndicator.{sc-ext}[`MongoHealthIndicator`]
182+
|Checks that a Mongo database is up.
183+
184+
|{sc-spring-boot-actuator}/health/RabbitHealthIndicator.{sc-ext}[`RabbitHealthIndicator`]
185+
|Checks that a Rabbit server is up.
186+
187+
|{sc-spring-boot-actuator}/health/SolrHealthIndicator.{sc-ext}[`RedisHealthIndicator`]
188+
|Checks that a Redis server is up.
189+
190+
|{sc-spring-boot-actuator}/health/SolrHealthIndicator.{sc-ext}[`SolrHealthIndicator`]
191+
|Checks that a Solr server is up.
192+
|===
193+
194+
195+
196+
==== Writing custom HealthIndicators
197+
To provide custom health information you can register Spring beans that implement the
146198
{sc-spring-boot-actuator}/health/HealthIndicator.{sc-ext}[`HealthIndicator`] interface.
199+
You need to provide an implementation of the `health()` method and return a `Health`
200+
response. The `Health` response should include a status and can optionally include
201+
additional details to be displayed.
147202

148203
[source,java,indent=0]
149204
----
@@ -155,30 +210,35 @@ To provide custom health information you can register a Spring bean that impleme
155210
156211
@Override
157212
public Health health() {
158-
// perform some specific health check
159-
return ...
213+
int errorCode = check(); // perform some specific health check
214+
if (errorCode != 0) {
215+
return Health.down().withDetail("Error Code", errorCode);
216+
}
217+
return Health.up();
160218
}
161219
162220
}
163221
----
164222

165-
Spring Boot provides a
166-
{sc-spring-boot-actuator}/health/DataSourceHealthIndicator.{sc-ext}[`DataSourceHealthIndicator`]
167-
implementation that attempts a simple database test (reusing the validation query set on the data
168-
source, if any) as well as implementations for Redis, MongoDB and RabbitMQ. Spring Boot adds the
169-
`HealthIndicator` instances automatically if beans of type `DataSource`, `MongoTemplate`,
170-
`RedisConnectionFactory`, and `RabbitTemplate` respectively are present in the
171-
`ApplicationContext`. A health indicator that checks free disk space is also provided.
223+
In addition to Spring Boot's default {sc-spring-boot-actuator}/health/Status.{sc-ext}[`Status`]
224+
types, it is also possible to introduce custom `Status` types to represent more
225+
complex system states. In such cases a custom implementation of the
226+
{sc-spring-boot-actuator}/health/HealthAggregator.{sc-ext}[`HealthAggregator`]
227+
interface also needs to be provided, or the default implementation has to be configured
228+
using the `management.health.status.order` configuration property.
229+
230+
For example, assuming a new `Status` with code `FATAL` is being used in one of your
231+
`HealthIndicator` implementations. To configure the severity order add the following
232+
to your application properties:
172233

173-
Besides implementing custom a `HealthIndicator` type and using out-of-box {sc-spring-boot-actuator}/health/Status.{sc-ext}[`Status`]
174-
types, it is also possible to introduce custom `Status` types for different or more complex system
175-
states. In that case a custom implementation of the {sc-spring-boot-actuator}/health/HealthAggregator.{sc-ext}[`HealthAggregator`]
176-
interface needs to be provided or the default implementation has to be configured using the
177-
`management.health.status.order` configuration property.
234+
[source,properties,indent=0]
235+
----
236+
management.health.status.order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
237+
----
178238

179-
Assuming a new `Status` with code `FATAL` is being used in one of your `HealthIndicator`
180-
implementations. To configure the severity or order add the following to your application properties:
181-
`management.health.status.order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP`.
239+
You might also want to register custom status mappings with the `HealthMvcEndpoint`
240+
if you access the health endpoint over HTTP. For example you could map `FATAL` to
241+
`HttpStatus.SERVICE_UNAVAILABLE`.
182242

183243

184244

@@ -411,7 +471,7 @@ If you don't want to expose endpoints over HTTP you can set the management port
411471

412472

413473
[[production-ready-health-access-restrictions]]
414-
=== Health endpoint anonymous access restrictions
474+
=== HTTP Health endpoint access restrictions
415475
The information exposed by the health endpoint varies depending on whether or not it's
416476
accessed anonymously. By default, when accessed anonymously, any details about the
417477
server's health are hidden and the endpoint will simply indicate whether or not the server

0 commit comments

Comments
 (0)