「Spring Boot」 Actuator Endpoint
wptr33 2025-06-30 20:45 6 浏览
Actuator
官网地址:
https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/actuator.html
目的
- 监控并管理应用程序
访问方式
- HTTP
- JMX Java Management Extensions(Java管理扩展)的缩写
依赖
- spring-boot-starter-actuator
一些常用 Endpoint
如何访问 Actuator Endpoint
HTTP 访问
- /actuator/
端口与路径
- management.server.address=
- management.server.port=
- management.endpoints.web.base-path=/actuator
- management.endpoints.web.path-mapping.=路径
开启 Endpoint
- management.endpoint..enabled=true
- management.endpoints.enabled-by-default=false
暴露 Endpoint
- management.endpoints.jmx.exposure.exclude=
- management.endpoints.jmx.exposure.include=*
- management.endpoints.web.exposure.exclude=
- management.endpoints.web.exposure.include=info, health
完整版Endpoint
官网地址:
https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/actuator.html#actuator.endpoints
Actuator endpoints允许您监视应用程序并与之交互。Spring Boot包括许多内置endpoints,并允许您添加自己的endpoints。例如,health endpoint提供基本应用程序health信息。
可以通过HTTP或JMX启用或禁用每个endpoint并公开(使其远程访问)。当一个endpoint同时启用和公开时,它就被认为是可用的。内置endpoint只有在可用时才会自动配置。大多数应用程序选择通过HTTP进行公开,其中endpoint的ID加上/actuator前缀被映射到一个URL。例如,默认情况下,health endpoint映射到/actuator/health。
要了解更多关于Actuator’s endpoints及其请求和响应格式的信息,可参考单独的API文档(HTML or PDF)。
ID | Description |
auditevents | 为当前应用程序公开审计事件信息。需要一个AuditEventRepository bean。 |
beans | 显示应用程序中所有Spring bean的完整列表。 |
caches | 公开可用的缓存。 |
conditions | 显示在配置和自动配置类上评估的条件,以及它们匹配或不匹配的原因。 |
configprops | 显示所有@ConfigurationProperties的排序列表。 |
env | 暴露Spring中ConfigurableEnvironment的属性。 |
flyway | 显示已应用的任何Flyway数据库迁移。需要一个或多个Flyway bean。 |
health | 显示应用程序health信息。 |
httptrace | 显示HTTP跟踪信息(默认情况下,最近100次HTTP请求-响应交换)。需要一个HttpTraceRepository bean。 |
info | 显示任意的应用程序信息。 |
integrationgraph | 显示Spring Integration graph。需要依赖了spring-integration-core。 |
loggers | 显示和修改应用程序中loggers的配置。 |
liquibase | 显示已应用的任何Liquibase数据库迁移。需要一个或多个Liquibase bean。 |
metrics | 显示当前应用程序的“metrics”信息。 |
mappings | 显示所有@RequestMapping路径的排序列表。 |
quartz | 显示有关Quartz Scheduler jobs的信息。 |
scheduledtasks | 显示应用程序中的scheduled任务。 |
sessions | 允许从Spring session支持的会话存储中检索和删除用户会话。需要使用Spring Session的基于servlet的web应用程序。 |
shutdown | 让应用程序优雅地关闭。默认禁用。 |
startup | 显示由ApplicationStartup收集的启动步骤数据。要求SpringApplication配置一个BufferingApplicationStartup。 |
threaddump | 执行线程转储。 |
如果你的应用程序是一个web应用程序(Spring MVC, Spring WebFlux,或Jersey),你可以使用以下附加endPoints:
ID | Description |
heapdump | 返回一个hprof堆转储文件。需要一个HotSpot JVM。 |
jolokia | 通过HTTP公开JMX bean(当Jolokia位于类路径上,对WebFlux不可用时)。需要存在依赖jolokia-core。 |
logfile | 返回日志文件的内容(如果已经设置了logging.file.name或logging.file.path属性)。支持使用HTTP Range头来检索部分日志文件的内容。 |
prometheus | 以Prometheus服务器可以抓取的格式公开指标。需要依赖于micrometer-registry-prometheus。 |
启用 EndPoints
缺省情况下,除shutdown外的所有endpoints都是启用的。通过配置可启用endpoint,使用它的management.endpoint.<id>.enabled属性。下面的例子启用了shutdown endpoint:
management.endpoint.shutdown.enabled=true
如果您更喜欢选择加入endpoint而不是选择退出endpoint,可将
management.endpoints.enabled-by-default属性设置为false,再将单个endpoint启用的属性设置为true。下面的示例启用info endpoint并禁用所有其他endpoints:
management.endpoints.enabled-by-default=false
management.endpoint.info.enabled=true
这会从应用程序上下文中完全删除禁用的endpoint。如果您只想更改暴露endpoint的技术,请使用include和exclude属性。
暴露 EndPoints
由于endpoints可能包含敏感信息,应仔细考虑何时公开它们。下表显示了内置endpoints的默认公开。
ID | JMX | Web |
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 | No |
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 |
quartz | Yes | No |
scheduledtasks | Yes | No |
sessions | Yes | No |
shutdown | Yes | No |
startup | Yes | No |
threaddump | Yes | No |
要更改公开的endpoints,请使用以下特定于技术的include和exclude属性:
Property | Default |
management.endpoints.jmx.exposure.exclude | |
management.endpoints.jmx.exposure.include | * |
management.endpoints.web.exposure.exclude | |
management.endpoints.web.exposure.include | health |
include属性列出了公开的endpoints的id。exclude属性列出不应公开的endpoints的id。exclude属性优先于include属性。包含和排除属性都可以使用endpoint id列表进行配置。
例如,要停止通过JMX公开所有endpoints,而只公开health and info endpoints,可使用以下属性:
management.endpoints.jmx.exposure.include=health,info
*可以用来选择所有endpoints。例如,要通过HTTP公开除env和beans endpoints外的所有内容,请使用以下属性:
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans
*在YAML中有特殊含义,所以如果您想包含(或排除)所有endpoints,请务必添加引号。
如果您的应用程序是公开的,我们强烈建议您也保护您的endpoints。
如果您想在endpoints暴露时实现自己的策略,可以注册一个EndpointFilter bean
相关推荐
- SpringBoot 3 + Flutter3 实战低代码运营管理-10章
-
获课》aixuetang.xyz/5075/三天构建运营管理系统:SpringBoot3+Flutter3高效开发方法论...
- SpringBoot探针实现:从零构建应用健康监控利器
-
SpringBoot探针实现:从零构建应用健康监控利器声明本文中的所有案例代码、配置仅供参考,如需使用请严格做好相关测试及评估,对于因参照本文内容进行操作而导致的任何直接或间接损失,作者概不负责。本文...
- Spring Batch中的JobRepository:批处理的“记忆大师”是如何工作
-
一、JobRepository是谁?——批处理的“档案馆”JobRepository是SpringBatch的“记忆中枢”,负责记录所有Job和Step的执行状态。它像一位严谨的档案管理员,把任务执...
- 还在为 Spring Boot3 技术整合发愁?一文解锁大厂都在用的实用方案
-
你在使用SpringBoot3开发后端项目时,是不是常常陷入这样的困境?想提升项目性能和功能,却不知道该整合哪些技术;好不容易选定技术,又在配置和使用上频频踩坑。其实,这是很多互联网大厂后端开发...
- 一文吃透!Spring Boot 项目请求日志记录,这几招你绝对不能错过!
-
在互联网应用开发的高速赛道上,系统的稳定性、可维护性以及安全性是每一位开发者都必须关注的核心要素。而请求日志记录,就如同系统的“黑匣子”,能够为我们提供排查故障、分析用户行为、优化系统性能等关键信息...
- spring-boot-starter-actuator简单介绍
-
SpringBootActuator是SpringBoot的一个功能强大的子项目,它提供了一些有用的监控和管理SpringBoot应用程序的端点。SpringBootActuat...
- 使用SpringBoot钩子或Actuator实现优雅停机
-
服务如何响应停机信号在java中我们可以直接利用通过Runtime...
- 28-自定义Spring Boot Actuator指标
-
上篇我们学习了《27-自定义SpringBootActuator健康指示器》,本篇我们学习自定义SpringBootActuator指标(Metric)。...
- 如何在Spring Boot中整合Spring Boot Actuator进行服务应用监控?
-
监控是确保系统稳定性和性能的关键组成部分,而在SpringBoot中就提供了默认的应用监控方案SpringBootActuator,通过SpringBootActuator提供了开箱即用的应...
- 「Spring Boot」 Actuator Endpoint
-
Actuator官网地址:https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/actuator.html目的监控并管理应用程序...
- Spring Boot Actuator监控功能全面剖析
-
SpringBootActuator监控功能全面剖析在现代企业级Java开发中,SpringBoot以其轻量化、高效率的特性深受开发者青睐。而作为SpringBoot生态系统的重要组成部分,S...
- 1000字彻底搞懂SpringBootActuator组件!
-
SpringBootActuator组件SpringBootActuator通过HTTPendpoints或者JMX来管理和监控SpringBoot应用,如服务的审计、健康检查、指标统计和...
- JavaScript数据类型(javascript数据类型介绍)
-
基本数据类型BooleanNullNumberStringSymbolUndefined对象数据类型ObjectArray定义:JavaScript数组是内置的对象之一,它可以用一个变量来存储多个同种...
- 能运行,不代表它是对的:5 个潜伏在正常功能下的 JavaScript 错误
-
JavaScript的动态性和复杂性意味着,代码虽然表面上正常运行,但一些深层次、隐蔽的陷阱往往让人意想不到,梳理了几个JavaScript开发中难以发现的隐蔽错误,旨在帮助我们写出更健壮、更可...
- 一周热门
-
-
C# 13 和 .NET 9 全知道 :13 使用 ASP.NET Core 构建网站 (1)
-
因果推断Matching方式实现代码 因果推断模型
-
git pull命令使用实例 git pull--rebase
-
面试官:git pull是哪两个指令的组合?
-
git 执行pull错误如何撤销 git pull fail
-
git fetch 和git pull 的异同 git中fetch和pull的区别
-
git pull 和git fetch 命令分别有什么作用?二者有什么区别?
-
git pull 之后本地代码被覆盖 解决方案
-
还可以这样玩?Git基本原理及各种骚操作,涨知识了
-
git命令之pull git.pull
-
- 最近发表
-
- SpringBoot 3 + Flutter3 实战低代码运营管理-10章
- SpringBoot探针实现:从零构建应用健康监控利器
- Spring Batch中的JobRepository:批处理的“记忆大师”是如何工作
- Github霸榜的SpringBoot全套学习教程,从入门到实战,内容超详细
- 还在为 Spring Boot3 技术整合发愁?一文解锁大厂都在用的实用方案
- 一文吃透!Spring Boot 项目请求日志记录,这几招你绝对不能错过!
- spring-boot-starter-actuator简单介绍
- 使用SpringBoot钩子或Actuator实现优雅停机
- 28-自定义Spring Boot Actuator指标
- 如何在Spring Boot中整合Spring Boot Actuator进行服务应用监控?
- 标签列表
-
- git pull (33)
- git fetch (35)
- mysql insert (35)
- mysql distinct (37)
- concat_ws (36)
- java continue (36)
- jenkins官网 (37)
- mysql 子查询 (37)
- python元组 (33)
- mybatis 分页 (35)
- vba split (37)
- redis watch (34)
- python list sort (37)
- nvarchar2 (34)
- mysql not null (36)
- hmset (35)
- python telnet (35)
- python readlines() 方法 (36)
- munmap (35)
- docker network create (35)
- redis 集合 (37)
- python sftp (37)
- setpriority (34)
- c语言 switch (34)
- git commit (34)