springboot之Actuator
1、Actuator 介绍
Actuator是Springboot提供的用来对应用系统进行自省和监控的功能模块,借助于Actuator开发者可以很方便地对应用系统某些监控指标进行查看、统计等。
Actuator 的核心是端点 Endpoint,它用来监视应用程序及交互,spring-boot-actuator 中已经内置了非常多的 Endpoint(health、info、beans、metrics、httptrace、shutdown等等),同时也允许我们自己扩展自己的 Endpoints。每个 Endpoint 都可以启用和禁用。要远程访问 Endpoint,还必须通过 JMX 或 HTTP 进行暴露,大部分应用选择HTTP。
2、Actuator 使用
2.1、依赖
<!-- 引入Actuator监控依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.2、配置
需要注意的是 Spring Boot 2.0 相对于上个版本, Actuator 发生很多变化,keys 的配置改变如下:
旧的属性 | 新的属性 |
---|---|
endpoints.<id>.*
|
management.endpoint.<id>.*
|
endpoints.cors.*
|
management.endpoints.web.cors.*
|
endpoints.jmx.*
|
management.endpoints.jmx.*
|
management.address
|
management.server.address
|
management.context-path
|
management.server.servlet.context-path
|
management.ssl.*
|
management.server.ssl.*
|
management.port
|
management.server.port
|
application.yml 配置
management:
endpoints:
# 暴露 EndPoint 以供访问,有jmx和web两种方式,exclude 的优先级高于 include
jmx:
exposure:
exclude: '*'
include: '*'
web:
exposure:
# exclude: '*'
include: ["health","info","beans","mappings","logfile","metrics","shutdown","env"]
base-path: /actuator # 配置 Endpoint 的基础路径
cors: # 配置跨域资源共享
allowed-origins: http://example.com
allowed-methods: GET,POST
enabled-by-default: true # 修改全局 endpoint 默认设置
endpoint:
auditevents: # 1、显示当前引用程序的审计事件信息,默认开启
enabled: true
cache:
time-to-live: 10s # 配置端点缓存响应的时间
beans: # 2、显示一个应用中所有 Spring Beans 的完整列表,默认开启
enabled: true
conditions: # 3、显示配置类和自动配置类的状态及它们被应用和未被应用的原因,默认开启
enabled: true
configprops: # 4、显示一个所有@ConfigurationProperties的集合列表,默认开启
enabled: true
env: # 5、显示来自Spring的 ConfigurableEnvironment的属性,默认开启
enabled: true
flyway: # 6、显示数据库迁移路径,如果有的话,默认开启
enabled: true
health: # 7、显示健康信息,默认开启
enabled: true
show-details: always
info: # 8、显示任意的应用信息,默认开启
enabled: true
liquibase: # 9、展示任何Liquibase数据库迁移路径,如果有的话,默认开启
enabled: true
metrics: # 10、展示当前应用的metrics信息,默认开启
enabled: true
mappings: # 11、显示一个所有@RequestMapping路径的集合列表,默认开启
enabled: true
scheduledtasks: # 12、显示应用程序中的计划任务,默认开启
enabled: true
sessions: # 13、允许从Spring会话支持的会话存储中检索和删除(retrieval and deletion)用户会话。使用Spring Session对反应性Web应用程序的支持时不可用。默认开启。
enabled: true
shutdown: # 14、允许应用以优雅的方式关闭,默认关闭
enabled: true
threaddump: # 15、执行一个线程dump
enabled: true
# web 应用时可以使用以下端点
heapdump: # 16、 返回一个GZip压缩的hprof堆dump文件,默认开启
enabled: true
jolokia: # 17、通过HTTP暴露JMX beans(当Jolokia在类路径上时,WebFlux不可用),默认开启
enabled: true
logfile: # 18、返回日志文件内容(如果设置了logging.file或logging.path属性的话),支持使用HTTP Range头接收日志文件内容的部分信息,默认开启
enabled: true
prometheus: #19、以可以被Prometheus服务器抓取的格式显示metrics信息,默认开启
enabled: true
基本路径
所有 endpoints 默认情况下都已移至
/actuator
。就是多了跟路径actuator
;上个版本中的
management/context-path:
和management/port:
改为 :management:server:port: 8004servlet:context-path: /xxx # 只有在设置了 management.server.port 时才有效
另外,您还可以使用新的单独属性
management.endpoints.web.base-path
为管理端点设置基本路径。例如,如果你设置
management.server.servlet.context-path=/management
和management.endpoints.web.base-path=/application
,你就可以在下面的路径到达终点健康:/management/application/health
。如果你想恢复 1.x 的行为(即具有
/health
代替/actuator/health
),设置以下属性:management.endpoints.web.base-path=/
2.3、ENDPOINTS
1.X 的时候属性:
HTTP 方法 | 路径 | 描述 |
---|---|---|
GET | /autoconfig | 提供了一份自动配置报告,记录哪些自动配置条件通过了,哪些没通过 |
GET | /configprops | 描述配置属性(包含默认值)如何注入Bean |
GET | /beans | 描述应用程序上下文里全部的Bean,以及它们的关系 |
GET | /dump | 获取线程活动的快照 |
GET | /env | 获取全部环境属性 |
GET | /env/{name} | 根据名称获取特定的环境属性值 |
GET | /health | 报告应用程序的健康指标,这些值由HealthIndicator的实现类提供 |
GET | /info | 获取应用程序的定制信息,这些信息由info打头的属性提供 |
GET | /mappings | 描述全部的URI路径,以及它们和控制器(包含Actuator端点)的映射关系 |
GET | /metrics | 报告各种应用程序度量信息,比如内存用量和HTTP请求计数 |
GET | /metrics/{name} | 报告指定名称的应用程序度量值 |
POST | /shutdown | 关闭应用程序,要求endpoints.shutdown.enabled设置为true |
GET | /trace | 提供基本的HTTP请求跟踪信息(时间戳、HTTP头等) |
2.0 部分更改:
1.x 端点 | 2.0 端点(改变) |
---|---|
/actuator
|
不再可用。 但是,在 management.endpoints.web.base-path 的根目录中有一个映射,它提供了到所有暴露端点的链接。
|
/auditevents
|
该after 参数不再需要
|
/autoconfig
|
重命名为 /conditions
|
/docs
|
不再可用 |
/health
|
现在有一个 management.endpoint.health.show-details 选项 never , always , when-authenticated ,而不是依靠 sensitive 标志来确定 health 端点是否必须显示全部细节。 默认情况下,/actuator/health 公开并且不显示细节。
|
/trace
|
重命名为 /httptrace
|
默认端点 path 前面多了一级 /actuator
。
同时注意只有端点/health
和/info
端点是暴露的。
Property | Default |
---|---|
management.endpoints.jmx.exposure.exclude
|
|
management.endpoints.jmx.exposure.include
|
*
|
management.endpoints.web.exposure.exclude
|
|
management.endpoints.web.exposure.include
|
info, health
|
- 您可以按如下方式公开所有端点:
management.endpoints.web.exposure.include=*
- 您可以通过以下方式显式启用
/shutdown
端点:management.endpoint.shutdown.enabled=true
- 要公开所有(已启用)网络端点除
env
端点之外:
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env
例如:
我现在开启所有的端点:
management:endpoints:web:exposure:include: "*" # * 在yaml 文件属于关键字
执行 localhost:${port}/actuator
,可以看到所有可以执行查看的端点监控的 Url,然后我们尝试执行关闭应用进程的指令:shutdown
:
端点格式
/actuator/mappings
端点大改变
JSON 格式已经更改为现在正确地包含有关上下文层次结构,多个DispatcherServlets,
部署的 Servlet 和 Servlet 过滤器的信息。详情请参阅#9979。
Actuator API 文档的相关部分提供了一个示例文档。/actuator/httptrace
端点大改变
响应的结构已经过改进,以反映端点关注跟踪 HTTP 请求 - 响应交换的情况
参考文章
Spring Boot 2.0 中使用 Actuator
springboot之Actuator相关推荐
- SpringBoot集成Actuator端点配置
1.说明 Actuator端点可以监控应用程序并与之交互. Spring Boot包括许多内置的端点, 比如health端点提供基本的应用程序运行状况信息, 并允许添加自定义端点. 可以控制每个单独的 ...
- SpringBoot集成Actuator监控管理
1.说明 本文详细介绍Spring Boot集成Actuator监控管理的方法, 基于已经创建好的Spring Boot工程, 然后引入Actuator依赖, 介绍监控管理相关功能的使用. Sprin ...
- springboot集成Actuator
Actuator监控端点,主要用来监控与管理. 原生端点主要分为三大类:应用配置类.度量指标类.操作控制类. 应用配置类:获取应用程序中加载的配置.环境变量.自动化配置报告等与SpringBoot应用 ...
- springboot整合Actuator监控
springboot整合Actuator监控. 1.简要说明: Actuator提供了对springboot应用程序监视和管理的能力,可以选择通过使用HTTP Endpoint或者使用JMX来管理和监 ...
- SpringBoot监控Actuator,关闭redis监测
SpringBoot监控Actuator,关闭redis监测 方法 方法 当我们导入了spring-boot-starter-actuator这个依赖后, SpringBoot会默认去监测一些信息.其 ...
- SpringBoot:Actuator 监控管理工程各项信息
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 在微服务体系中,有很多工程相互作用,如果其中某一个Down 了,可能就不是那么容易快速定位 bug ...
- Springboot之actuator配置不当漏洞(autoconfig、configprops、beans、dump、env、health、info、mappings、metrics、trace)
前言 Actuator 是 springboot 提供的用来对应用系统进行自省和监控的功能模块,借助于 Actuator 开发者可以很方便地对应用系统某些监控指标进行查看.统计等.在 Actuator ...
- SpringBoot集成Actuator健康指示器health
1.说明 本文详细介绍Actuator提供的HealthIndicators, 即健康指示器的配置使用, 利用自动配置的健康指标, 检查正在运行的应用程序的状态, 以及自定义健康指标的方法. 监控软件 ...
- springboot 集成 actuator
简介 spring-actuator做度量统计收集,使用Prometheus(普罗米修斯)进行数据收集,Grafana(增强ui)进行数据展示,用于监控生成环境机器的性能指标和业务数据指标.一般,我们 ...
- Springboot使用Actuator健康监控以及可视化界面
前言 我们的微服务在云上部署以后都需要对其进行监控.追踪.审计.控制等.SpringBoot就抽取了Actuator场景,使得我们每个微服务快速引用即可获得生产级别的应用监控.审计等功能. DEMO ...
最新文章
- 程序员:提高编程效率的技巧
- c++ RTTI(运行时类型识别)
- 如何使用JavaScript将数据附加到div?
- 005_CSS通配符选择器
- Qt第三方库QCustomPlot——认识图表的各个部分
- 大地win11 32位旗舰版镜像v2021.08
- 在用v-for时又想用v-if进行判断是否生产内容
- 【Python-2.7】换行符和制表符
- Redis源码阅读 (深入理解字符串)
- 国产达梦数据库管理系统-通过Excel文件导入数据
- 拓端tecdat|R语言惩罚logistic逻辑回归(LASSO,岭回归)高维变量选择的分类模型案例
- 第13章 用序列化保存模型
- win10系统如何安装SQL服务器,在Win10系统上正确安装SQL Server
- 医院时钟系统,NTP子钟,网络子母钟系统,ntp子母钟,网络子母钟——为您的系统保驾护航
- centos7 “v篇n“工具
- Several ports (8005, 8080, 8009) required by demo are already in use. The server may already be runn
- 配置 hosts 浏览器访问仍然不生效
- ADC采集数据求平均
- matlab获得模型切面,基于MATLAB的STL模型切片分层算法
- 2020微信最新版可以修改ID号了,你的号码还那么尬么?
热门文章
- 奥比中光 Astra pro 深度相机在ROS Melodic的调试
- android 地铁地图api,百度地铁图JS API使用
- Linux查看硬件信息以及驱动设备的命令
- 异构计算(CPU + GPU)编程简介
- suricata 命令
- 笔记本计算机忘记密码,Windows笔记本电脑忘记开机登录密码忘记怎么办 最新win7/8/10开机密码重置教程...
- wildfly部署springboot项目
- 他,生物系毕业,刚入职连Java都没听过,却在马云的要求下,三周写出淘宝网雏形...
- 0和5 (51Nod)
- 卫康直销如何安全的参与中国MMM互助金融社区系统?