温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SpringBoot2如何开启Actuator端点监控

发布时间:2022-06-13 09:25:10 来源:亿速云 阅读:213 作者:zzz 栏目:开发技术

今天小编给大家分享一下SpringBoot2如何开启Actuator端点监控的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

背景

SpringBoot本身提供了一套监控端点, 可以查看应用的基本信息、 健康程度、 配置等监控信息, 很容易上手。

Note: 此处所用SpringBoot版本: 2.1.4

开启Actuator

在Maven的pom.xml文件中添加 spring-boot-starter-actuator 依赖:

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

直接运行项目, 在后端控制台会看到以下输出:

2019-06- 26 18: 07: 27.896 INFO 7868-- - [restartedMain] o.s.b.a.e.web.EndpointLinksResolver: Exposing 2 endpoint(s) beneath base path '/actuator'

在浏览器访问 http://localhost:9000/actuator , 结果如下:

SpringBoot2如何开启Actuator端点监控

即SpringBoot2.0的actuator启动端点监控web端默认加载默认仅info, health两个可见的端点(除了actuator本身之外), 见官方文档说明

暴露其他端点(与SpringBoot 2.0之前的配置不太一样)

management:
  endpoints:
    web:
      exposure:
        include: "*"
        exclude: env,beans

以上配置暴露了除 env , beans 之外的所有端点; 修改配置后, 在后端控制台会看到以下输出:

2019-06-26 18: 16: 03.951 INFO 7868-- - [restartedMain] o.s.b.a.e.web.EndpointLinksResolver: Exposing 13 endpoint(s) beneath base path '/actuator'

再次在浏览器访问 http://localhost:9000/actuator , 结果如下:

SpringBoot2如何开启Actuator端点监控

SpringBoot2如何开启Actuator端点监控

SpringBoot2如何开启Actuator端点监控

SpringBoot2如何开启Actuator端点监控

Notes:

  • 虽然端点 enabled , 但是还需要 exposed , 才能在Web端访问;

  • health 端点在默认情况下, 仅显示 "status": "UP" ; 如需显示详细信息, 配置: management.endpoint.health.show-details=always

  • 实际中, 请谨慎选择要开启的端点!

以上配置仅实现了对应用监控信息的获取, 但其实已经有专门用于展现这些 json 数据的管理端, 后续将实践一下SpringBoot Admin这套社区提供的可视化应用监控管理端。 SpringBoot Admin 文档对自己的介绍:

codecentric&rsquo; s Spring Boot Admin is a community project to manage and monitor your Spring Boot&reg; applications.The applications register with our Spring Boot Admin Client(via HTTP) or are discovered using Spring Cloud&reg;(e.g.Eureka, Consul).The UI is just a Vue.js application on top of the Spring Boot Actuator endpoints.

以上就是“SpringBoot2如何开启Actuator端点监控”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI