《Spring Boot框架入门到实践》(18)spring boot Actuator(服务监控)

其他博主的详解
在生产环境中,需要实时或定期监控服务的可用性, spring-boot的actuator功能提供了很多监控所需的接口;
actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、健康检查、相关功能统计等;
如何实用该功能那?

  1. 在项目的Maven中添入如下依赖:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  1. 在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提供的主要监控项。
在这里插入图片描述
详细使用可以查看上方其他博主的详解。

发布了24 篇原创文章 · 获赞 10 · 访问量 739

猜你喜欢

转载自blog.csdn.net/qq_43581078/article/details/103688234