springboot 运行状态监控Actuator 野性酷女 2022-03-26 06:46 430阅读 0赞 springboot 的 Actuator 提供了运行状态监控的功能,Actuator的监控数据可以通过REST、远程shell和JMX方式获得。 1、通过 REST 方式查看 Actuator 的节点的方法。 下 pom 文件中引入 Actuator 的依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>1.5.10.RELEASE</version> //可自行选择 </dependency> 在配置文件中 application.yaml 中配置 ,对外暴露的端口是 8888 ,如果不指定,端口为应用程序的启动端口; false:springboot 1.5x 版本默认开启了 Actuator 的安全验证,为了能够在浏览器上展示效果,不做安全验证,用false。 management: security: enabled: false port: 8888 2、Actuator 提供了13个API 接口 <table style="width:500px;"> <tbody> <tr> <td>类型</td> <td>API 接口</td> <td>描述</td> </tr> <tr> <td>GET</td> <td>/autoconfig</td> <td>提供了一份自动配置报告,记录哪些自动配置条件通过了,哪些没有通过</td> </tr> <tr> <td>GET</td> <td>/configprops</td> <td>描述配置属性如何注入Bean</td> </tr> <tr> <td>GET</td> <td>/beans</td> <td>描述应用程序上下文里全部的Bean,以及他们的关系</td> </tr> <tr> <td>GET</td> <td>/dump</td> <td>获取线程活动的快照</td> </tr> <tr> <td>GET</td> <td>/env</td> <td>获取全部环境属性</td> </tr> <tr> <td>GET</td> <td>/env/{name}</td> <td>根据名称获取特定的环境属性值</td> </tr> <tr> <td>GET</td> <td>/health</td> <td>应用程序的健康指标</td> </tr> <tr> <td>GET</td> <td>/info</td> <td>获取应用程序的信息</td> </tr> <tr> <td>GET</td> <td>/mappings</td> <td>描述全部URL路径,及它们和控制器(包括Actuator端点)的映射关系</td> </tr> <tr> <td>GET</td> <td>/metrics</td> <td>获取应用程序度量信息,比如内存用量和http请求计算</td> </tr> <tr> <td>GET</td> <td>/metrics/{name}</td> <td>获取程序指定名称的度量信息</td> </tr> <tr> <td>GET</td> <td>/shutdown</td> <td>关闭应用程序,要求endpoints.shutdown.enabled设值为true</td> </tr> <tr> <td>GET</td> <td>/trace</td> <td>提供基本的HTTP请求跟踪信息(时间戳,HTTP头)等</td> </tr> </tbody> </table> 3、查看健康状态 “[http://localhost:8888/][http_localhost_8888]health” ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4Mjg5NDA1_size_16_color_FFFFFF_t_70][] **springboot自带的健康指示器** ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4Mjg5NDA1_size_16_color_FFFFFF_t_70 1][] 4、查看运行程序 Bean [http://localhost:8000/beans][http_localhost_8000_beans] 了解springboot上下文注入了哪些 bean , 这些 bean 的 ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4Mjg5NDA1_size_16_color_FFFFFF_t_70 2][] 在返回消息中包含了Bean 的一下四类信息: bean : spring 应用程序上下文中的Bean 名称或 Id; resource : class 文件的物理位置,通常是一个 URL ,指向构建出的 jar 文件的路径; scope : Bean 的作用域(通常是单列 singleton , 也可以是 ptototype 、request 和 session)。 type : Bean 的类型; [http_localhost_8888]: http://192.168.11.189:8123/ [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4Mjg5NDA1_size_16_color_FFFFFF_t_70]: /images/20220326/ab17271d64b94a9f9a485a80bff4efd0.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4Mjg5NDA1_size_16_color_FFFFFF_t_70 1]: /images/20220326/19cb1cab1c2047219dcbfa225bf8ca4d.png [http_localhost_8000_beans]: http://localhost:8000/beans [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4Mjg5NDA1_size_16_color_FFFFFF_t_70 2]: /images/20220326/4bef72e0cc514b6288eb0a0a63620c6c.png
还没有评论,来说两句吧...