1、简介
干嘛的:
主要运用在微服务架构,所以我建议你先学微服务,否则可能get不到它的用处,只有大型的分布式系统才会用到指标监控… Why:?
对于一个大型的几十个、几百个微服务构成的微服务架构系统,在线上时通常会遇到下面一些问题,比如:
- 如何知道哪些服务除了问题,如何快速定位? (健康状况)
- 如何统一监控各个微服务的性能指标(内存、jvm、并发数、线程池、Http 请求统计)
- 如何统一管理各个微服务的日志?(切换线上日志等级,快速搜索日志…)
- 如何优雅管理服务下线(正在运行的线程不发生中断)
So: 在这种大型分布式应用的环境下,我们如何能够快速发现问题、快速解决问题, 必须要有监控平台、(链路追踪、日志)
2、SpringBoot Actuator
介绍:
SpringBoot自带监控功能Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变 量、日志信息、线程信息等
实现:
1 <dependency>
2 <groupId>org.springframework.boot</groupId>
3 <artifactId>spring‐boot‐starter‐actuator</artifactId>
4 </dependency>
引入场景
访问 http://localhost:8080/actuator/**
暴露所有监控信息为HTTP
1 management:
2 endpoints:
3 enabled‐by‐default: true # 默认开启所有监控端点4 web:
5 exposure:
6 include: '*' # 以web方式暴露所有端点
7
测试
http://localhost:8080/actuator/beans http://localhost:8080/actuator/configprops http://localhost:8080/actuator/metrics http://localhost:8080/actuator/metrics/jvm.gc.pause http://localhost:8080/actuator/endpointName/detailPath 。。。。。。
Actuator Endpoint
常用的端点
Health:监控状况
一个组件指标状态为Down则总状态信息Down,很多组件中都定制了Health子节点指标: 比如jdbc、redis、等等
shutdown:优雅关闭
注意需要web服务器的支持
1 server:
2 shutdown: