SpringBoot集成Actuator端点配置
1.说明
Actuator端点可以监控应用程序并与之交互。
Spring Boot包括许多内置的端点,
比如health端点提供基本的应用程序运行状况信息,
并允许添加自定义端点。
可以控制每个单独的端点启用或禁用,
也可以通过include和exclude属性通配,
这会影响端点的Bean创建。
要远程访问端点,还必须通过JMX或HTTP公开。
大多数应用程序选择HTTP,
其中/actuator前缀和端点的ID组成了对外暴露的URL。
比如默认情况下,health端点映射到/actuator/health。
本文主要介绍通过HTTP进行监控和管理。
2.支持的端点
以下是与技术无关的端点:
| ID | 描述 |
|---|---|
| auditevents | 公开当前应用程序的审核事件信息。 |
| beans | 显示应用程序中所有Spring bean的完整列表。 |
| caches | 公开可用的缓存。 |
| conditions | 显示在配置和自动配置类上评估的条件,以及它们匹配或不匹配的原因。 |
| configprops | 显示所有@ConfigurationProperties的整理列表。 |
| env | 从Spring的ConfigurableEnvironment中公开属性。 |
| flyway | 显示已应用的所有Flyway数据库迁移。 |
| health | 显示应用程序运行状况信息。 |
| httptrace | 显示HTTP跟踪信息(默认情况下,最后100个HTTP请求-响应交换)。 |
| info | 显示任意应用程序信息。 |
| integrationgraph | 显示Spring集成图。 |
| loggers | 显示和修改应用程序中记录器的配置。 |
| liquibase | 显示已应用的任何Liquibase数据库迁移。 |
| metrics | 显示当前应用程序的"度量"信息。 |
| mappings | 显示所有@RequestMapping路径的整理列表。 |
| scheduledtasks | 显示应用程序中的计划任务。 |
| sessions | 允许从支持Spring Session的会话存储中检索和删除用户会话。在使用Spring Session对反应式web应用程序的支持时不可用。 |
| shutdown | 允许优雅地关闭应用程序。 |
| threaddump | 执行线程转储。 |
如果你的应用程序是 web 应用程序(Spring MVC、Spring WebFlux或Jersey),则可以使用以下附加端点:
| ID | 描述 | |
|---|---|---|
| heapdump | 返回hprof堆转储文件。 | |
| jolokia | 通过HTTP公开JMX bean(当Jolokia在类路径上时,WebFlux不可用)。 | |
| logfile | 返回日志文件的内容(如果已设置logging.file或logging.path属性)。支持使用 HTTP Range 头来检索日志文件的部分内容。 | Yes |
| prometheus | 以Prometheus服务器可以抓取的格式公开度量。 |
3.默认公开端点
由于端点可能包含敏感信息,
因此应仔细考虑何时公开它们。
下表显示了内置端点对于JMX或HTTP,
是否默认对外公开的情况:
| ID | JMX | HTTP |
|---|---|---|
| auditevents | Yes | No |
| beans | Yes | No |
| caches | Yes | No |
| conditions | Yes | No |
| configprops | Yes | No |
| env | Yes | No |
| flyway | Yes | No |
| health | Yes | Yes |
| heapdump | N/A | No |
| httptrace | Yes | No |
| info | Yes | Yes |
| integrationgraph | Yes | No |
| jolokia | N/A | No |
| logfile | N/A | No |
| loggers | Yes | No |
| liquibase | Yes | No |
| metrics | Yes | No |
| mappings | Yes | No |
| prometheus | N/A | No |
| scheduledtasks | Yes | No |
| sessions | Yes | No |
| shutdown | Yes | No |
| threaddump | Yes | No |
从上表可以看到HTTP默认对外公开2个端点,
只有health和info。
实际上公开的端点受到include和exclude属性控制,
下表显示了这两个属性的默认配置,
和上表能够一一对应起来,
其中包含web的属性对应的是HTTP的配置。
| 属性 | 默认 |
|---|---|
| management.endpoints.jmx.exposure.exclude | |
| management.endpoints.jmx.exposure.include | * |
| management.endpoints.web.exposure.exclude | |
| management.endpoints.web.exposure.include | info, health |
4.修改公开端点
只公开loggers端点:
management:
endpoints:
web:
exposure:
include: loggers
公开所有端点,但是要排除loggers和env端点:
management:
endpoints:
web:
exposure:
include: "*"
exclude:
- loggers
- env
注意*在YAML中具有特殊含义,
如果要包括(或排除)所有端点,
请务必添加引号。
另外如果想在公开端点时实现自定义策略,
可以注册EndpointFilter bean。
5.查看所有公开端点
通过修改配置,公开所有端点后,
浏览器访问Actuator提供的管理URL:
http://localhost:8011/actuator
返回结果:
{
"_links": {
"self": {
"href": "http://localhost:8011/actuator",
"templated": false
},
"beans": {
"href": "http://localhost:8011/actuator/beans",
"templated": false
},
"caches-cache": {
"href": "http://localhost:8011/actuator/caches/{cache}",
"templated": true
},
"caches": {
"href": "http://localhost:8011/actuator/caches",
"templated": false
},
"health": {
"href": "http://localhost:8011/actuator/health",
"templated": false
},
"health-path": {
"href": "http://localhost:8011/actuator/health/{*path}",
"templated": true
},
"info": {
"href": "http://localhost:8011/actuator/info",
"templated": false
},
"conditions": {
"href": "http://localhost:8011/actuator/conditions",
"templated": false
},
"configprops": {
"href": "http://localhost:8011/actuator/configprops",
"templated": false
},
"env": {
"href": "http://localhost:8011/actuator/env",
"templated": false
},
"env-toMatch": {
"href": "http://localhost:8011/actuator/env/{toMatch}",
"templated": true
},
"loggers": {
"href": "http://localhost:8011/actuator/loggers",
"templated": false
},
"loggers-name": {
"href": "http://localhost:8011/actuator/loggers/{name}",
"templated": true
},
"heapdump": {
"href": "http://localhost:8011/actuator/heapdump",
"templated": false
},
"threaddump": {
"href": "http://localhost:8011/actuator/threaddump",
"templated": false
},
"metrics-requiredMetricName": {
"href": "http://localhost:8011/actuator/metrics/{requiredMetricName}",
"templated": true
},
"metrics": {
"href": "http://localhost:8011/actuator/metrics",
"templated": false
},
"scheduledtasks": {
"href": "http://localhost:8011/actuator/scheduledtasks",
"templated": false
},
"httptrace": {
"href": "http://localhost:8011/actuator/httptrace",
"templated": false
},
"mappings": {
"href": "http://localhost:8011/actuator/mappings",
"templated": false
}
}
}
发现对外开放了14个端点,
没有对外开放的端点还有9个:
auditevents, flyway, integrationgraph, jolokia, logfile,
liquibase, prometheus, sessions, shutdown。
6.启用端点
上面介绍了公开端点的配置,
但是即使公开了所有端点,
也不一定能看到对应的端点。
上面还有9个端点没有对外开放,
原因是有2个,
一个端点是没有启用,
另一个是端点因为没有相关的功能实现,
所以暴露出去也没有用。
而且除shutdown以外,
所有端点是默认启用的。
下面演示启用shutdown端点:
management:
endpoint:
shutdown:
enabled: true
7.禁用端点(通配)
禁用端点可以通过设置对应ID为faslse,
下面演示关闭logger端点:
management:
endpoint:
loggers:
enabled: false
也可以通过设置所有端点的开启默认值为fasle,
从而禁用所有端点,
然后再启用特定端点,
下面演示禁用所有端点,
只启用shutdown端点:
management:
endpoints:
enabled-by-default: false
endpoint:
shutdown:
enabled: true
同样的启用所有端点,
只禁用shutdown端点:
management:
endpoints:
enabled-by-default: true
endpoint:
shutdown:
enabled: false
8.公开端点和启用端点的区别
只有一个端点同时公开和启用了才能访问到;
一个端点启用后,
可以选择在JMX公开,
而不在HTTP公开;
一个端点禁用后,
不管在JMX或者HTTP是否公开,
都无法被访问到。
从而实现更细致的控制管理。
9.自定义管理端点的路径
可以为管理端点自定义前缀,
特别是已经将/actuator用于其他目的,
下面修改管理端点的前缀为/manage:
management:
endpoints:
web:
base-path: /manage
重启服务后,原来的管理URL不能再访问:
http://localhost:8011/actuator
应该访问新的管理URL:
http://localhost:8011/manage
而且其下的health等其他端点也变成新的URL:
http://localhost:8011/manage/health
如果把管理端点路径设置为/或者空时,
将禁用管理URL,
以防止与其他映射发生冲突。
10.自定义普通端点的路径
可以将端点映射到不同的路径,
下面以健康检查为例,
演示将/actuator/health映射到/actuator/healthcheck:
management:
endpoints:
web:
path-mapping:
health: healthcheck
重启服务后,原来的健康URL不能再访问:
http://localhost:8011/actuator/health
应该访问新的健康URL:
http://localhost:8011/actuator/healthcheck
进一步修改管理端点路径设置为/:
management:
endpoints:
web:
path-mapping:
health: healthcheck
base-path: /
虽然不能访问管理URL,
但是可以访问更短的健康URL:
http://localhost:8011/healthcheck
SpringBoot集成Actuator端点配置的更多相关文章
- springboot集成Actuator
Actuator监控端点,主要用来监控与管理. 原生端点主要分为三大类:应用配置类.度量指标类.操作控制类. 应用配置类:获取应用程序中加载的配置.环境变量.自动化配置报告等与SpringBoot应用 ...
- SpringBoot集成actuator模块的基本使用
© 版权声明:本文为博主原创文章,转载请注明出处 1. 版本 SpringBoot:2.0.0.RELEASE 2. 集成 SpringBoot集成actuator模块非常简单,只需要引入actuat ...
- SpringBoot集成Swagger2并配置多个包路径扫描
1. 简介 随着现在主流的前后端分离模式开发越来越成熟,接口文档的编写和规范是一件非常重要的事.简单的项目来说,对应的controller在一个包路径下,因此在Swagger配置参数时只需要配置一 ...
- SpringBoot集成Actuator监控管理
1.说明 本文详细介绍Spring Boot集成Actuator监控管理的方法, 基于已经创建好的Spring Boot工程, 然后引入Actuator依赖, 介绍监控管理相关功能的使用. Sprin ...
- springboot集成Apollo分布式配置
安装Apollo服务 1.安装mysql 地址:https://www.cnblogs.com/xuaa/p/10782352.html 2.下载Apollo源码到本地 地址:https://gith ...
- SpringBoot集成Actuator健康指示器health
1.说明 本文详细介绍Actuator提供的HealthIndicators, 即健康指示器的配置使用, 利用自动配置的健康指标, 检查正在运行的应用程序的状态, 以及自定义健康指标的方法. 监控软件 ...
- SpringBoot集成Mybatis(0配置注解版)
Mybatis初期使用比较麻烦,需要各种配置文件.实体类.dao层映射关联.还有一大推其它配置.当然Mybatis也发现了这种弊端,初期开发了generator可以根据表结构自动生成实体类.配置文件和 ...
- apollo与springboot集成实现动态刷新配置
分布式apollo简介 Apollo(阿波罗)是携程框架部门研发的开源配置管理中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性. 本 ...
- 分享知识-快乐自己:SpringBoot集成热部署配置(一)
摘要: 热部署与热加载: ava热部署与Java热加载的联系和区别: 1):Java热部署与热加载的联系: 1.不重启服务器编译/部署项目 2.基于Java的类加载器实现 2):Java热部署与热加载 ...
随机推荐
- Linux学习 - 数值运算
1 declare 声明变量类型 declare [+/-] [选项] 变量名 - 给变量设定类型属性 + 取消变量的类型属性 -i 将变量声明为整数型 -x 将变量声明为环境变量(同export) ...
- 【编程思想】【设计模式】【结构模式Structural】桥梁模式/桥接模式bridge
Python版 https://github.com/faif/python-patterns/blob/master/structural/bridge.py #!/usr/bin/env pyth ...
- jdk1.7源码之-hashMap源码解析
背景: 笔者最近这几天在思考,为什么要学习设计模式,学些设计模式无非是提高自己的开发技能,但是通过这一段时间来看,其实我也学习了一些设计模式,但是都是一些demo,没有具体的例子,学习起来不深刻,所以 ...
- Boss直聘App上“天使投资、VC、PE” 与“A轮、B轮、C轮融资”的关系
我们经常看到朋友圈里某某公司获得了某轮融资,所谓的A轮B轮究竟是个什么概念呢?今天就跟小伙伴们分享一下A.B.C.D轮融资与天使投资.VC.PE的关系. 天使投资(AI):天使投资所投的是一些非常早期 ...
- vue3 到底哪里好?看这一篇就够了
之前写的关于 vue3 的文章,好多人吐槽:这些API每次使用都要引入一遍,感觉有点麻烦. 今天我们就来看看 vue3 相比 vue2 的优点有些啥? 为啥有些人说:自从写了 ts vue3 再也回不 ...
- LuoguB2104 矩阵加法 题解
Content 给定两个 \(n\times m\) 的矩阵 \(A,B\),求 \(C=A+B\). 数据范围:\(1\leqslant n,m\leqslant 100\). Solution 我 ...
- 分布式文件系统fastdfs安装以及python调用
fastfds的安装和使用 一.所需依赖 操作系统:centos7.x(注意的是centos使用yum安装相关依赖) fastdfs:V6.06.tar.gz libfastcommon:V1.0.4 ...
- clickhouse配置登录密码
执行 PASSWORD=$(base64 < /dev/urandom | head -c8); echo "123456"; echo -n "123456&qu ...
- JAVA实现导出excel功能,封装通用导出工具类
引入maven <!--excel导出--> <dependency> <groupId>net.sourceforge.jexcelapi</groupId ...
- 【LeetCode】370. Range Addition 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 只修改区间起终点 日期 题目地址:https://le ...