其他博主的详解
在生产环境中,需要实时或定期监控服务的可用性, spring-boot的actuator功能提供了很多监控所需的接口;
actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、健康检查、相关功能统计等;
如何实用该功能那?
- 在项目的Maven中添入如下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- 在spring boot核心配置文件中指定监控的HTTP端口;
如果不知道则使用和server相同的端口,比如:
#服务运行的端口
server.port=8080
#Actuator监控的端口(端口可配可不配)
management.server.port=8100
#Actuator的上下文(可配可不配,不配就用tomcat的上下文)
management.server.servlet.context-path=/springboot-mybatis-1
#默认只开启health和info,设置为*,则包含所有的web入口的端点
management.endpoints.web.exposure.include=*
举例访问:http://localhost:8100/springboot-mybatis-1/actuator/health
表示监控正常
访问时必须加一个actuator,否则会404。
也可以访问http://localhost:8100/springboot-mybatis-1/actuator/info
表示为空
3. 下表包含了Actuator提供的主要监控项。
详细使用可以查看上方其他博主的详解。