| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | [[production-ready]] | 
					
						
							| 
									
										
										
										
											2014-06-04 21:25:39 +08:00
										 |  |  |  | = Spring Boot Actuator: Production-ready features | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [partintro] | 
					
						
							|  |  |  |  | -- | 
					
						
							|  |  |  |  | Spring Boot includes a number of additional features to help you monitor and manage your | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | application when you push it to production. You can choose to manage and monitor your | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | application by using HTTP endpoints or with JMX. Auditing, health, and metrics gathering | 
					
						
							|  |  |  |  | can also be automatically applied to your application. | 
					
						
							| 
									
										
										
										
											2015-07-16 16:05:20 +08:00
										 |  |  |  | -- | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-17 03:56:49 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | [[production-ready-enabling]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | == Enabling Production-ready Features | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | The {github-code}/spring-boot-project/spring-boot-actuator[`spring-boot-actuator`] module | 
					
						
							|  |  |  |  | provides all of Spring Boot's production-ready features. The simplest way to enable the | 
					
						
							|  |  |  |  | features is to add a dependency to the `spring-boot-starter-actuator` '`Starter`'. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | .Definition of Actuator | 
					
						
							|  |  |  |  | **** | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | An actuator is a manufacturing term that refers to a mechanical device for moving or | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | controlling something. Actuators can generate a large amount of motion from a small | 
					
						
							|  |  |  |  | change. | 
					
						
							|  |  |  |  | **** | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | To add the actuator to a Maven based project, add the following '`Starter`' dependency: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,xml,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	<dependencies> | 
					
						
							|  |  |  |  | 		<dependency> | 
					
						
							|  |  |  |  | 			<groupId>org.springframework.boot</groupId> | 
					
						
							|  |  |  |  | 			<artifactId>spring-boot-starter-actuator</artifactId> | 
					
						
							|  |  |  |  | 		</dependency> | 
					
						
							|  |  |  |  | 	</dependencies> | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | For Gradle, use the following declaration: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,groovy,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	dependencies { | 
					
						
							|  |  |  |  | 		compile("org.springframework.boot:spring-boot-starter-actuator") | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-endpoints]] | 
					
						
							|  |  |  |  | == Endpoints | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | Actuator endpoints let you monitor and interact with your application. Spring Boot | 
					
						
							|  |  |  |  | includes a number of built-in endpoints and lets you add your own. For example, the | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | `health` endpoint provides basic application health information. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | The way that endpoints are exposed depends on the type of technology that you choose. | 
					
						
							|  |  |  |  | Most applications choose HTTP monitoring, where the ID of the endpoint along with a | 
					
						
							| 
									
										
										
										
											2017-11-23 14:32:11 +08:00
										 |  |  |  | prefix of `/actuator` is mapped to a URL. For example, by default, the `health` | 
					
						
							|  |  |  |  | endpoint is mapped to `/actuator/health`. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | The following technology-agnostic endpoints are available: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 20:15:18 +08:00
										 |  |  |  | [cols="2,5"] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | |=== | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | | ID | Description | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-21 00:05:21 +08:00
										 |  |  |  | |`auditevents` | 
					
						
							|  |  |  |  | |Exposes audit events information for the current application. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-12 22:45:25 +08:00
										 |  |  |  | |`beans` | 
					
						
							|  |  |  |  | |Displays a complete list of all the Spring beans in your application. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 21:40:39 +08:00
										 |  |  |  | |`conditions` | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | |Shows the conditions that were evaluated on configuration and auto-configuration | 
					
						
							|  |  |  |  | classes and the reasons why they did or did not match. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | |`configprops` | 
					
						
							|  |  |  |  | |Displays a collated list of all `@ConfigurationProperties`. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | |`env` | 
					
						
							|  |  |  |  | |Exposes properties from Spring's `ConfigurableEnvironment`. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-08 09:44:36 +08:00
										 |  |  |  | |`flyway` | 
					
						
							|  |  |  |  | |Shows any Flyway database migrations that have been applied. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | |`health` | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | |Shows application health information. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | |`info` | 
					
						
							|  |  |  |  | |Displays arbitrary application info. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 07:32:43 +08:00
										 |  |  |  | |`loggers` | 
					
						
							|  |  |  |  | |Shows and modifies the configuration of loggers in the application. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-08 09:44:36 +08:00
										 |  |  |  | |`liquibase` | 
					
						
							|  |  |  |  | |Shows any Liquibase database migrations that have been applied. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | |`metrics` | 
					
						
							| 
									
										
										
										
											2014-10-09 17:24:30 +08:00
										 |  |  |  | |Shows '`metrics`' information for the current application. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | |`mappings` | 
					
						
							|  |  |  |  | |Displays a collated list of all `@RequestMapping` paths. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 21:28:38 +08:00
										 |  |  |  | |`scheduledtasks` | 
					
						
							|  |  |  |  | |Displays the scheduled tasks in your application. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-28 06:18:37 +08:00
										 |  |  |  | |`sessions` | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | |Allows retrieval and deletion of user sessions from a Spring Session-backed session | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | store. Not available when using Spring Session's support for reactive web applications. | 
					
						
							| 
									
										
										
										
											2016-11-28 06:18:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | |`shutdown` | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | |Lets the application be gracefully shutdown (not enabled by default). | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-12 16:08:43 +08:00
										 |  |  |  | |`threaddump` | 
					
						
							|  |  |  |  | |Performs a thread dump. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | |`trace` | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | |Displays trace information (by default, the last 100 HTTP requests). | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | |=== | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | If your application is a web application (Spring MVC, Spring WebFlux, or Jersey), you can | 
					
						
							|  |  |  |  | use the following additional endpoints: | 
					
						
							| 
									
										
										
										
											2016-07-03 02:07:09 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 20:15:18 +08:00
										 |  |  |  | [cols="2,5"] | 
					
						
							| 
									
										
										
										
											2016-07-03 02:07:09 +08:00
										 |  |  |  | |=== | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | | ID | Description | 
					
						
							| 
									
										
										
										
											2016-07-03 02:07:09 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | |`heapdump` | 
					
						
							|  |  |  |  | |Returns a GZip compressed `hprof` heap dump file. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | |`logfile` | 
					
						
							|  |  |  |  | |Returns the contents of the logfile (if `logging.file` or `logging.path` properties have | 
					
						
							|  |  |  |  | been set). Supports the use of the HTTP `Range` header to retrieve part of the log file's | 
					
						
							|  |  |  |  | content. | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | |`prometheus` | 
					
						
							|  |  |  |  | |Exposes metrics in a format that can be scraped by a Prometheus server. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 09:15:25 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | |`jolokia` | 
					
						
							|  |  |  |  | |Exposes JMX beans over HTTP (when Jolokia is on the classpath, not availble for WebFlux). | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 02:07:09 +08:00
										 |  |  |  | |=== | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 09:15:25 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 19:56:48 +08:00
										 |  |  |  | To learn more about the Actuator's endpoints and their request and response formats, | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | please refer to the separate API documentation ({spring-boot-actuator-api}/html[HTML] or | 
					
						
							|  |  |  |  | {spring-boot-actuator-api}/pdf/spring-boot-actuator-web-api.pdf[PDF]). | 
					
						
							| 
									
										
										
										
											2017-08-04 19:56:48 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | [[production-ready-endpoints-exposing-endpoints]] | 
					
						
							|  |  |  |  | === Exposing Endpoints | 
					
						
							|  |  |  |  | Since Endpoints may contain sensitive information, careful consideration should be given | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | about when to expose them. By default, Spring Boot exposes all enabled endpoints | 
					
						
							|  |  |  |  | over JMX but only the `health` and `info` endpoints over HTTP. | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | To change the endpoints that are exposed, you can use the `expose` and `exclude` property | 
					
						
							|  |  |  |  | for the technology. For example, to only expose the `health` over JMX you would set the | 
					
						
							|  |  |  |  | following property: | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | .application.properties | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 	management.endpoints.jmx.expose=health | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | The `*` character can be used to indicate all endpoints. For example, to expose everything | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | over HTTP except the `env` endpoint, you would use the following properties: | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | .application.properties | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	management.endpoints.web.expose=* | 
					
						
							|  |  |  |  | 	management.endpoints.web.exclude=env | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | NOTE: If your application is exposed publicly, we strongly recommend that you also | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | <<production-ready-endpoints-security, secure your endpoints>>. | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | TIP: If you want to implement your own strategy for when endpoints are exposed, you can | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | register an `EndpointFilter` bean. | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-endpoints-security]] | 
					
						
							|  |  |  |  | === Securing HTTP Endpoints | 
					
						
							|  |  |  |  | You should take care to secure HTTP endpoints in the same way that you would any other | 
					
						
							| 
									
										
										
										
											2018-01-05 08:19:52 +08:00
										 |  |  |  | sensitive URL. If Spring Security is present, endpoints are secured by default using Spring Security’s | 
					
						
							|  |  |  |  | content-negotiation strategy. If you wish to configure custom security for HTTP endpoints, for example, only allow users | 
					
						
							|  |  |  |  | with a certain role to access them, Spring Boot provides some convenient `RequestMatcher` objects that can be used in combination with | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | Spring Security. | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | A typical Spring Security configuration might look something like the following example: | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,java,indent=0] | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 	@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(); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | 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 | 
					
						
							|  |  |  |  | ({spring-boot-actuator-api}/html[HTML] or | 
					
						
							|  |  |  |  | {spring-boot-actuator-api}/pdf/spring-boot-actuator-web-api.pdf[PDF]) for details. | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 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.expose` property, as follows: | 
					
						
							| 
									
										
										
										
											2017-08-01 17:05:09 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | .application.properties | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	management.endpoints.web.expose=* | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-05 08:19:52 +08:00
										 |  |  |  | Additionally, if Spring Security is present, you would need to add custom security configuration | 
					
						
							|  |  |  |  | that allows unauthenticated access to the endpoints. For example, | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,java,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	@Configuration | 
					
						
							|  |  |  |  | 	public class ActuatorSecurity extends WebSecurityConfigurerAdapter { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		@Override | 
					
						
							|  |  |  |  | 		protected void configure(HttpSecurity http) throws Exception { | 
					
						
							|  |  |  |  | 			http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() | 
					
						
							|  |  |  |  | 				.anyRequest().permitAll() | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-customizing-endpoints]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Customizing Endpoints | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | Endpoints can be customized by using Spring properties. You can change whether an | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | endpoint is `enabled` and the amount of time for which it caches responses. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | For example, the following `application.properties` file changes the time-to-live of the | 
					
						
							| 
									
										
										
										
											2017-11-23 20:52:58 +08:00
										 |  |  |  | `beans` endpoint to 10 seconds and also enables `shutdown`: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-11-23 20:52:58 +08:00
										 |  |  |  | 	management.endpoint.beans.cache.time-to-live=10s | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 	management.endpoint.shutdown.enabled=true | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | NOTE: The prefix `management.endpoint.<name>` is used to uniquely identify the | 
					
						
							|  |  |  |  | endpoint that is being configured. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | By default, all endpoints except for `shutdown` are enabled. If you prefer to | 
					
						
							|  |  |  |  | specifically "`opt-in`" endpoint enablement, you can use the | 
					
						
							|  |  |  |  | `management.endpoints.enabled-by-default` property. For example, the following settings | 
					
						
							|  |  |  |  | disable _all_ endpoints except for `info`: | 
					
						
							| 
									
										
										
										
											2014-12-11 04:31:32 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-11-17 01:51:21 +08:00
										 |  |  |  | 	management.endpoints.enabled-by-default=false | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 	management.endpoint.info.enabled=true | 
					
						
							| 
									
										
										
										
											2014-12-11 04:31:32 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | NOTE: Disabled endpoints are removed entirely from the `ApplicationContext`. If you want | 
					
						
							|  |  |  |  | to change only the technologies over which an endpoint is exposed, you can use the | 
					
						
							|  |  |  |  | `expose` and `exclude` properties (see <<production-ready-endpoints-exposing-endpoints>>). | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 08:46:01 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 01:36:21 +08:00
										 |  |  |  | [[production-ready-endpoint-hypermedia]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Hypermedia for Actuator Web Endpoints | 
					
						
							| 
									
										
										
										
											2017-07-31 05:12:17 +08:00
										 |  |  |  | A "`discovery page`" is added with links to all the endpoints. The "`discovery page`" is | 
					
						
							| 
									
										
										
										
											2017-11-23 14:32:11 +08:00
										 |  |  |  | available on `/actuator` by default. | 
					
						
							| 
									
										
										
										
											2015-08-06 22:56:06 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | When a custom management context path is configured, the "`discovery page`" automatically | 
					
						
							| 
									
										
										
										
											2017-11-23 14:32:11 +08:00
										 |  |  |  | moves from `/actuator` to the root of the management context. For example, if the | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | management context path is `/management`, then the discovery page is available from | 
					
						
							|  |  |  |  | `/management`. When the management context path is set to `/`, the discovery page is | 
					
						
							|  |  |  |  | disabled to prevent the possibility of a clash with other mappings. | 
					
						
							| 
									
										
										
										
											2015-07-02 01:36:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 12:36:20 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | [[production-ready-endpoint-custom-mapping]] | 
					
						
							|  |  |  |  | === Actuator Web Endpoint Paths | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | By default, endpoints are exposed over HTTP under the `/actuator` path by using the ID of | 
					
						
							|  |  |  |  | the endpoint. For example, the `beans` endpoint is exposed under `/actuator/beans`. If you | 
					
						
							|  |  |  |  | want to map endpoints to a different path, you can use the | 
					
						
							|  |  |  |  | `management.endpoints.web.path-mapping` property. Also,  if you want change the base path, | 
					
						
							|  |  |  |  | you can use `management.endpoints.web.base-path`. | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | The following example remaps `/actuator/health` to `/healthcheck`: | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | .application.properties | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	management.endpoints.web.base-path=/ | 
					
						
							| 
									
										
										
										
											2017-12-12 22:45:25 +08:00
										 |  |  |  | 	management.endpoints.web.path-mapping.health=healthcheck | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-27 18:41:30 +08:00
										 |  |  |  | [[production-ready-endpoint-cors]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === CORS Support | 
					
						
							| 
									
										
										
										
											2015-10-27 18:41:30 +08:00
										 |  |  |  | http://en.wikipedia.org/wiki/Cross-origin_resource_sharing[Cross-origin resource sharing] | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | (CORS) is a http://www.w3.org/TR/cors/[W3C specification] that lets you specify in a | 
					
						
							|  |  |  |  | flexible way what kind of cross-domain requests are authorized. If you use Spring MVC or | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | Spring WebFlux, Actuator's web endpoints can be configured to support such scenarios. | 
					
						
							| 
									
										
										
										
											2015-10-27 18:41:30 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | CORS support is disabled by default and is only enabled once the | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | `management.endpoints.web.cors.allowed-origins` property has been set. The following | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | configuration permits `GET` and `POST` calls from the `example.com` domain: | 
					
						
							| 
									
										
										
										
											2015-10-27 18:41:30 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 	management.endpoints.web.cors.allowed-origins=http://example.com | 
					
						
							|  |  |  |  | 	management.endpoints.web.cors.allowed-methods=GET,POST | 
					
						
							| 
									
										
										
										
											2015-10-27 18:41:30 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | TIP: See | 
					
						
							|  |  |  |  | {sc-spring-boot-actuator-autoconfigure}/endpoint/web/CorsEndpointProperties.{sc-ext}[CorsEndpointProperties] | 
					
						
							|  |  |  |  | for a complete list of options. | 
					
						
							| 
									
										
										
										
											2015-07-01 09:46:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 11:06:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 12:36:20 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-30 16:01:35 +08:00
										 |  |  |  | [[production-ready-customizing-endpoints-programmatically]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Adding Custom Endpoints | 
					
						
							| 
									
										
										
										
											2017-07-12 16:08:43 +08:00
										 |  |  |  | If you add a `@Bean` annotated with `@Endpoint`, any methods annotated with | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | `@ReadOperation`, `@WriteOperation`, or `@DeleteOperation` are automatically exposed over | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | JMX and, in a web application, over HTTP as well. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | You can also write technology-specific endpoints by using `@JmxEndpoint` or | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | `@WebEndpoint`. These endpoints are filtered to their respective technologies. For | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | example, `@WebEndpoint` is exposed only over HTTP and not over JMX. | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | Finally, you can write technology-specific extensions by using `@EndpointWebExtension` and | 
					
						
							|  |  |  |  | `@EndpointJmxExtension`. These annotations let you provide technology-specific operations | 
					
						
							|  |  |  |  | to augment an existing endpoint. | 
					
						
							| 
									
										
										
										
											2017-10-14 00:14:27 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | TIP: If you add endpoints as a library feature, consider adding a configuration class | 
					
						
							|  |  |  |  | annotated with `@ManagementContextConfiguration` to `/META-INF/spring.factories` under the | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | following key: | 
					
						
							|  |  |  |  | `org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration`. If you do | 
					
						
							|  |  |  |  | so and if your users ask for a separate management port or address, the endpoint moves to | 
					
						
							|  |  |  |  | a child context with all the other web endpoints. | 
					
						
							| 
									
										
										
										
											2015-06-30 16:01:35 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-health]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Health Information | 
					
						
							|  |  |  |  | You can use health information to check the status of your running application. It is | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | often used by monitoring software to alert someone when a production system goes down. | 
					
						
							| 
									
										
										
										
											2017-11-24 00:14:34 +08:00
										 |  |  |  | The information exposed by the `health` endpoint depends on the | 
					
						
							|  |  |  |  | `management.endpoint.health.show-details` property. By default, the property's value is | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | `false` and a simple "`status`" message is returned. When the property's value is set to | 
					
						
							| 
									
										
										
										
											2017-11-24 00:14:34 +08:00
										 |  |  |  | `true`, additional details from the individual health indicators are also displayed. | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-11 07:11:58 +08:00
										 |  |  |  | Health information is collected from all | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | {sc-spring-boot-actuator}/health/HealthIndicator.{sc-ext}[`HealthIndicator`] beans | 
					
						
							|  |  |  |  | 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. | 
					
						
							| 
									
										
										
										
											2017-07-07 07:52:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ==== Auto-configured HealthIndicators | 
					
						
							|  |  |  |  | The following `HealthIndicators` are auto-configured by Spring Boot when appropriate: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-27 23:35:36 +08:00
										 |  |  |  | [cols="4,6"] | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | |=== | 
					
						
							|  |  |  |  | |Name |Description | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/cassandra/CassandraHealthIndicator.{sc-ext}[`CassandraHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2015-11-08 22:26:50 +08:00
										 |  |  |  | |Checks that a Cassandra database is up. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/system/DiskSpaceHealthIndicator.{sc-ext}[`DiskSpaceHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | |Checks for low disk space. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/jdbc/DataSourceHealthIndicator.{sc-ext}[`DataSourceHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | |Checks that a connection to `DataSource` can be obtained. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/elasticsearch/ElasticsearchHealthIndicator.{sc-ext}[`ElasticsearchHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2016-06-29 12:51:52 +08:00
										 |  |  |  | |Checks that an Elasticsearch cluster is up. | 
					
						
							| 
									
										
										
										
											2015-08-03 20:45:04 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 22:16:00 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/influx/InfluxDbHealthIndicator.{sc-ext}[`InfluxDbHealthIndicator`] | 
					
						
							|  |  |  |  | |Checks that an InfluxDB server is up. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/jms/JmsHealthIndicator.{sc-ext}[`JmsHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2015-08-03 20:45:04 +08:00
										 |  |  |  | |Checks that a JMS broker is up. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/mail/MailHealthIndicator.{sc-ext}[`MailHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2015-08-03 20:45:04 +08:00
										 |  |  |  | |Checks that a mail server is up. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/mongo/MongoHealthIndicator.{sc-ext}[`MongoHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | |Checks that a Mongo database is up. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 00:45:46 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/neo4j/Neo4jHealthIndicator.{sc-ext}[`Neo4jHealthIndicator`] | 
					
						
							|  |  |  |  | |Checks that a Neo4j server is up. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/amqp/RabbitHealthIndicator.{sc-ext}[`RabbitHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | |Checks that a Rabbit server is up. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/redis/RedisHealthIndicator.{sc-ext}[`RedisHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | |Checks that a Redis server is up. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:33:54 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/solr/SolrHealthIndicator.{sc-ext}[`SolrHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | |Checks that a Solr server is up. | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | TIP: You can disable them all by setting the `management.health.defaults.enabled` | 
					
						
							| 
									
										
										
										
											2015-07-28 22:27:56 +08:00
										 |  |  |  | property. | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | ==== Writing Custom HealthIndicators | 
					
						
							|  |  |  |  | To provide custom health information, you can register Spring beans that implement the | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | {sc-spring-boot-actuator}/health/HealthIndicator.{sc-ext}[`HealthIndicator`] interface. | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | 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 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | additional details to be displayed. The following code shows a sample `HealthIndicator` | 
					
						
							|  |  |  |  | implementation: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,java,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2016-07-04 12:52:57 +08:00
										 |  |  |  | 	import org.springframework.boot.actuate.health.Health; | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 	import org.springframework.boot.actuate.health.HealthIndicator; | 
					
						
							|  |  |  |  | 	import org.springframework.stereotype.Component; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	@Component | 
					
						
							| 
									
										
										
										
											2015-11-28 00:21:15 +08:00
										 |  |  |  | 	public class MyHealthIndicator implements HealthIndicator { | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		@Override | 
					
						
							| 
									
										
										
										
											2014-05-23 04:53:08 +08:00
										 |  |  |  | 		public Health health() { | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | 			int errorCode = check(); // perform some specific health check | 
					
						
							|  |  |  |  | 			if (errorCode != 0) { | 
					
						
							| 
									
										
										
										
											2015-01-01 09:46:59 +08:00
										 |  |  |  | 				return Health.down().withDetail("Error Code", errorCode).build(); | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-01-01 09:46:59 +08:00
										 |  |  |  | 			return Health.up().build(); | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-28 00:21:15 +08:00
										 |  |  |  | NOTE: The identifier for a given `HealthIndicator` is the name of the bean without the | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | `HealthIndicator` suffix, if it exists. In the preceding example, the health information | 
					
						
							|  |  |  |  | is available in an entry named `my`. | 
					
						
							| 
									
										
										
										
											2015-11-28 00:21:15 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | In addition to Spring Boot's predefined | 
					
						
							|  |  |  |  | {sc-spring-boot-actuator}/health/Status.{sc-ext}[`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 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | {sc-spring-boot-actuator}/health/HealthAggregator.{sc-ext}[`HealthAggregator`] interface | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | also needs to be provided, or the default implementation has to be configured by using | 
					
						
							|  |  |  |  | the `management.health.status.order` configuration property. | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | 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 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | property to your application properties: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-05-18 19:26:39 +08:00
										 |  |  |  | 	management.health.status.order=FATAL, DOWN, OUT_OF_SERVICE, UNKNOWN, UP | 
					
						
							| 
									
										
										
										
											2014-12-10 13:59:12 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2014-05-23 04:53:08 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | 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 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | register custom status mappings if you access the health endpoint over HTTP. For example, | 
					
						
							|  |  |  |  | the following property maps `FATAL` to 503 (service unavailable): | 
					
						
							| 
									
										
										
										
											2017-04-10 20:01:50 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-08-22 17:11:22 +08:00
										 |  |  |  | 	management.health.status.http-mapping.FATAL=503 | 
					
						
							| 
									
										
										
										
											2017-04-10 20:01:50 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2014-05-23 04:53:08 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | TIP: If you need more control, you can define your own `HealthStatusHttpMapper` bean. | 
					
						
							| 
									
										
										
										
											2017-08-22 17:11:22 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | The following table shows the default status mappings for the built-in statuses: | 
					
						
							| 
									
										
										
										
											2017-06-30 02:31:40 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [cols="1,3"] | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | |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 | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 17:44:33 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 07:39:27 +08:00
										 |  |  |  | [[reactive-health-indicators]] | 
					
						
							| 
									
										
										
										
											2017-11-22 17:44:33 +08:00
										 |  |  |  | ==== Reactive Health Indicators | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | For reactive applications, such as those using Spring WebFlux, `ReactiveHealthIndicator` | 
					
						
							|  |  |  |  | provides a non-blocking contract for getting application health. Similar to a traditional | 
					
						
							| 
									
										
										
										
											2017-11-22 17:44:33 +08:00
										 |  |  |  | `HealthIndicator`, health information is collected from all | 
					
						
							|  |  |  |  | {sc-spring-boot-actuator}/health/ReactiveHealthIndicator.{sc-ext}[`ReactiveHealthIndicator`] | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | beans defined in your `ApplicationContext`. Regular `HealthIndicator` beans that do not | 
					
						
							|  |  |  |  | check against a reactive API are included and executed on the elastic scheduler. | 
					
						
							| 
									
										
										
										
											2017-11-22 17:44:33 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | To provide custom health information from a reactive API, you can register Spring beans | 
					
						
							|  |  |  |  | that implement the | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | {sc-spring-boot-actuator}/health/ReactiveHealthIndicator.{sc-ext}[`ReactiveHealthIndicator`] | 
					
						
							|  |  |  |  | interface. The following code shows a sample `ReactiveHealthIndicator` implementation: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 07:39:27 +08:00
										 |  |  |  | [source,java,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	@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()))); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 17:44:33 +08:00
										 |  |  |  | TIP: To handle the error automatically, consider extending from | 
					
						
							|  |  |  |  | `AbstractReactiveHealthIndicator`. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 17:40:25 +08:00
										 |  |  |  | ==== Auto-configured ReactiveHealthIndicators | 
					
						
							|  |  |  |  | The following `ReactiveHealthIndicators` are auto-configured by Spring Boot when | 
					
						
							|  |  |  |  | appropriate: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [cols="1,4"] | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | |Name |Description | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | |{sc-spring-boot-actuator}/redis/RedisReactiveHealthIndicator.{sc-ext}[`RedisReactiveHealthIndicator`] | 
					
						
							|  |  |  |  | |Checks that a Redis server is up. | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | TIP: If necessary, reactive indicators replace the regular ones. Also, any | 
					
						
							| 
									
										
										
										
											2017-11-23 17:40:25 +08:00
										 |  |  |  | `HealthIndicator` that is not handled explicitly is wrapped automatically. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | [[production-ready-application-info]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Application Information | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | Application information exposes various information collected from all | 
					
						
							|  |  |  |  | {sc-spring-boot-actuator}/info/InfoContributor.{sc-ext}[`InfoContributor`] beans defined | 
					
						
							|  |  |  |  | in your `ApplicationContext`. Spring Boot includes a number of auto-configured | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | `InfoContributor` beans, and you can write your own. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [[production-ready-application-info-autoconfigure]] | 
					
						
							|  |  |  |  | ==== Auto-configured InfoContributors | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-14 20:38:06 +08:00
										 |  |  |  | The following `InfoContributor` beans are auto-configured by Spring Boot, when | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | appropriate: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [cols="1,4"] | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | |Name |Description | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/info/EnvironmentInfoContributor.{sc-ext}[`EnvironmentInfoContributor`] | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | |Exposes any key from the `Environment` under the `info` key. | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/info/GitInfoContributor.{sc-ext}[`GitInfoContributor`] | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | |Exposes git information if a `git.properties` file is available. | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | |{sc-spring-boot-actuator}/info/BuildInfoContributor.{sc-ext}[`BuildInfoContributor`] | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | |Exposes build information if a `META-INF/build-info.properties` file is available. | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | |=== | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | TIP: It is possible to disable them all by setting the `management.info.defaults.enabled` | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | property. | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [[production-ready-application-info-env]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | ==== Custom Application Information | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | You can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | properties. All `Environment` properties under the `info` key are automatically exposed. | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | For example, you could add the following settings to your `application.properties` file: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 	info.app.encoding=UTF-8 | 
					
						
							|  |  |  |  | 	info.app.java.source=1.8 | 
					
						
							|  |  |  |  | 	info.app.java.target=1.8 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [TIP] | 
					
						
							|  |  |  |  | ==== | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | Rather than hardcoding those values, you could also | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | <<howto.adoc#howto-automatic-expansion,expand info properties at build time>>. | 
					
						
							| 
									
										
										
										
											2015-02-19 16:32:23 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | Assuming you use Maven, you could rewrite the preceding example as follows: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-11-04 18:41:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 	info.app.encoding=@project.build.sourceEncoding@ | 
					
						
							|  |  |  |  | 	info.app.java.source=@java.version@ | 
					
						
							|  |  |  |  | 	info.app.java.target=@java.version@ | 
					
						
							| 
									
										
										
										
											2014-11-04 18:41:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | ==== | 
					
						
							| 
									
										
										
										
											2014-11-04 18:41:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-14 15:09:04 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [[production-ready-application-info-git]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | ==== Git Commit Information | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | Another useful feature of the `info` endpoint is its ability to publish information about | 
					
						
							|  |  |  |  | the state of your `git` source code repository when the project was built. If a | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | `GitProperties` bean is available, the `git.branch`, `git.commit.id`, and | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | `git.commit.time` properties are exposed. | 
					
						
							| 
									
										
										
										
											2015-02-24 11:21:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | TIP: A `GitProperties` bean is auto-configured if a `git.properties` file is available at | 
					
						
							|  |  |  |  | the root of the classpath. See | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | "<<howto.adoc#howto-git-info,Generate git information>>" for more details. | 
					
						
							| 
									
										
										
										
											2015-02-24 11:21:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | If you want to display the full git information (that is, the full content of | 
					
						
							|  |  |  |  | `git.properties`), use the `management.info.git.mode` property, as follows: | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 	management.info.git.mode=full | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-application-info-build]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | ==== Build Information | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | If a `BuildProperties` bean is available, the `info` endpoint can also publish | 
					
						
							|  |  |  |  | information about your build. This happens if a `META-INF/build-info.properties` file is | 
					
						
							|  |  |  |  | available in the classpath. | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | TIP: The Maven and Gradle plugins can both generate that file. See | 
					
						
							|  |  |  |  | "<<howto.adoc#howto-build-info,Generate build information>>" for more details. | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-22 06:11:14 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [[production-ready-application-info-custom]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | ==== Writing Custom InfoContributors | 
					
						
							|  |  |  |  | To provide custom application information, you can register Spring beans that implement | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | the {sc-spring-boot-actuator}/info/InfoContributor.{sc-ext}[`InfoContributor`] interface. | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | The following example contributes an `example` entry with a single value: | 
					
						
							| 
									
										
										
										
											2014-09-15 23:25:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [source,java,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	import java.util.Collections; | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 	import org.springframework.boot.actuate.info.Info; | 
					
						
							|  |  |  |  | 	import org.springframework.boot.actuate.info.InfoContributor; | 
					
						
							|  |  |  |  | 	import org.springframework.stereotype.Component; | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 	@Component | 
					
						
							|  |  |  |  | 	public class ExampleInfoContributor implements InfoContributor { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		@Override | 
					
						
							|  |  |  |  | 		public void contribute(Info.Builder builder) { | 
					
						
							|  |  |  |  | 			builder.withDetail("example", | 
					
						
							|  |  |  |  | 					Collections.singletonMap("key", "value")); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | If you reach the `info` endpoint, you should see a response that contains the following | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | additional entry: | 
					
						
							| 
									
										
										
										
											2015-09-30 20:41:31 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | [source,json,indent=0] | 
					
						
							| 
									
										
										
										
											2015-09-30 20:41:31 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2016-03-24 19:55:56 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		"example": { | 
					
						
							|  |  |  |  | 			"key" : "value" | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-30 20:41:31 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-monitoring]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | == Monitoring and Management over HTTP | 
					
						
							| 
									
										
										
										
											2017-11-24 21:05:21 +08:00
										 |  |  |  | If you are developing a web application, Spring Boot Actuator auto-configures all | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | enabled endpoints to be exposed over HTTP. The default convention is to use the `id` of | 
					
						
							| 
									
										
										
										
											2017-11-23 14:32:11 +08:00
										 |  |  |  | the endpoint with a prefix of `/actuator` as the URL path. For example, `health` is | 
					
						
							|  |  |  |  | exposed as `/actuator/health`. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | TIP: Actuator is supported natively with Spring MVC, Spring WebFlux, and Jersey. | 
					
						
							| 
									
										
										
										
											2017-11-24 21:05:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-customizing-management-server-context-path]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Customizing the Management Endpoint Paths | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | Sometimes, it is useful to customize the prefix for the management endpoints. For | 
					
						
							| 
									
										
										
										
											2017-11-23 14:32:11 +08:00
										 |  |  |  | example, your application might already use `/actuator` for another purpose. You can | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | use the `management.endpoints.web.base-path` property to change the prefix for your | 
					
						
							|  |  |  |  | management endpoint, as shown in the following example: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-10-17 06:05:32 +08:00
										 |  |  |  | 	management.endpoints.web.base-path=/manage | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | The preceding `application.properties` example changes the endpoint from | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | `/actuator/{id}` to `/manage/{id}` (for example, `/manage/info`). | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 19:10:42 +08:00
										 |  |  |  | NOTE: Unless the management port has been configured to | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | <<production-ready-customizing-management-server-port,expose endpoints by using a | 
					
						
							|  |  |  |  | different HTTP port>>, `management.endpoints.web.base-path` is relative to | 
					
						
							| 
									
										
										
										
											2017-12-15 17:24:14 +08:00
										 |  |  |  | `server.servlet.context-path`. If `management.server.port` is configured, | 
					
						
							| 
									
										
										
										
											2017-12-28 19:08:51 +08:00
										 |  |  |  | `management.endpoints.web.base-path` is relative to | 
					
						
							|  |  |  |  | `management.server.servlet.context-path`. | 
					
						
							| 
									
										
										
										
											2017-03-24 07:11:22 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-customizing-management-server-port]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Customizing the Management Server Port | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | Exposing management endpoints by using the default HTTP port is a sensible choice for | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | cloud-based deployments. If, however, your application runs inside your own data center, | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | you may prefer to expose endpoints by using a different HTTP port. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | You can set the `management.server.port` property to change the HTTP port, as shown in | 
					
						
							|  |  |  |  | the following example: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-10-17 06:05:32 +08:00
										 |  |  |  | 	management.server.port=8081 | 
					
						
							| 
									
										
										
										
											2014-04-03 22:58:10 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 12:44:20 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-27 19:33:21 +08:00
										 |  |  |  | [[production-ready-management-specific-ssl]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Configuring Management-specific SSL | 
					
						
							| 
									
										
										
										
											2016-06-27 19:33:21 +08:00
										 |  |  |  | When configured to use a custom port, the management server can also be configured with | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | its own SSL by using the various `management.server.ssl.*` properties. For example, doing | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | so lets a management server be available over HTTP while the main application uses HTTPS, | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | as shown in the following property settings: | 
					
						
							| 
									
										
										
										
											2016-06-27 19:33:21 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	server.port=8443 | 
					
						
							|  |  |  |  | 	server.ssl.enabled=true | 
					
						
							|  |  |  |  | 	server.ssl.key-store=classpath:store.jks | 
					
						
							|  |  |  |  | 	server.ssl.key-password=secret | 
					
						
							| 
									
										
										
										
											2017-10-17 06:05:32 +08:00
										 |  |  |  | 	management.server.port=8080 | 
					
						
							|  |  |  |  | 	management.server.ssl.enabled=false | 
					
						
							| 
									
										
										
										
											2016-06-27 19:33:21 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | Alternatively, both the main server and the management server can use SSL but with | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | different key stores, as follows: | 
					
						
							| 
									
										
										
										
											2016-06-27 19:33:21 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	server.port=8443 | 
					
						
							|  |  |  |  | 	server.ssl.enabled=true | 
					
						
							|  |  |  |  | 	server.ssl.key-store=classpath:main.jks | 
					
						
							|  |  |  |  | 	server.ssl.key-password=secret | 
					
						
							| 
									
										
										
										
											2017-10-17 06:05:32 +08:00
										 |  |  |  | 	management.server.port=8080 | 
					
						
							|  |  |  |  | 	management.server.ssl.enabled=true | 
					
						
							|  |  |  |  | 	management.server.ssl.key-store=classpath:management.jks | 
					
						
							|  |  |  |  | 	management.server.ssl.key-password=secret | 
					
						
							| 
									
										
										
										
											2016-06-27 19:33:21 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | [[production-ready-customizing-management-server-address]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Customizing the Management Server Address | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | You can customize the address that the management endpoints are available on by setting | 
					
						
							|  |  |  |  | the `management.server.address` property. Doing so can be useful if you want to listen | 
					
						
							|  |  |  |  | only on an internal or ops-facing network or to listen only for connections from | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | `localhost`. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | NOTE: You can listen on a different address only when the port differs from the main | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | server port. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | The following example `application.properties` does not allow remote management | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | connections: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-10-17 06:05:32 +08:00
										 |  |  |  | 	management.server.port=8081 | 
					
						
							|  |  |  |  | 	management.server.address=127.0.0.1 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-disabling-http-endpoints]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Disabling HTTP Endpoints | 
					
						
							|  |  |  |  | If you do not want to expose endpoints over HTTP, you can set the management port to | 
					
						
							|  |  |  |  | `-1`, as shown in the following example: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-10-17 06:05:32 +08:00
										 |  |  |  | 	management.server.port=-1 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-30 07:48:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | [[production-ready-jmx]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | == Monitoring and Management over JMX | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | Java Management Extensions (JMX) provide a standard mechanism to monitor and manage | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | applications. By default, Spring Boot exposes management endpoints as JMX MBeans under | 
					
						
							|  |  |  |  | the `org.springframework.boot` domain. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-custom-mbean-names]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Customizing MBean Names | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | The name of the MBean is usually generated from the `id` of the endpoint. For example, the | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | `health` endpoint is exposed as `org.springframework.boot:type=Endpoint,name=Health`. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | If your application contains more than one Spring `ApplicationContext`, you may find that | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | names clash. To solve this problem, you can set the | 
					
						
							|  |  |  |  | `management.endpoints.jmx.unique-names` property to `true` so that MBean names are always | 
					
						
							|  |  |  |  | unique. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | You can also customize the JMX domain under which endpoints are exposed. The following | 
					
						
							|  |  |  |  | settings show an example of doing so in `application.properties`: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-08-22 17:46:38 +08:00
										 |  |  |  | 	management.endpoints.jmx.domain=com.example.myapp | 
					
						
							|  |  |  |  | 	management.endpoints.jmx.unique-names=true | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-disable-jmx-endpoints]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Disabling JMX Endpoints | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | If you do not want to expose endpoints over JMX, you can set the | 
					
						
							| 
									
										
										
										
											2017-11-29 21:25:32 +08:00
										 |  |  |  | `management.endpoints.jmx.enabled` property to `false`, as shown in the following example: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-11-29 21:25:32 +08:00
										 |  |  |  | 	management.endpoints.jmx.enabled=false | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-jolokia]] | 
					
						
							|  |  |  |  | === Using Jolokia for JMX over HTTP | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | Jolokia is a JMX-HTTP bridge that provides an alternative method of accessing JMX beans. | 
					
						
							|  |  |  |  | To use Jolokia, include a dependency to `org.jolokia:jolokia-core`. For example, with | 
					
						
							|  |  |  |  | Maven, you would add the following dependency: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,xml,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	<dependency> | 
					
						
							|  |  |  |  | 		<groupId>org.jolokia</groupId> | 
					
						
							|  |  |  |  | 		<artifactId>jolokia-core</artifactId> | 
					
						
							|  |  |  |  |  	</dependency> | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 09:15:25 +08:00
										 |  |  |  | The Jolokia endpoint can then be exposed by adding `jolokia` or `*` to the | 
					
						
							|  |  |  |  | `management.endpoints.web.expose` property. You can then be accessed it by using | 
					
						
							|  |  |  |  | `/actuator/jolokia` on your management HTTP server. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-customizing-jolokia]] | 
					
						
							|  |  |  |  | ==== Customizing Jolokia | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | Jolokia has a number of settings that you would traditionally configure by setting servlet | 
					
						
							|  |  |  |  | parameters. With Spring Boot, you can use your `application.properties` file. To do so, | 
					
						
							| 
									
										
										
										
											2018-01-24 09:15:25 +08:00
										 |  |  |  | prefix the parameter with `management.endpont.jolokia.config.`, as shown in the following | 
					
						
							|  |  |  |  | example: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2018-01-24 09:15:25 +08:00
										 |  |  |  | 	management.endpoint.jolokia.config.debug=true | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-disabling-jolokia]] | 
					
						
							|  |  |  |  | ==== Disabling Jolokia | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | If you use Jolokia but do not want Spring Boot to configure it, set the | 
					
						
							| 
									
										
										
										
											2018-01-24 09:15:25 +08:00
										 |  |  |  | `management.endpoint.jolokia.enabled` property to `false`, as follows: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 15:04:57 +08:00
										 |  |  |  | [source,properties,indent=0] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-08-11 20:05:03 +08:00
										 |  |  |  | 	management.jolokia.enabled=false | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 07:32:43 +08:00
										 |  |  |  | [[production-ready-loggers]] | 
					
						
							|  |  |  |  | == Loggers | 
					
						
							|  |  |  |  | Spring Boot Actuator includes the ability to view and configure the log levels of your | 
					
						
							| 
									
										
										
										
											2017-10-20 02:02:06 +08:00
										 |  |  |  | application at runtime. You can view either the entire list or an individual logger's | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | configuration, which is made up of both the explicitly configured logging level as well | 
					
						
							|  |  |  |  | as the effective logging level given to it by the logging framework.  These levels can be | 
					
						
							|  |  |  |  | one of: | 
					
						
							| 
									
										
										
										
											2016-11-15 07:32:43 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | * `TRACE` | 
					
						
							|  |  |  |  | * `DEBUG` | 
					
						
							|  |  |  |  | * `INFO` | 
					
						
							|  |  |  |  | * `WARN` | 
					
						
							|  |  |  |  | * `ERROR` | 
					
						
							|  |  |  |  | * `FATAL` | 
					
						
							|  |  |  |  | * `OFF` | 
					
						
							|  |  |  |  | * `null` | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | `null` indicates that there is no explicit configuration. | 
					
						
							| 
									
										
										
										
											2016-11-15 07:32:43 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-logger-configuration]] | 
					
						
							|  |  |  |  | === Configure a Logger | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | To configure a given logger, `POST` a partial entity to the resource's URI, as shown in | 
					
						
							|  |  |  |  | the following example: | 
					
						
							| 
									
										
										
										
											2016-11-15 07:32:43 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,json,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		"configuredLevel": "DEBUG" | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | TIP: To "`reset`" the specific level of the logger (and use the default configuration | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | instead), you can pass a value of `null` as the `configuredLevel`. | 
					
						
							| 
									
										
										
										
											2017-06-01 20:31:07 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 07:32:43 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | [[production-ready-metrics]] | 
					
						
							|  |  |  |  | == Metrics | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | Spring Boot Actuator provides dependency management and auto-configuration for | 
					
						
							|  |  |  |  | https://micrometer.io[Micrometer], an application metrics facade that supports numerous | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | monitoring systems, including: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | - https://github.com/Netflix/atlas[Atlas] | 
					
						
							|  |  |  |  | - https://www.datadoghq.com[Datadog] | 
					
						
							|  |  |  |  | - http://ganglia.sourceforge.net[Ganglia] | 
					
						
							|  |  |  |  | - https://graphiteapp.org[Graphite] | 
					
						
							|  |  |  |  | - https://www.influxdata.com[Influx] | 
					
						
							|  |  |  |  | - https://prometheus.io[Prometheus] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | NOTE: At the time of this writing, the number of monitoring systems supported by | 
					
						
							|  |  |  |  | Micrometer is growing rapidly. See the https://micrometer.io[Micrometer project] for more | 
					
						
							|  |  |  |  | information. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | Micrometer provides a separate module for each supported monitoring system. Depending on | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | one (or more) of these modules is sufficient to get started with Micrometer in your | 
					
						
							|  |  |  |  | Spring Boot application. To learn more about Micrometer's capabilities, please refer to | 
					
						
							|  |  |  |  | its https://micrometer.io/docs[reference documentation]. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-30 03:31:40 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | [[production-ready-metrics-spring-mvc]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Spring MVC Metrics | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | Auto-configuration enables the instrumentation of requests handled by Spring MVC. When | 
					
						
							| 
									
										
										
										
											2017-12-14 19:27:24 +08:00
										 |  |  |  | `management.metrics.web.server.auto-time-requests` is `true`, this instrumentation occurs | 
					
						
							|  |  |  |  | for all requests. Alternatively, when set to `false`, you can enable instrumentation by | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | adding `@Timed` to a request-handling method. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | By default, metrics are generated with the name, `http.server.requests`. The name can be | 
					
						
							| 
									
										
										
										
											2018-01-05 08:10:06 +08:00
										 |  |  |  | customized by setting the `management.metrics.web.server.requests-metric-name` property. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 02:57:28 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 19:51:07 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | [[production-ready-metrics-spring-mvc-tags]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | ==== Spring MVC Metric Tags | 
					
						
							|  |  |  |  | By default, Spring MVC-related metrics are tagged with the following information: | 
					
						
							| 
									
										
										
										
											2017-01-20 17:52:55 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | * The request's method. | 
					
						
							|  |  |  |  | * The request's URI (templated if possible). | 
					
						
							|  |  |  |  | * The simple class name of any exception that was thrown while handling the request. | 
					
						
							|  |  |  |  | * The response's status. | 
					
						
							| 
									
										
										
										
											2015-05-31 19:17:11 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | To customize the tags, provide a `@Bean` that implements `WebMvcTagsProvider`. | 
					
						
							| 
									
										
										
										
											2015-03-30 17:39:41 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-03 01:13:15 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | [[production-ready-metrics-web-flux]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === WebFlux Metrics | 
					
						
							|  |  |  |  | Auto-configuration enables the instrumentation of all requests handled by WebFlux | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | controllers. You can also use a helper class, `RouterFunctionMetrics`, to instrument | 
					
						
							|  |  |  |  | applications that use WebFlux's functional programming model. | 
					
						
							| 
									
										
										
										
											2015-03-30 17:39:41 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | By default, metrics are generated with the name `http.server.requests`. You can customize | 
					
						
							| 
									
										
										
										
											2018-01-05 08:10:06 +08:00
										 |  |  |  | the name by setting the `management.metrics.web.server.requests-metric-name` property. | 
					
						
							| 
									
										
										
										
											2015-03-30 17:39:41 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | [[production-ready-metrics-web-flux-tags]] | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | ==== WebFlux Metrics Tags | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | By default, WebFlux-related metrics for the annotation-based programming model are tagged | 
					
						
							|  |  |  |  | with the following information: | 
					
						
							| 
									
										
										
										
											2015-03-30 17:39:41 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | * The request's method. | 
					
						
							|  |  |  |  | * The request's URI (templated if possible). | 
					
						
							|  |  |  |  | * The simple class name of any exception that was thrown while handling the request. | 
					
						
							|  |  |  |  | * The response's status. | 
					
						
							| 
									
										
										
										
											2015-05-31 19:17:11 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | To customize the tags, provide a `@Bean` that implements `WebFluxTagsProvider`. | 
					
						
							| 
									
										
										
										
											2015-05-05 18:50:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | By default, metrics for the functional programming model are tagged with the following | 
					
						
							|  |  |  |  | information: | 
					
						
							| 
									
										
										
										
											2015-05-05 18:50:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | * The request's method | 
					
						
							|  |  |  |  | * The request's URI (templated if possible). | 
					
						
							|  |  |  |  | * The response's status. | 
					
						
							| 
									
										
										
										
											2015-06-04 02:57:28 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | To customize the tags, use the `defaultTags` method on your `RouterFunctionMetrics` | 
					
						
							|  |  |  |  | instance. | 
					
						
							| 
									
										
										
										
											2015-03-30 17:39:41 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 18:50:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | [[production-ready-metrics-rest-template]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === RestTemplate Metrics | 
					
						
							| 
									
										
										
										
											2018-01-12 00:12:34 +08:00
										 |  |  |  | The instrumentation of any `RestTemplate` created using the auto-configured | 
					
						
							|  |  |  |  | `RestTemplateBuilder` is enabled. It is also possible to apply | 
					
						
							|  |  |  |  | `MetricsRestTemplateCustomizer` manually. | 
					
						
							| 
									
										
										
										
											2015-05-02 05:04:50 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | By default, metrics are generated with the name, `http.client.requests`. The name can be | 
					
						
							| 
									
										
										
										
											2018-01-05 08:10:06 +08:00
										 |  |  |  | customized by setting the `management.metrics.web.client.requests-metric-name` property. | 
					
						
							| 
									
										
										
										
											2015-05-02 05:04:50 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | [[production-ready-metrics-rest-template-tags]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | ==== RestTemplate Metric Tags | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | By default, metrics generated by an instrumented `RestTemplate` are tagged with the | 
					
						
							|  |  |  |  | following information: | 
					
						
							| 
									
										
										
										
											2015-08-10 18:59:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | * The request's method. | 
					
						
							|  |  |  |  | * The request's URI (templated if possible). | 
					
						
							|  |  |  |  | * The response's status. | 
					
						
							|  |  |  |  | * The request URI's host. | 
					
						
							| 
									
										
										
										
											2015-04-23 20:25:57 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 18:59:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 22:21:19 +08:00
										 |  |  |  | [[production-ready-metrics-cache]] | 
					
						
							|  |  |  |  | === Cache metrics | 
					
						
							|  |  |  |  | Auto-configuration will enable the instrumentation of all available ``Cache``s on startup | 
					
						
							|  |  |  |  | with a metric named `cache`. The prefix can be customized by using the | 
					
						
							| 
									
										
										
										
											2018-01-19 00:21:40 +08:00
										 |  |  |  | `management.metrics.cache.metric-name` property. Cache instrumentation is specific | 
					
						
							| 
									
										
										
										
											2018-01-03 22:21:19 +08:00
										 |  |  |  | to each cache library, refer to https://micrometer.io/docs[the micrometer documentation] | 
					
						
							|  |  |  |  | for more details. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | The following cache libraries are supported: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | * Caffeine | 
					
						
							|  |  |  |  | * EhCache 2 | 
					
						
							|  |  |  |  | * Hazelcast | 
					
						
							|  |  |  |  | * Any compliant JCache (JSR-107) implementation | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | Metrics will also be tagged by the name of the `CacheManager` computed based on the bean | 
					
						
							|  |  |  |  | name. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | NOTE: Only caches that are available on startup are bound to the registry. For caches | 
					
						
							|  |  |  |  | created on-the-fly or programmatically after the startup phase, an explicit registration | 
					
						
							|  |  |  |  | is required. A `CacheMetricsRegistrar` bean is made available to make that process easier. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-30 19:39:42 +08:00
										 |  |  |  | [[production-ready-metrics-jdbc]] | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | === DataSource Metrics | 
					
						
							|  |  |  |  | Auto-configuration enables the instrumentation of all available ``DataSource`` objects | 
					
						
							|  |  |  |  | with a metric named `data.source`. Data source instrumentation results in gauges | 
					
						
							|  |  |  |  | representing the currently active, maximum allowed, and minimum allowed connections in the | 
					
						
							|  |  |  |  | pool. Each of these gauges has a name that is prefixed by `data.source` by default. The | 
					
						
							| 
									
										
										
										
											2018-01-19 00:21:40 +08:00
										 |  |  |  | prefix can be customized by setting the `management.metrics.jdbc.metric-name` | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | property. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | Metrics are also tagged by the name of the `DataSource` computed based on the bean name. | 
					
						
							| 
									
										
										
										
											2017-10-30 19:39:42 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-18 22:14:39 +08:00
										 |  |  |  | [[production-ready-metrics-rabbitmq]] | 
					
						
							|  |  |  |  | === RabbitMQ metrics | 
					
						
							|  |  |  |  | Auto-configuration will enable the instrumentation of all available RabbitMQ connection | 
					
						
							|  |  |  |  | factories with a metric named `rabbitmq`. The prefix can be customized by using the | 
					
						
							|  |  |  |  | `management.metrics.rabbitmq.metric-name` property. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | [[production-ready-metrics-integration]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Spring Integration Metrics | 
					
						
							|  |  |  |  | Auto-configuration enables binding of a number of Spring Integration-related metrics: | 
					
						
							| 
									
										
										
										
											2015-06-06 06:42:41 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | .General metrics | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | | Metric | Description | 
					
						
							| 
									
										
										
										
											2015-06-06 06:42:41 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.channelNames` | 
					
						
							|  |  |  |  | | Number of Spring Integration channels | 
					
						
							| 
									
										
										
										
											2015-04-23 17:36:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.handlerNames` | 
					
						
							|  |  |  |  | | Number of Spring Integration handlers | 
					
						
							| 
									
										
										
										
											2015-04-23 17:36:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.sourceNames` | 
					
						
							|  |  |  |  | | Number of Spring Integration sources | 
					
						
							|  |  |  |  | |=== | 
					
						
							| 
									
										
										
										
											2015-04-23 17:36:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | .Channel metrics | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | | Metric | Description | 
					
						
							| 
									
										
										
										
											2015-05-31 19:17:11 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.channel.receives` | 
					
						
							|  |  |  |  | | Number of receives | 
					
						
							| 
									
										
										
										
											2015-04-23 17:36:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.channel.sendErrors` | 
					
						
							|  |  |  |  | | Number of failed sends | 
					
						
							| 
									
										
										
										
											2015-04-23 17:36:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.channel.sends` | 
					
						
							|  |  |  |  | | Number of successful sends | 
					
						
							|  |  |  |  | |=== | 
					
						
							| 
									
										
										
										
											2015-05-31 19:51:07 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | .Handler metrics | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | | Metric | Description | 
					
						
							| 
									
										
										
										
											2015-04-23 17:36:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.handler.duration.max` | 
					
						
							|  |  |  |  | | Maximum handler duration in milliseconds | 
					
						
							| 
									
										
										
										
											2015-06-04 02:57:28 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.handler.duration.min` | 
					
						
							|  |  |  |  | | Minimum handler duration in milliseconds | 
					
						
							| 
									
										
										
										
											2014-12-10 11:52:56 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.handler.duration.mean` | 
					
						
							|  |  |  |  | | Mean handler duration in milliseconds | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.handler.activeCount` | 
					
						
							|  |  |  |  | | Number of active handlers | 
					
						
							|  |  |  |  | |=== | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | .Source metrics | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | | Metric | Description | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 11:59:45 +08:00
										 |  |  |  | | `spring.integration.source.messages` | 
					
						
							|  |  |  |  | | Number of successful source calls | 
					
						
							|  |  |  |  | |=== | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-auditing]] | 
					
						
							|  |  |  |  | == Auditing | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | Once Spring Security is in play, Spring Boot Actuator has a flexible audit framework that | 
					
						
							|  |  |  |  | publishes events (by default, "`authentication success`", "`failure`" and | 
					
						
							|  |  |  |  | "`access denied`" exceptions). This feature can be very useful for reporting and for | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | implementing a lock-out policy based on authentication failures. To customize published | 
					
						
							|  |  |  |  | security events, you can provide your own implementations of | 
					
						
							|  |  |  |  | `AbstractAuthenticationAuditListener` and `AbstractAuthorizationAuditListener`. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | You can also use the audit services for your own business events. To do so, either inject | 
					
						
							|  |  |  |  | the existing `AuditEventRepository` into your own components and use that directly or | 
					
						
							|  |  |  |  | publish an `AuditApplicationEvent` with the Spring `ApplicationEventPublisher` (by | 
					
						
							|  |  |  |  | implementing `ApplicationEventPublisherAware`). | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-tracing]] | 
					
						
							|  |  |  |  | == Tracing | 
					
						
							| 
									
										
										
										
											2014-03-18 02:36:56 +08:00
										 |  |  |  | Tracing is automatically enabled for all HTTP requests. You can view the `trace` endpoint | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | and obtain basic information about the last 100 requests. The following listing shows | 
					
						
							|  |  |  |  | sample output: | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,json,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2017-01-04 08:59:53 +08:00
										 |  |  |  | 	[{ | 
					
						
							|  |  |  |  | 		"timestamp": 1394343677415, | 
					
						
							|  |  |  |  | 		"info": { | 
					
						
							|  |  |  |  | 			"method": "GET", | 
					
						
							|  |  |  |  | 			"path": "/trace", | 
					
						
							|  |  |  |  | 			"headers": { | 
					
						
							|  |  |  |  | 				"request": { | 
					
						
							|  |  |  |  | 					"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | 
					
						
							|  |  |  |  | 					"Connection": "keep-alive", | 
					
						
							|  |  |  |  | 					"Accept-Encoding": "gzip, deflate", | 
					
						
							|  |  |  |  | 					"User-Agent": "Mozilla/5.0 Gecko/Firefox", | 
					
						
							|  |  |  |  | 					"Accept-Language": "en-US,en;q=0.5", | 
					
						
							|  |  |  |  | 					"Cookie": "_ga=GA1.1.827067509.1390890128; ..." | 
					
						
							|  |  |  |  | 					"Authorization": "Basic ...", | 
					
						
							|  |  |  |  | 					"Host": "localhost:8080" | 
					
						
							|  |  |  |  | 				}, | 
					
						
							|  |  |  |  | 				"response": { | 
					
						
							|  |  |  |  | 					"Strict-Transport-Security": "max-age=31536000 ; includeSubDomains", | 
					
						
							|  |  |  |  | 					"X-Application-Context": "application:8080", | 
					
						
							|  |  |  |  | 					"Content-Type": "application/json;charset=UTF-8", | 
					
						
							|  |  |  |  | 					"status": "200" | 
					
						
							|  |  |  |  | 				} | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	},{ | 
					
						
							|  |  |  |  | 		"timestamp": 1394343684465, | 
					
						
							|  |  |  |  | 		... | 
					
						
							|  |  |  |  | 	}] | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | By default, the trace includes the following information: | 
					
						
							| 
									
										
										
										
											2017-03-24 06:36:27 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [cols="1,2"] | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | |Name |Description | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | |Request Headers | 
					
						
							|  |  |  |  | |Headers from the request. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | |Response Headers | 
					
						
							|  |  |  |  | |Headers from the response. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | |Cookies | 
					
						
							|  |  |  |  | |`Cookie` from request headers and `Set-Cookie` from response headers. | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | |Errors | 
					
						
							|  |  |  |  | |The error attributes (if any). | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | |Time Taken | 
					
						
							|  |  |  |  | |The time taken to service the request in milliseconds. | 
					
						
							|  |  |  |  | |=== | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-custom-tracing]] | 
					
						
							|  |  |  |  | === Custom tracing | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | If you need to trace additional events, you can inject a | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | {sc-spring-boot-actuator}/trace/TraceRepository.{sc-ext}[`TraceRepository`] into your | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | Spring beans. The `add` method accepts a single `Map` structure that is converted to JSON | 
					
						
							|  |  |  |  | and logged. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | By default, an `InMemoryTraceRepository` that stores the last 100 events is used. If you | 
					
						
							|  |  |  |  | need to expand the capacity, you can define your own instance of the | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | `InMemoryTraceRepository` bean. You can also create your own alternative | 
					
						
							|  |  |  |  | `TraceRepository` implementation. | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 02:57:28 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-12 03:19:18 +08:00
										 |  |  |  | [[production-ready-process-monitoring]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | == Process Monitoring | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | In the `spring-boot` module, you can find two classes to create files that are often | 
					
						
							|  |  |  |  | useful for process monitoring: | 
					
						
							| 
									
										
										
										
											2014-10-09 14:03:35 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | * `ApplicationPidFileWriter` creates a file containing the application PID (by default, | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | in the application directory with a file name of `application.pid`). | 
					
						
							| 
									
										
										
										
											2014-10-09 14:03:35 +08:00
										 |  |  |  | * `EmbeddedServerPortFileWriter` creates a file (or files) containing the ports of the | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | embedded server (by default, in the application directory with a file name of | 
					
						
							| 
									
										
										
										
											2017-11-03 04:01:43 +08:00
										 |  |  |  | `application.port`). | 
					
						
							| 
									
										
										
										
											2014-10-09 14:03:35 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | By default, these writers are not activated, but you can enable: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | * <<production-ready-process-monitoring-configuration,By Extending Configuration>> | 
					
						
							|  |  |  |  | * <<production-ready-process-monitoring-programmatically>> | 
					
						
							| 
									
										
										
										
											2014-04-12 03:19:18 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-process-monitoring-configuration]] | 
					
						
							| 
									
										
										
										
											2017-12-26 22:53:29 +08:00
										 |  |  |  | === Extending Configuration | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | In the `META-INF/spring.factories` file, you can activate the listener(s) that writes a | 
					
						
							|  |  |  |  | PID file, as shown in the following example: | 
					
						
							| 
									
										
										
										
											2014-04-23 16:42:10 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-12 03:19:18 +08:00
										 |  |  |  | [indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2015-06-06 06:42:41 +08:00
										 |  |  |  | 	org.springframework.context.ApplicationListener=\ | 
					
						
							| 
									
										
										
										
											2017-02-05 16:23:56 +08:00
										 |  |  |  | 	org.springframework.boot.system.ApplicationPidFileWriter,\ | 
					
						
							| 
									
										
										
										
											2017-10-30 23:32:49 +08:00
										 |  |  |  | 	org.springframework.boot.system.EmbeddedServerPortFileWriter | 
					
						
							| 
									
										
										
										
											2014-04-12 03:19:18 +08:00
										 |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-process-monitoring-programmatically]] | 
					
						
							|  |  |  |  | === Programmatically | 
					
						
							| 
									
										
										
										
											2014-10-09 14:03:35 +08:00
										 |  |  |  | You can also activate a listener by invoking the `SpringApplication.addListeners(...)` | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | method and passing the appropriate `Writer` object. This method also lets you customize | 
					
						
							|  |  |  |  | the file name and path in the `Writer` constructor. | 
					
						
							| 
									
										
										
										
											2014-04-12 03:19:18 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | [[production-ready-cloudfoundry]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | == Cloud Foundry Support | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | Spring Boot's actuator module includes additional support that is activated when you | 
					
						
							|  |  |  |  | deploy to a compatible Cloud Foundry instance. The `/cloudfoundryapplication` path | 
					
						
							| 
									
										
										
										
											2017-07-12 16:08:43 +08:00
										 |  |  |  | provides an alternative secured route to all `@Endpoint` beans. | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | The extended support lets Cloud Foundry management UIs (such as the web application that | 
					
						
							|  |  |  |  | you can use to view deployed applications) be augmented with Spring Boot actuator | 
					
						
							|  |  |  |  | information. For example, an application status page may include full health information | 
					
						
							|  |  |  |  | instead of the typical "`running`" or "`stopped`" status. | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | NOTE: The `/cloudfoundryapplication` path is not directly accessible to regular users. | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | In order to use the endpoint, a valid UAA token must be passed with the request. | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-cloudfoundry-disable]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Disabling Extended Cloud Foundry Actuator Support | 
					
						
							|  |  |  |  | If you want to fully disable the `/cloudfoundryapplication` endpoints, you can add the | 
					
						
							|  |  |  |  | following setting to your `application.properties` file: | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | .application.properties | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	management.cloudfoundry.enabled=false | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-cloudfoundry-ssl]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Cloud Foundry Self-signed Certificates | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | By default, the security verification for `/cloudfoundryapplication` endpoints makes SSL | 
					
						
							|  |  |  |  | calls to various Cloud Foundry services. If your Cloud Foundry UAA or Cloud Controller | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | services use self-signed certificates, you need to set the following property: | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | .application.properties | 
					
						
							|  |  |  |  | [source,properties,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 	management.cloudfoundry.skip-ssl-validation=true | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [[production-ready-cloudfoundry-custom-security]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | === Custom Security Configuration | 
					
						
							|  |  |  |  | If you define custom security configuration and you want extended Cloud Foundry actuator | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | support, you should ensure that `/cloudfoundryapplication/**` paths are open. Without a | 
					
						
							|  |  |  |  | direct open route, your Cloud Foundry application manager is not able to obtain endpoint | 
					
						
							|  |  |  |  | data. | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | For Spring Security, you typically include something like | 
					
						
							|  |  |  |  | `mvcMatchers("/cloudfoundryapplication/**").permitAll()` in your configuration, as shown | 
					
						
							|  |  |  |  | in the following example: | 
					
						
							| 
									
										
										
										
											2017-01-04 09:27:14 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | [source,java,indent=0] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | include::{code-examples}/cloudfoundry/CloudFoundryIgnorePathsExample.java[tag=security] | 
					
						
							|  |  |  |  | ---- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | [[production-ready-whats-next]] | 
					
						
							| 
									
										
										
										
											2017-10-31 00:15:32 +08:00
										 |  |  |  | == What to Read Next | 
					
						
							| 
									
										
										
										
											2014-03-14 04:18:47 +08:00
										 |  |  |  | If you want to explore some of the concepts discussed in this chapter, you can take a | 
					
						
							|  |  |  |  | look at the actuator {github-code}/spring-boot-samples[sample applications]. You also | 
					
						
							|  |  |  |  | might want to read about graphing tools such as http://graphite.wikidot.com/[Graphite]. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 19:06:46 +08:00
										 |  |  |  | Otherwise, you can continue on, to read about <<deployment.adoc#deployment, '`deployment | 
					
						
							|  |  |  |  | options`'>> or jump ahead for some in-depth information about Spring Boot's | 
					
						
							| 
									
										
										
										
											2014-10-28 18:53:47 +08:00
										 |  |  |  | _<<build-tool-plugins.adoc#build-tool-plugins, build tool plugins>>_. |