【Spring Boot】 Actuator Endpoint
admin
2024-02-14 16:28:27
0次

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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BXuDDDOT-1669298081146)(https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/bbef3e5e46ee4159858c063c09fb6595~tplv-k3u1fbpfcp-zoom-1.image)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3Tvk1JLp-1669298081147)(https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/3e8f7b59d0824d9390791f80e95f1a37~tplv-k3u1fbpfcp-zoom-1.image)]

如何访问 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)。

IDDescription
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:

IDDescription
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..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的默认公开。

IDJMXWeb
auditeventsYesNo
beansYesNo
cachesYesNo
conditionsYesNo
configpropsYesNo
envYesNo
flywayYesNo
healthYesYes
heapdumpN/ANo
httptraceYesNo
infoYesNo
integrationgraphYesNo
jolokiaN/ANo
logfileN/ANo
loggersYesNo
liquibaseYesNo
metricsYesNo
mappingsYesNo
prometheusN/ANo
quartzYesNo
scheduledtasksYesNo
sessionsYesNo
shutdownYesNo
startupYesNo
threaddumpYesNo

要更改公开的endpoints,请使用以下特定于技术的include和exclude属性:

PropertyDefault
management.endpoints.jmx.exposure.exclude
management.endpoints.jmx.exposure.include*
management.endpoints.web.exposure.exclude
management.endpoints.web.exposure.includehealth

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

相关内容

热门资讯

蜻蜓订购APP贵金属订购非法期...   蜻蜓订购APP以"投资平台"名义对外宣传,主打贵金属期货(订购)交易。该平台一方面强调自身"正规...
悟空订购APP非法期货交易欺骗...   近期,有投资者反映,“悟空订购APP”等平台以白银、贵金属订购为名,宣传所谓“高收益”“低门槛”...
小赢淘金APP期货投资骗局,平...   “小赢淘金”之流,最擅长的就是用“注册送现金”、“充值返券”的糖衣炮弹来引流。别天真地以为那是福...
八方淘金APP非法期货交易欺骗...   警惕!八方生财、每日淘金、小赢淘金、悟空订购、蜻蜓订购、斗金订购等APP均涉嫌非法期货交易!  ...
智易购APP贵金属订购交易骗局...   很多人看到“3元起投”“充值送福利”“操作简单”“随时提现”这类宣传,很容易把智易购APP当成普...
喜玛银庄APP商品订购投资骗局...   喜玛银庄APP白银、铂金“现货订购”骗局警示:无资质平台涉嫌非法期货交易,投资者爆仓后如何维权?...
吉鑫乐享APP炒贵金属订购交易...   近期,多名投资者反映在“吉鑫乐享APP”进行贵金属投资时遭遇严重亏损,甚至血本无归。看似正规的“...
易掘金APP虚假期货投资骗局,...   “易掘金”的APP它打着“高收益、灵活投资”的旗号,宣称通过“商品订购”就能轻松赚钱,吸引了不少...
在大吉订购APP订购交易亏损被...   近期,不少投资者反映在“大吉订购App”上投资白银、铂金等商品遭遇严重亏损。该平台宣称提供现货订...
铂银壹号APP商品订购交易亏损...   许多中小投资者误以为网上的“商品现货订购”是合规合法的理财渠道,殊不知这背后隐藏着巨大的合规风险...
兴鑫淘金APP贵金属订购交易亏...   白银、贵金属或其他商品类投资,除国家批准的正规期货交易场所及持牌期货公司外,市面上大量第三方交易...
铂银掘金APP无资质的违规平台...   铂银掘金等平台的投资者,往往是被“注册送现金”“充值返现券”“首单免亏”等广告话术吸引,进而下载...
八方淘金APP订购交易不合规,...   “八方淘金APP”“铂银掘金APP”“铂银壹号APP”等软件被指以“现货订购”为名,实际采用高杠...
在指尖订购APP订购商品亏损被...   指尖订购APP这类平台,表面是“订购交易”,实则是披着电商外衣的非法期货陷阱。绝大多数投资者被蒙...
在犀贝易购APP做商品订购交易...   市面上打着“现货投资”“贵金属交易”旗号的APP并不少,但真正合规、受监管的平台并不多。犀贝易购...
易达淘金APP虚假商品订购交易...   易达淘金APP存在严重的虚假宣传与违规交易行为。该平台打着“商品订购”的旗号,实则通过不合规的交...
大浪淘金APP白银订购亏损被骗...   大浪淘金APP最隐蔽的套路,在于其完全封闭的内盘交易系统。表面上,它宣称与国际贵金属市场接轨;实...
一品好购APP上订购白银出现亏...   一品好购APP原名“一品订购”,运营方为上海宝智未来信息技术有限公司。近期不少投资者反映在该平台...
九州订购APP贵金属订购投资骗...   九州订购APP正通过抖.音、快手、今日头条等平台大量投放投资广告,用“5元起投”“充值返现”“0...
坚锅淘金APP交易软件并不正规...   当前,市面上大量所谓的“现货商城订购”交易软件,早已偏离了正常的实物商品买卖,演变为高杠杆、高手...