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热部署与热加载 ...
随机推荐
- spring注解事务管理
使用步骤: 步骤一.在spring配置文件中引入<tx:>命名空间<beans xmlns="http://www.springframework.org/schema/b ...
- proxysql+MHA+半同步复制
先配置成主从同步 先在各节点安装服务 [root@inotify ~]# yum install mariadb-server -y 编辑主节点的配置文件,并启动 [root@centos7 ~]# ...
- jQuery全局进行方法扩展
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>01 ...
- 使用OPC与PLC通讯 一
总结自己在opc与自控开发的经验.首先介绍OPC DA模式下的OPC各种操作. 在使用opc时需要引用到 OPCDAAuto.dll 这个类库. 在项目引用后需要注册这个类库,否则程序跑起来会报错,& ...
- 使用plantuml,业务交接就是这么简单
使用plantuml,业务交接就是这么简单 你好,我是轩脉刃. 最近交接了一个业务,原本还是有挺复杂的业务逻辑的,但发现交接过来的项目大有文章,在项目代码中有一个docs文件夹,里面躺着若干个 pum ...
- [BUUCTF]REVERSE——[GKCTF2020]Check_1n
[GKCTF2020]Check_1n 附件 步骤: 例行查壳儿,32位程序,无壳儿 32位ida载入,习惯性的检索程序里的字符串,看到了一个比较有意思的字符串,但是不懂是什么解密,先不管它了 在这些 ...
- Spring事务什么时候会失效?
面试官:Spring事务什么时候会失效? 应聘者: 访问权限问题 方法用final修饰 未被Spring管理 错误的传播特性 自己吞了异常 手动抛了别的异常 自定义了回滚异常 方法内部调用 1.访问权 ...
- Excel数据导出功能
HTML代码: <a id="aExportData" hidden><span>Export</span></a> <div ...
- 在执行java代码时,设置了断点,然后莫名的没执行完方法内的代码就结束了,此刻一般在出错处代码用try,catch包括起来
在执行java代码时,设置了断点,然后莫名的没执行完方法内的代码就结束了,此刻一般在出错处代码用try,catch包括起来就能看到是什么异常了,记住try,catch语句的作用
- 【PS算法理论探讨二】 Photoshop中图层样式之 投影样式 算法原理初探讨。
接下来几篇文章我们将稍微简单的探索下PS中多种图层混合模式的算法内部原理,因为毕竟没有这方面的官方资料,所以很多方面也只是本人自己的探索和实践,有可能和实际的情况有着较大的差异. 在PS的实践中,图层 ...