SpringBoot入门教程(十)应用监控Actuator

Actuator可能大家非常熟悉,它是springboot提供对应用自身监控,以及对应用系统配置查看等功能。spring-boot-starter-actuator模块的实现对于实施微服务的中小团队来说,可以有效地减少监控系统在采集应用指标时的开发量。当然,它也并不是万能的,有时候我们也需要对其做一些简单的扩展来帮助我们实现自身系统个性化的监控需求。下面,在本文中,我们将详解的介绍一些关于spring-boot-starter-actuator模块的内容,包括它的原生提供的端点以及一些常用的扩展和配置方式。

v添加引用

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

查看日志:

SpringBoot入门教程(十)应用监控Actuator

我们发现,在Spring Boot 2.0中Actuator只暴露了health和info端点,其它的一堆怎么也打不开。后来看文档找到了原因:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-endpoints

更新application.properties management.endpoints.web.exposure.include=*

更新application.properties以后再查看日志:

SpringBoot入门教程(十)应用监控Actuator

运行项目以后,访问http://localhost:8080/actuator,所有的相关信息都在这可以看到。

SpringBoot入门教程(十)应用监控Actuator

SpringBoot入门教程(十)应用监控Actuator

v更多介绍

介绍一下红框内的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

v源码地址

https://github.com/toutouge/javademosecond/tree/master/hellospringboot


作  者:请叫我头头哥
出  处:http://www.cnblogs.com/toutou/
关于作者:专注于基础平台的项目开发。如有问题或建议,请多多赐教!
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是作者坚持原创和持续写作的最大动力!

原文地址:https://www.cnblogs.com/toutou/p/9804083.html