Spring Boot includes the Spring Boot Actuator. This section answers questions that often arise from its use.
In a standalone application, the Actuator HTTP port defaults to the same as the main HTTP port.
To make the application listen on a different port, set the external property: management.server.port
.
To listen on a completely different network address (such as when you have an internal network for management and an external one for user applications), you can also set management.server.address
to a valid IP address to which the server is able to bind.
For more detail, see the ManagementServerProperties
source code and “Section 54.2, “Customizing the Management Server Port”” in the “Production-ready features” section.
Spring Boot installs a ‘whitelabel’ error page that you see in a browser client if you encounter a server error (machine clients consuming JSON and other media types should see a sensible response with the right error code).
Note | |
---|---|
Set |
Overriding the error page with your own depends on the templating technology that you use.
For example, if you use Thymeleaf, you can add an error.html
template.
If you use FreeMarker, you can add an error.ftl
template.
In general, you need a View
that resolves with a name of error
or a @Controller
that handles the /error
path.
Unless you replaced some of the default configuration, you should find a BeanNameViewResolver
in your ApplicationContext
, so a @Bean
named error
would be one way of doing that.
See ErrorMvcAutoConfiguration
for more options.
See also the section on “Error Handling” for details of how to register handlers in the servlet container.
Information returned by the env
and configprops
endpoints can be somewhat sensitive so keys matching a certain pattern are sanitized by default (i.e. their values are replaced by ******
).
Spring Boot uses sensible defaults for such keys: for instance, any key ending with the word "password", "secret", "key" or "token" is sanitized.
It is also possible to use a regular expression instead, such as *credentials.*
to sanitize any key that holds the word credentials
as part of the key.
The patterns to use can be customized using the management.endpoint.env.keys-to-sanitize
and management.endpoint.configprops.keys-to-sanitize
respectively.
Spring Boot health indicators return a Status
type to indicate the overall system health.
If you want to monitor or alert on levels of health for a particular application, you can export these statuses as metrics via Micrometer.
By default, the status codes “up”, “down”, “out of service” and “unknown” are used by Spring Boot.
To export these, you’ll need to convert these states to some set of numbers so that they can be used with a Micrometer Gauge
.
The follow example shows one way to write such an exporter:
@Configuration public class HealthMetricsConfiguration { public HealthMetricsConfiguration(MeterRegistry registry, HealthAggregator aggregator, Map<String, HealthIndicator> indicators) { // This example presumes common tags (such as the app) are applied elsewhere HealthIndicator health = new CompositeHealthIndicator(aggregator, indicators); Gauge.builder("health", health, this::getStatusCode).strongReference(true).register(registry); } private int getStatusCode(HealthIndicator health) { Status status = health.health().getStatus(); if (Status.UP.equals(status)) { return 3; } if (Status.OUT_OF_SERVICE.equals(status)) { return 2; } if (Status.DOWN.equals(status)) { return 1; } return 0; } }