springboot的actuator配置

本文介绍了如何配置Springboot的Actuator模块,包括引入2.0.0版本依赖,yaml文件设置,如management.endpoint、management.endpoints.web.cors、management.endpoints.jmx等关键配置项,以及management.server的相关属性,如地址、端口和上下文路径。默认暴露的端点为/health和/info。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、引入依赖包(2.0.0版本)

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2、yaml文件配置

#暴露端口
management:
  endpoints:
    web:
      exposure:
        include: "*"   # * 在yaml 文件属于关键字

3、keys的配置
management.endpoint..*
management.endpoints.web.cors.*
management.endpoints.jmx.*
management.server.address
management.server.servlet.context-path
management.server.ssl.*
management.server.port

4、端口详细
只有端点/health和/info端点是默认暴露的

HTTP方法路径描述
GET/actuator/conditions提供了一份自动配置报告,记录哪些自动配置条件通过了,哪些没通过
GET/actuator/configprops描述配置属性(包含默认值)如何注入Bean
GET/actuator/beans描述应用程序上下文里全部的Bean,以及它们的关系
GET/actuator/dump获取线程活动的快照
GET/actuator/env获取全部环境属性
GET/actuator/env/{name}根据名称获取特定的环境属性值
GET/actuator/health报告应用程序的健康指标,这些值由HealthIndicator的实现类提供
GET/actuator/info获取应用程序的定制信息,这些信息由info打头的属性提供
GET/actuator/mappings描述全部的URI路径,以及它们和控制器(包含Actuator端点)的映射关系
GET/actuator/metrics报告各种应用程序度量信息,比如内存用量和HTTP请求计数
GET/actuator/metrics/{name}报告指定名称的应用程序度量值
POST/actuator/shutdown关闭应用程序,要求endpoints.shutdown.enabled设置为true
GET/actuator/httptrace提供基本的HTTP请求跟踪信息(时间戳、HTTP头等)
POST/actuator/bus-refresh配置更新
Spring Boot Actuator 提供了一些端点,可以让你监控和管理 Spring Boot 应用程序。其中包括一些敏感信息,例如应用程序的健康状况、配置信息、日志等等。为了保护这些敏感信息,你可以配置 Actuator 端点的访问密码。 以下是配置 Actuator 端点访问密码的步骤: 1. 在 application.properties 或 application.yml 文件中添加以下配置: ``` management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always management.endpoint.info.enabled=true management.endpoint.logfile.enabled=true spring.security.user.name=admin spring.security.user.password=your_password ``` 上述配置中,`management.endpoints.web.exposure.include=*` 表示暴露所有 Actuator 端点,`management.endpoint.health.show-details=always` 表示展示详细的健康状况信息,`management.endpoint.info.enabled=true` 表示开启 info 端点,`management.endpoint.logfile.enabled=true` 表示开启 logfile 端点。 2. 在需要保护的端点上添加 `@Secured` 注解,如: ```java @RestController public class MyController { @GetMapping("/my-endpoint") @Secured("ROLE_ACTUATOR") public String myEndpoint() { // ... } } ``` 这里的 `@Secured("ROLE_ACTUATOR")` 表示只有具有 `ROLE_ACTUATOR` 权限的用户才能访问该端点。 3. 启动应用程序,并使用 `http://username:password@localhost:port/actuator/` 访问 Actuator 端点。其中,`username` 和 `password` 分别是你在第一步中配置的用户名和密码,`port` 是应用程序的端口号。 这样,你就可以保护 Actuator 端点的访问了。注意,在生产环境中,应该使用更加安全的身份验证方式,例如 OAuth2 或 JWT。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值