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端点配置的更多相关文章

  1. springboot集成Actuator

    Actuator监控端点,主要用来监控与管理. 原生端点主要分为三大类:应用配置类.度量指标类.操作控制类. 应用配置类:获取应用程序中加载的配置.环境变量.自动化配置报告等与SpringBoot应用 ...

  2. SpringBoot集成actuator模块的基本使用

    © 版权声明:本文为博主原创文章,转载请注明出处 1. 版本 SpringBoot:2.0.0.RELEASE 2. 集成 SpringBoot集成actuator模块非常简单,只需要引入actuat ...

  3. SpringBoot集成Swagger2并配置多个包路径扫描

    1. 简介   随着现在主流的前后端分离模式开发越来越成熟,接口文档的编写和规范是一件非常重要的事.简单的项目来说,对应的controller在一个包路径下,因此在Swagger配置参数时只需要配置一 ...

  4. SpringBoot集成Actuator监控管理

    1.说明 本文详细介绍Spring Boot集成Actuator监控管理的方法, 基于已经创建好的Spring Boot工程, 然后引入Actuator依赖, 介绍监控管理相关功能的使用. Sprin ...

  5. springboot集成Apollo分布式配置

    安装Apollo服务 1.安装mysql 地址:https://www.cnblogs.com/xuaa/p/10782352.html 2.下载Apollo源码到本地 地址:https://gith ...

  6. SpringBoot集成Actuator健康指示器health

    1.说明 本文详细介绍Actuator提供的HealthIndicators, 即健康指示器的配置使用, 利用自动配置的健康指标, 检查正在运行的应用程序的状态, 以及自定义健康指标的方法. 监控软件 ...

  7. SpringBoot集成Mybatis(0配置注解版)

    Mybatis初期使用比较麻烦,需要各种配置文件.实体类.dao层映射关联.还有一大推其它配置.当然Mybatis也发现了这种弊端,初期开发了generator可以根据表结构自动生成实体类.配置文件和 ...

  8. apollo与springboot集成实现动态刷新配置

    分布式apollo简介 Apollo(阿波罗)是携程框架部门研发的开源配置管理中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性. 本 ...

  9. 分享知识-快乐自己:SpringBoot集成热部署配置(一)

    摘要: 热部署与热加载: ava热部署与Java热加载的联系和区别: 1):Java热部署与热加载的联系: 1.不重启服务器编译/部署项目 2.基于Java的类加载器实现 2):Java热部署与热加载 ...

随机推荐

  1. iOS11&IPhoneX适配

    1.在iOS 11中,会默认开启获取的一个估算值来获取一个大体的空间大小,导致不能正常显示,可以选择关闭.目前尝试在delegate中处理不能很好的解决,不过可以直接设置: Swift if #ava ...

  2. 转 Android 多线程:手把手教你使用AsyncTask

    转自:https://www.jianshu.com/p/ee1342fcf5e7 前言 多线程的应用在Android开发中是非常常见的,常用方法主要有: 继承Thread类 实现Runnable接口 ...

  3. synchronized底层浅析(一)

    之前说过hashMap,我们知道hashMap是一种非线程安全的集合,主要原因是它在多线程的情况下,插入.删除.扩容的时候容易导致数据丢失或者链表环 那我们也知道ConcurrentHashMap.h ...

  4. Python multiprocessing 基础使用和小trick

    最近进行数据预处理时(噪声插入),单进程严重影响实验周期,故学习了multiprocessing并发执行不同数据集的处理,加快执行效率.现于此进行一些简单记录以供日后参考. 1. 基础: From m ...

  5. antd动态的表格合并(包含排序功能)

    主要是两个步骤, 1.处理接口返回数据,给其添加两个属性,一个是合并行数(列数),一个是当前数据的序号 2.在columns结合antd官网的处理方法合并表格 3.尽可能得减少计算量 数据处理函数 / ...

  6. 腾讯新闻基于 Flink PipeLine 模式的实践

    摘要  :随着社会消费模式以及经济形态的发展变化,将催生新的商业模式.腾讯新闻作为一款集游戏.教育.电商等一体的新闻资讯平台.服务亿万用户,业务应用多.数据量大.加之业务增长.场景更加复杂,业务对实时 ...

  7. 搭建直接通过CPU执行汇编语言的环境

    搭建直接通过CPU执行汇编语言环境 我们通过编译写好的汇编语言代码可以生成.bin的机器语言二进制代码.但是这个.bin程序我们该如何运行呢? 这里其实有两个办法: 1: 将其作为一个Windows/ ...

  8. presto官网阅读记录: Functions and Operators 部分

    官网Functions and Operators部分 版本:0.266 目录 官网Functions and Operators部分 1 Comparison Functions and Opera ...

  9. CF83A Magical Array 题解

    Content 有一个长度为 \(n\) 的序列 \(a_1,a_2,a_3,...,a_n\).定义一个"神奇数组"为在上面的序列中最大值和最小值相等的子序列.求出这个序列中&q ...

  10. CF934A A Compatible Pair 题解

    Content 有两个数列 \(A\) 和 \(B\),\(A\) 数列里面有 \(n\) 个元素,\(B\) 数列里面有 \(m\) 个元素,现在请从 \(A\) 数列中删除一个数,使得 \(A\) ...