![]() |
睿智的大熊猫 · 陈翔六点半团队招聘 - 百度· 3 月前 · |
![]() |
文雅的沙发 · 日本能源新政引发民间发电热---国家能源局· 5 月前 · |
![]() |
鼻子大的煎饼果子 · 雄商高铁衡水段最新进展→_手机新浪网· 6 月前 · |
![]() |
刚毅的刺猬 · 连带勒让德函数_百度百科· 11 月前 · |
spring |
https://docs.spring.io/spring-boot/docs/2.1.7.RELEASE/reference/html/production-ready-endpoints.html |
![]() |
礼貌的消防车
1 年前 |
Each individual endpoint can be
enabled
or disabled
. This controls whether or not the endpoint is created and its bean exists in
the application context. To be remotely accessible an endpoint also has to be
exposed via JMX or HTTP
. Most
applications choose HTTP, where the ID of the endpoint along with a prefix of
/actuator
is mapped to a URL. For example, by default, the
health
endpoint is mapped to
/actuator/health
.
The following technology-agnostic endpoints are available:
ID | Description | Enabled by default |
---|---|---|
|
Exposes audit events information for the current application. |
Yes |
|
Displays a complete list of all the Spring beans in your application. |
Yes |
|
Exposes available caches. |
Yes |
|
Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match. |
Yes |
|
Displays a collated list of all
|
Yes |
|
Exposes properties from Spring’s
|
Yes |
|
Shows any Flyway database migrations that have been applied. |
Yes |
|
Shows application health information. |
Yes |
|
Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). |
Yes |
|
Displays arbitrary application info. |
Yes |
|
Shows the Spring Integration graph. |
Yes |
|
Shows and modifies the configuration of loggers in the application. |
Yes |
|
Shows any Liquibase database migrations that have been applied. |
Yes |
|
Shows ‘metrics’ information for the current application. |
Yes |
|
Displays a collated list of all
|
Yes |
|
Displays the scheduled tasks in your application. |
Yes |
|
Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Not available when using Spring Session’s support for reactive web applications. |
Yes |
|
Lets the application be gracefully shutdown. |
No |
|
Performs a thread dump. |
Yes |
If your application is a web application (Spring MVC, Spring WebFlux, or Jersey), you can use the following additional endpoints:
ID | Description | Enabled by default |
---|---|---|
|
Returns an
|
Yes |
|
Exposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux). |
Yes |
|
Returns the contents of the logfile (if
|
Yes |
|
Exposes metrics in a format that can be scraped by a Prometheus server. |
Yes |
To learn more about the Actuator’s endpoints and their request and response formats, please refer to the separate API documentation ( HTML or PDF ).
management.endpoint.shutdown.enabled=true
management.endpoints.enabled-by-default=false management.endpoint.info.enabled=true
![]() |
Note |
---|---|
Disabled endpoints are removed entirely from the application context. If you want
to change only the technologies over which an endpoint is exposed, use the
|
ID | JMX | Web |
---|---|---|
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
Yes |
|
N/A |
No |
|
Yes |
No |
|
Yes |
Yes |
|
Yes |
No |
|
N/A |
No |
|
N/A |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
|
N/A |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
|
Yes |
No |
Property | Default |
---|---|
|
|
|
|
|
|
|
|
management.endpoints.jmx.exposure.include=health,info
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.exclude=env,beans
![]() |
Note |
---|---|
management: endpoints: web: exposure: include: "*" |
![]() |
Note |
---|---|
If your application is exposed publicly, we strongly recommend that you also secure your endpoints . |
![]() |
Tip |
---|---|
If you want to implement your own strategy for when endpoints are exposed, you can
register an
|
A typical Spring Security configuration might look something like the following example:
@Configuration public class ActuatorSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() .anyRequest().hasRole("ENDPOINT_ADMIN") .and() .httpBasic(); }
The preceding example uses
EndpointRequest.toAnyEndpoint()
to match a request to any
endpoint and then ensures that all have the
ENDPOINT_ADMIN
role. Several other matcher
methods are also available on
EndpointRequest
. See the API documentation
(
HTML
or
PDF
) for details.
If you deploy applications behind a firewall, you may prefer that all your actuator
endpoints can be accessed without requiring authentication. You can do so by changing the
management.endpoints.web.exposure.include
property, as follows:
application.properties.
management.endpoints.web.exposure.include=*
Additionally, if Spring Security is present, you would need to add custom security configuration that allows unauthenticated access to the endpoints as shown in the following example:
@Configuration public class ActuatorSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() .anyRequest().permitAll(); }
management.endpoint.beans.cache.time-to-live=10s
![]() |
Note |
---|---|
The prefix
|
![]() |
Note |
---|---|
When making an authenticated HTTP request, the
|
Cross-origin resource sharing (CORS) is a W3C specification that lets you specify in a flexible way what kind of cross-domain requests are authorized. If you use Spring MVC or Spring WebFlux, Actuator’s web endpoints can be configured to support such scenarios.
CORS support is disabled by default and is only enabled once the
management.endpoints.web.cors.allowed-origins
property has been set. The following
configuration permits
GET
and
POST
calls from the
example.com
domain:
management.endpoints.web.cors.allowed-origins=https://example.com management.endpoints.web.cors.allowed-methods=GET,POST
![]() |
Tip |
---|---|
See CorsEndpointProperties for a complete list of options. |
{ "name": "test", "counter": 42 }
This can be used to invoke a write operation that takes
String name
and
int counter
parameters.
![]() |
Tip |
---|---|
Because endpoints are technology agnostic, only simple types can be specified in the
method signature. In particular declaring a single parameter with a custom type defining a
|
![]() |
Note |
---|---|
To allow the input to be mapped to the operation method’s parameters, Java code
implementing an endpoint should be compiled with
|
Operation | HTTP method |
---|---|
|
|
|
|
|
|
![]() |
Note |
---|---|
Range requests are not supported when using Jersey. |
Name | Description |
---|---|
|
Details are never shown. |
|
Details are only shown to authorized users. Authorized roles can be configured using
|
|
Details are shown to all users. |
![]() |
Note |
---|---|
If you have secured your application and wish to use
|
Health information is collected from the content of a
HealthIndicatorRegistry
(by default all
HealthIndicator
instances
defined in your
ApplicationContext
. Spring Boot includes a number of auto-configured
HealthIndicators
and you can also write your own. By default, the final system state is
derived by the
HealthAggregator
which sorts the statuses from each
HealthIndicator
based on an ordered list of statuses. The first status in the sorted list is used as the
overall health status. If no
HealthIndicator
returns a status that is known to the
HealthAggregator
, an
UNKNOWN
status is used.
![]() |
Tip |
---|---|
The
|
The following
HealthIndicators
are auto-configured by Spring Boot when appropriate:
Name | Description |
---|---|
Checks that a Cassandra database is up. |
|
Checks that a Couchbase cluster is up. |
|
Checks for low disk space. |
|
Checks that a connection to
|
|
Checks that an Elasticsearch cluster is up. |
|
Checks that an InfluxDB server is up. |
|
Checks that a JMS broker is up. |
|
Checks that a mail server is up. |
|
Checks that a Mongo database is up. |
|
Checks that a Neo4j server is up. |
|
Checks that a Rabbit server is up. |
|
Checks that a Redis server is up. |
|
Checks that a Solr server is up. |
![]() |
Tip |
---|---|
You can disable them all by setting the
|
To provide custom health information, you can register Spring beans that implement the
HealthIndicator
interface.
You need to provide an implementation of the
health()
method and return a
Health
response. The
Health
response should include a status and can optionally include
additional details to be displayed. The following code shows a sample
HealthIndicator
implementation:
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.stereotype.Component; @Component public class MyHealthIndicator implements HealthIndicator { @Override public Health health() { int errorCode = check(); // perform some specific health check if (errorCode != 0) { return Health.down().withDetail("Error Code", errorCode).build(); return Health.up().build(); }
![]() |
Note |
---|---|
The identifier for a given
|
In addition to Spring Boot’s predefined
Status
types, it is also possible for
Health
to return a custom
Status
that represents a new system state. In such cases, a
custom implementation of the
HealthAggregator
interface
also needs to be provided, or the default implementation has to be configured by using
the
management.health.status.order
configuration property.
For example, assume a new
Status
with code
FATAL
is being used in one of your
HealthIndicator
implementations. To configure the severity order, add the following
property to your application properties:
management.health.status.order=FATAL, DOWN, OUT_OF_SERVICE, UNKNOWN, UP
The HTTP status code in the response reflects the overall health status (for example,
UP
maps to 200, while
OUT_OF_SERVICE
and
DOWN
map to 503). You might also want to
register custom status mappings if you access the health endpoint over HTTP. For example,
the following property maps
FATAL
to 503 (service unavailable):
management.health.status.http-mapping.FATAL=503
![]() |
Tip |
---|---|
If you need more control, you can define your own
|
The following table shows the default status mappings for the built-in statuses:
Status | Mapping |
---|---|
DOWN |
SERVICE_UNAVAILABLE (503) |
OUT_OF_SERVICE |
SERVICE_UNAVAILABLE (503) |
UP |
No mapping by default, so http status is 200 |
UNKNOWN |
No mapping by default, so http status is 200 |
For reactive applications, such as those using Spring WebFlux,
ReactiveHealthIndicator
provides a non-blocking contract for getting application health. Similar to a traditional
HealthIndicator
, health information is collected from the content of a
ReactiveHealthIndicatorRegistry
(by default all
HealthIndicator
and
ReactiveHealthIndicator
instances defined in your
ApplicationContext
. Regular
HealthIndicator
that do not check against a reactive API are executed on the elastic
scheduler.
![]() |
Tip |
---|---|
In a reactive application, The
|
To provide custom health information from a reactive API, you can register Spring beans
that implement the
ReactiveHealthIndicator
interface. The following code shows a sample
ReactiveHealthIndicator
implementation:
@Component public class MyReactiveHealthIndicator implements ReactiveHealthIndicator { @Override public Mono<Health> health() { return doHealthCheck() //perform some specific health check that returns a Mono<Health> .onErrorResume(ex -> Mono.just(new Health.Builder().down(ex).build()))); }
![]() |
Tip |
---|---|
To handle the error automatically, consider extending from
|
The following
ReactiveHealthIndicators
are auto-configured by Spring Boot when
appropriate:
Name | Description |
---|---|
Checks that a Cassandra database is up. |
|
Checks that a Couchbase cluster is up. |
|
Checks that a Mongo database is up. |
|
Checks that a Redis server is up. |
![]() |
Tip |
---|---|
If necessary, reactive indicators replace the regular ones. Also, any
|
Application information exposes various information collected from all
InfoContributor
beans defined
in your
ApplicationContext
. Spring Boot includes a number of auto-configured
InfoContributor
beans, and you can write your own.
The following
InfoContributor
beans are auto-configured by Spring Boot, when
appropriate:
Name | Description |
---|---|
Exposes any key from the
|
|
Exposes git information if a
|
|
Exposes build information if a
|
![]() |
Tip |
---|---|
It is possible to disable them all by setting the
|
info.app.encoding=UTF-8 info.app.java.source=1.8 info.app.java.target=1.8
![]() |
Tip |
---|---|
Rather than hardcoding those values, you could also expand info properties at build time . Assuming you use Maven, you could rewrite the preceding example as follows: info.app.encoding[email protected]@ info.app.java.source[email protected]@ info.app.java.target[email protected]@ |
![]() |
Tip |
---|---|
A
|
management.info.git.mode=full
![]() |
Tip |
---|---|
The Maven and Gradle plugins can both generate that file. See " Generate build information " for more details. |
To provide custom application information, you can register Spring beans that implement
the
InfoContributor
interface.
The following example contributes an
example
entry with a single value:
import java.util.Collections; import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.InfoContributor; import org.springframework.stereotype.Component; @Component public class ExampleInfoContributor implements InfoContributor { @Override public void contribute(Info.Builder builder) { builder.withDetail("example", Collections.singletonMap("key", "value")); }
If you reach the
info
endpoint, you should see a response that contains the following
![]() |
睿智的大熊猫 · 陈翔六点半团队招聘 - 百度 3 月前 |
![]() |
文雅的沙发 · 日本能源新政引发民间发电热---国家能源局 5 月前 |
![]() |
鼻子大的煎饼果子 · 雄商高铁衡水段最新进展→_手机新浪网 6 月前 |
![]() |
刚毅的刺猬 · 连带勒让德函数_百度百科 11 月前 |