微服务之服务监控篇 Actuator
服务监控
- 什么是服务监控?
- 主要是查看当前系统的运行状态,例如内存、线程、堆栈、日志等等,通过服务监控可以快速准确的发现问题,以减少或避免对用户的影响.
- 为什么使用服务监控
- 随着功能的拆分. 微服务越来越多,相互调用出错的概率也越来越大,如果不能及时发现问题会引起灾难性后果.
Spring Boot Actuator &Admin
- actuator是监控系统健康情况的工具,admin是一个针对spring-boot的actuator接口进行UI美化封装的监控工具
入门小demo
-
创建SpringBoot项目版本2.3.5.RELEASE
-
引入依赖
<!-- SpringBoot Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>2.3.5.RELEASE</version> </dependency>
-
application.yml配置
management: endpoints: web: exposure: include: '*' # 暴露所有的监控点
-
启动项目并访问:
http://localhost:8080/actuator
服务端返回
-
好丑啊,看不下去.
-
添加依赖并在启动类添加@EnableAdminServer注解
<!-- SpringBoot Admin --> <dependency> <groupId>de.codecentric</groupId> <artifactId