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. list通过比较器进行排序

    Collections.sort(dataList,new Comparator<BaseTransitData>(){            public int compare(Bas ...

  2. 【Java 8】Predicate详解

    一.java.util.function.Predicate 这里类是java自带主要广泛用在支持lambda表达式的API中. 1.接口源码 @FunctionalInterface public ...

  3. 『与善仁』Appium基础 — 24、等待activity出现

    目录 1.什么是等待activity出现 2.wait_activity()方法 3.获取当前页面的activity方法 4.综合练习 1.什么是等待activity出现 在启动APP的时候,要配置包 ...

  4. drone 使用git tag触发构建

    配置ref为tag .drone.yml中配置trigger为ref trigger: ref: - refs/tags/FileService 或者配置when为ref when: ref: - r ...

  5. 1、Spring简介及IOC入门案例

    一.Spring框架介绍 1.介绍 Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spring的用途不仅仅限于服务 ...

  6. RDS备份到OSS增量+全量

    一.前言 阿里云的RDS备份是占用使用量的,你购买200G那备份使用量是100G左右,导致备份一般也就存半个月,2个全备份. 那半个月后之前的也就删除了,如果要持续保留更久将花费不少的金钱.所以这里用 ...

  7. Jenkins环境变量

    目录 一.环境变量 二.自定义环境变量 三.自定义全局变量 四.常用变量定义 五.常用环境变量 一.环境变量 环境变量可以被看作是pipeline与Jenkins交互的媒介.比如,可以在pipelin ...

  8. ssm项目中常用的上传文件

    在项目中,上传文件一般是必不可少的,所以今天学到新的上传方式,就干脆将学习过的上传方式记录一下 一.表单直接上传图片 表单头要设置 <form action="" metho ...

  9. PowerDotNet平台化软件架构设计与实现系列(08):缓存平台

    几乎所有后端应用都会或多或少用到缓存,尤其是分布式缓存服务,以及和本地缓存构造的二级缓存.根据我们一贯的节约代码的风格,为了复用的目标,抽象出缓存平台,进行缓存管理. 考虑到很多公司都会自己造或者直接 ...

  10. re模块计算器作业

    1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )