In a production environment, the availability of services needs to be monitored in real time or regularly. The Spring-boot Actuator (monitoring) feature provides many of the interfaces required for monitoring. The simple configuration and use are as follows:
1, the introduction of dependency:
[HTML] view plain copy <dependency> <groupId>org.springframework.boot</groupId> & Lt;artifactid>spring-boot-starter-actuator</artifactid> </dependency>
This dependency is also required if the HTTP call is used:
[HTML] view plain copy <dependency> <groupId>org.springframework.boot</groupId> & Lt;artifactid>spring-boot-starter-web</artifactid> </dependency>
2. Configuration:
The HTTP port specified in APPLICATION.YML (if not specified, uses the same port as the server); Specifies that a check is removed (such as not monitoring Health.mail):
[plain] view plain copy server:port:8082 management:port:54001 health:mail:en Abled:false
3. Use: View the health indicator: http://localhost:54001/health
[plain] view plain copy {"status": "Up", "diskspace": {' status ': ' Up ', ' total ': 120031539200, "free": 33554337792 , "Threshold": 10485760}, "db": {"status": "Up", "DataSource1": {"status": "Up", "Database": "MySQL", "Hello": 1}, " DataSource2 ": {" status ":" Up "," Database ":" MySQL "," Hello ": 1}}}
4. Custom indicators:
4.1/health: Implements the Healthindicator interface in a class, and then implement the health () method in it:
Code:
[Java] View plain copy @SpringBootApplication @EnableScheduling public class MySpringBootApplication implements HealthIndicator{ private static logger logger = loggerfactory.getlogger (Myspringbootapplication.class); public static void main ( String[] args) { springapplication.run ( Myspringbootapplication.class, args); Logger.info ("my spring boot application started"); } /** * when the/health interface is called, Returns one more attribute: ' myspringbootapplication ': {' status ': ' Up ', ' Hello ': ' World '} */ &NBSP;&NBSP; @Override public health health () {