SpringBoot-Actuator 末蓝、 2022-05-20 22:36 236阅读 0赞 * * * 摘要 * 使用 ### 摘要 ### 本文介绍如何使用Actuator。 Actuator提供了HTTP和JMX接口便于查看程序运行时的某些信息,如:容器中的bean信息、自动配置类匹配信息等。 > 本文内容来自SpringBoot参考手册 > [https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/\#production-ready][https_docs.spring.io_spring-boot_docs_2.0.0.RELEASE_reference_htmlsingle_production-ready] ### 使用 ### * 加入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> * 配置端点启用及暴露 SpringBoot2.0默认启用shutdown以外的端点,但并不暴露。 启用端点 management.endpoint.<id>.enabled // 示例:启用shutdown端点 management.endpoint.shutdown.enable=true 暴露端点 // 通过jmx暴露或隐藏端点 management.endpoints.jmx.exposure.exclude management.endpoints.jmx.exposure.include 默认* // 通过http暴露或隐藏端点 management.endpoints.web.exposure.exclude management.endpoints.web.exposure.include 默认:info,health // 示例:暴露beans端点 management.endpoints.web.exposure.include=beans * 启动程序查看控制台 可以看到输出的启用端点 2018-06-26 18:49:56.563 |-INFO [restartedMain] org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping [87] -| Mapped "{[/actuator/beans],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>) 2018-06-26 18:49:56.565 |-INFO [restartedMain] org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping [87] -| Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) * 常用端点 <table> <thead> <tr> <th>端点</th> <th>请求方式</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>autoconfig</td> <td>GET</td> <td>自动配置类匹配信息</td> </tr> <tr> <td>beans</td> <td>GET</td> <td>容器中所有的bean</td> </tr> <tr> <td>configprops</td> <td>GET</td> <td>@ConfigurationProperties配置类属性</td> </tr> <tr> <td>dump</td> <td>GET</td> <td>线程活动信息</td> </tr> <tr> <td>env</td> <td>GET</td> <td>环境变量</td> </tr> <tr> <td>health</td> <td>GET</td> <td>健康指数</td> </tr> <tr> <td>info</td> <td>GET</td> <td>应用信息。可以自定义info.*定义info公开的数据</td> </tr> <tr> <td>mappings</td> <td>GET</td> <td>所有的URL路径</td> </tr> <tr> <td>metrics</td> <td>GET</td> <td>系统的度量指数</td> </tr> <tr> <td>shutdown</td> <td>POST</td> <td>关闭应用。默认不开启</td> </tr> <tr> <td>trace</td> <td>GET</td> <td>默认显示最近100个请求的跟踪信息</td> </tr> </tbody> </table> [https_docs.spring.io_spring-boot_docs_2.0.0.RELEASE_reference_htmlsingle_production-ready]: https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#production-ready
还没有评论,来说两句吧...