《深入理解Spring Cloud与微服务构建》学习笔记(四)~运行状态监控Actuator

Spring Boot 的 Actuator 提供了运行状态监控的功能, Actuator 监控数据可以通过REST、远程 shell 和JMX 方式获得。
主要是完成微服务的监控,完成监控治理。可以查看微服务间的数据处理和调用,当它们之间出现了异常,就可以快速定位到出现问题的地方。这里只看REST方式。

一、mavan项目在pom.xml中添加actuator依赖:

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

这样就已经引用成功了,启动程序,会看到控制台有如下信息:

在浏览器输入,控台输出的信息应该就是我们在浏览器可以访问的地址(看教程1.5是直接访问health和info,这里是2.0需要统一加上/actuator):
http://localhost:8080/actuator     
http://localhost:8080/actuator/health
http://localhost:8080/actuator/info

二、Actuator暴露的功能其实很多,这里默认只能访问到这三个路径的检测,据说其他功能点默认都是被禁止访问的,如果需要访问我们需要进行配置,经过验证,以下配置可以访问所有端点功能:

management:
  security:
    enable: false
  endpoints:
    web:
      exposure:
        include: "*"   #开启所有端点


Actuator暴露的功能:

HTTP方法 路径 描述 鉴权
GET /autoconfig 查看自动配置的使用情况 true
GET /configprops 查看配置属性,包括默认配置 true
GET /beans 查看bean及其关系列表 true
GET /dump 打印线程栈 true
GET /env 查看所有环境变量 true
GET /env/{name} 查看具体变量值 true
GET /health 查看应用健康指标 false
GET /info 查看应用信息 false
GET /mappings 查看所有url映射 true
GET /metrics 查看应用基本指标 true
GET /metrics/{name} 查看具体指标 true
POST /shutdown 关闭应用 true
GET /trace 查看基本追踪信息 true

再次启动程序,会发现控制台多了很多功能端点信息:

可以根据以上信息,在浏览器进行访问:
http://localhost:8080/actuator/beans
http://localhost:8080/actuator/metrics
http://localhost:8080/actuator/httptrace 
......
等等根据需要可以自行访问,反正目前我是基本看不懂.

三、还可以将程序端口和监控端口分开,如果不分开则默认都用程序端口,如果要分开,则需要重新配置监控端口,如:

重新启动应用,然后就可以分开访问了:
http://localhost:8080/h
http://localhost:9001/actuator/beans


 参考资料:

猜你喜欢

转载自blog.csdn.net/ssdate/article/details/83068359