In this article, we introduce the Spring Boot physical, we will first introduce the basic knowledge, and then discuss in detail the Spring Boot 1 x and 2 x the content available,
We will be in the Spring the Boot 1 x in learning how to use, configuration, and extend the monitoring tools, and then, we will discuss how to use the reactive programming model using the Boot 2 x and WebFlux for the same operation,
Since April 2014, Spring Boot physical release with Spring Boot,
As SpringBoot2 release, actuators were redesigned, and add a new exciting endpoints, this guide is divided into three main parts:
- what is Actuator (physical)
Physical - Spring Boot 1 x
- Spring Boot 2. Physical x
-- -- --
# # what is Actuator (physical)
Essence, the actuator brought production ready for our application function,
* * by dependence on him, to monitor our application, collect metrics, understand the flow or the state of the database becomes easy and simple: * *
The library's main advantage is that we can get the production tools, and don't have to implement these functions, physical is mainly used for public information about the operation of the running application - running status, indicators, information, dump, environment, etc., it USES HTTP endpoint or JMX Bean allows us to interact, once use actuators on the class path, can immediately use several endpoints, like most Spring modules, we can easily through a variety of ways to configure it or extension,
# # # Getting Started
To enable the SpringBootActuator, we just need to SpringBootActuator dependencies added to the package manager, in Maven:
` ` ` XML
` ` `
Please note that whatever guidance version, it will remain effective, because version is in the Spring the Boot Bill of Materials (BOM) specified in the
-- -- --
Physical # # Spring Boot 1 x
In 1 x, actuators to follow the R/W (read/write) model, which means that we can read or write, for example, we can retrieve index or operation situation of the application, in addition, we can terminate our application gracefully or change the logging configuration,
In order to make it work, actuators need Spring MVC of its endpoints through HTTP, does not support other technologies,
# # # Endpoints
* * in 1 x, brought their own physical Security model, it USES Spring Security structure, but needs and the rest of the application of independent configuration, * *
And, most endpoints are sensitive - said they are not fully open, in other words, most of the information will be omitted - and a few endpoint is not sensitive/info, for example,
Here is a list of some of the most common in the Boot offers endpoint:
-/health - display application running status information (through unauthenticated connection during a visit to a simple "status", or authenticated display for complete details). By default, not sensitive
-/info - show any application information; The default is not sensitive to
-/metrics - displays the current application of "index" information; By default is sensitive to
-/trace - show tracking information (by default, the last several HTTP requests)
We can be found in [the official documentation] (https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints) a complete list of current endpoint,
# # # configuration existing endpoints
You can use the following format using attributes to customize each endpoint: * endpoints in [the endpoint name]. [the property to customize] *
Provide three attributes:
- id - will visit the endpoint via HTTP
- enabled - if it is true, you can access, otherwise cannot access
- sensitive - if it is true, you will need to authorize via HTTP display key information
For example, add the following attribute to the custom/beans endpoint:
` ` ` properties
Endpoints. Beans. Id=springbeans
Endpoints. Beans. Sensitive=false
Endpoints. Beans. Enabled=true
` ` `
This method has been deprecated,
# # #/health endpoint
/health endpoint is used to check the operation condition of the running application or state, monitoring software will usually do this, to warn our running instance failure or for other reasons and become abnormal, for example, database connection problem, lack of disk space...
By default, in the condition of unauthorized access will only display performance information:
` ` ` json
{
"Status" : "UP", "
}
` ` `
From the health information in our application context configuration, realized all the bean's collection of HealthIndicator interface,
HealthIndicator returned some of the information is essentially a sensitive, but we can be configured endpoints. Health. Sensitive=false to expose more detailed information, such as disk space, messaging agents connection, such as custom inspection,
We can also realize their own custom status indicator - can collect specific to the application of any type of custom running status data, and through/automatically its public health endpoint:
` ` ` Java
@ Component
Public class HealthCheck implements HealthIndicator {
@ Override
Public Health Health () {
Int errorCode=check ();//perform some specific health check
If (errorCode!=0) {
Return the Health. The down ()
. WithDetail (" Error Code ", errorCode). The build ();
}
Return the Health. The up (). The build ();
}
Public int check () {
//Our logic to check the health
return 0;
}
}
` ` `
The output is shown below:
` ` ` Java
{
"Status", "DOWN",
"MyHealthCheck" : {
"Status", "DOWN",
"Error Code" : 1
},
"DiskSpace" : {
"Status" : "UP,"
"Free" : 209047318528,
"Threshold" : 10485760
}
}
` ` `
# # #/info endpoint
We can also custom/info endpoint display data - such as:
` ` ` properties
Info. App. Name=Spring Sample Application
The info. The app. The description=This is my first spring boot application
Info. App. Version=1.0.0
` ` `
And sample output:
` ` ` json
{
"App" : {
"Version" : "1.0.0",
"Description" : "This is my first spring boot application",
"Name" : "the Spring Sample Application"
}
}
` ` `
# # #/metrics endpoint
Metrics endpoint issue related to OS, the JVM and application level measurement information, after the commissioning, we will get such as memory, heap, processors, threads, class load and unload classes, HTTP metric thread pool and some information, such as
The following is the output result of the endpoint:
` ` ` json
{
The "mem" : 193024,
"Mem. Free" : 87693,
"Processors" : 4,
"Instance. Uptime" : 305027,
"Uptime" : 307077,
"Systemload. Business" :
0.11,"Heap.com mitted" : 193024,
"Heap. The init" : 124928,
"Heap. 2" : 105330,
"Heap" : 1764352,
"Threads. Peak" : 22,
"Threads. The daemon" : 19,
"Threads" : 22,
"Classes" : 5819,
"Classes. The loaded" : 5819,
"Classes. Unloaded" : 0,
Gc. Ps_scavenge. "count" : 7,
Gc. Ps_scavenge. "time" : 54,
Gc. Ps_marksweep. "count" : 1,
Gc. Ps_marksweep. "time" : 44,
"Httpsessions. Max" : 1,
"Httpsessions. Active" : 0,
"Counter. Status. 200. Root" : 1,
The gauge. The response. "root" : 37.0
}
` ` `
* * to collect custom indicators, we support the "instrument" (that is, the data of single value snapshots) and "counter" (i.e., increase/decrease index), * *
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull