Actuator is an integrated function of introspection and monitoring of application systems provided by Spring Boot, which can configure and view the application system, count related functions, etc.
Using Actuator
Just introduce dependencies
Maven :
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId></dependency>
Gradle :
compile('org.springframework.boot:spring-boot-starter-actuator')Endpoints
List some major endpoints
Properties of configuration file
Address and port configuration
management.port : Specifies the port to access these monitoring methods, separated from the logical interface port. If you don't want to expose these to http, you can set management.port = -1management.address : Specify the address. For example, you can only monitor it through the local machine. You can set management.address = 127.0.0.1Restrictions on access to sensitive information
According to the above table, if the authentication is false , it means that it is insensitive and can be accessed at will. Otherwise, it will be protected and cannot be accessed at will.
endpoints.mappings.sensitive=false
This requires setting up each one, which is more troublesome. The sensitive method requires the user to have the ACTUATOR role by default, so you can also set the security restrictions on the off:
management.security.enabled=false
Or cooperate with Spring Security for fine-grained control.
Custom system information
You can obtain information through access /info , which needs to be set in the configuration file
info: aaa: name: xxx email: [email protected] bbb: age: 25 hobbies: running build: artifact: "@project.artifactId@" name: "@project.name@" version: "@project.version@"
At this time, visit localhost:8080/info to return the information
If you use maven , you can access the information of the pom.xml file, and the usage is as follows:
// Get the artifactId attribute under the project node in pom.xml artifact: "@project.artifactId@"
other
/shutdown requires a post method, and the application is closed through requests.
This operation is quite sensitive. To be effective, the following configuration is required:
endpoints.shutdown.enabled: true
We can write our own /health method logic by implementing the HealthIndicator interface. Custom monitoring methods can also be added.
For detailed introduction, please move to the official document
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.