spring-boot-starter-actuator访问/actuator/info报404错误
需要加上如下配置management : endpoints : web : exposure : include : health , info # 可以用【*】来表示开放所有的监控 info : defaults : enabled : true # info信息补充 info : app : name : test description : this is a demo。
背景
使用了spring-boot-dependencies是2.7.7版本的springboot项目,用actuator做健康状态监控时,发现/actuator/info访问一直报错。
分析
以前用过2.3.3版本的,依赖一导入,就能访问/actuator/info了,现在是怎么一回事呢?
我很快就锁定了WebEndpointProperties.java这个类中的include属性
当我什么都没设置的时候,他默认值是否不包含了info?找到additional-spring-configuration-metadata.json这个配置文件
不知道从什么时候开始,已经默认值不包括了info,那很简单只要加上这么一个配置即可
management:
endpoints:
web:
exposure:
include: health,info
加上去再访问的时候,不报404错误了,但是返回了一个空的json集合
那么我们直接配置上info的信息行不行呢
info:
app:
name: test
description: this is a demo
加上配置之后,还是返回的空的json集合,查看源码后发现需要激活env的配置才能读取到info的配置
那再补上这部分的配置即可
management:
endpoints:
web:
exposure:
include: health,info
info:
defaults:
enabled: true
总结
需要加上如下配置
management:
endpoints:
web:
exposure:
include: health,info # 可以用【*】来表示开放所有的监控
info:
defaults:
enabled: true
# info信息补充
info:
app:
name: test
description: this is a demo
扩展
Spring Boot Actuator模块中常用的接口及其作用:
-
/actuator/health:获取应用程序的健康状态信息。应用程序可以通过实现HealthIndicator接口来自定义健康检查逻辑。
-
/actuator/info:获取应用程序的自定义信息。应用程序可以通过实现InfoContributor接口来向/info端点添加额外的信息。
-
/actuator/metrics:获取应用程序的度量指标信息。应用程序可以通过实现MeterBinder接口来向/metrics端点添加自定义度量指标。
-
/actuator/trace:获取应用程序的HTTP请求跟踪信息。
-
/actuator/beans:获取应用程序中所有的Spring Bean信息。
-
/actuator/mappings:获取应用程序中所有的请求映射信息。
-
/actuator/env:获取应用程序的环境变量和配置属性信息。
-
/actuator/loggers:获取应用程序的日志配置信息。
-
/actuator/threaddump:获取应用程序的线程信息。
-
/actuator/scheduledtasks:获取应用程序中所有的定时任务信息。
-
/actuator/httptrace:获取应用程序的HTTP请求跟踪信息(包括请求和响应的详细信息)。
-
/actuator/sessions:获取应用程序的会话信息(仅适用于基于Spring Session的应用程序)。
以上接口中,/actuator/health、/actuator/info和/actuator/metrics是最常用的。它们可以为应用程序提供健康状态、自定义信息和度量指标等重要信息,对于应用程序的运维和监控非常有帮助。其他接口则可以提供更详细的信息,用于排查问题和调试应用程序。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)