spring-boot-starter-actuator监控接口

1、介绍:actuator是监控系统健康情况的工具。


2、如何引入:

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

3、actuator 的端点分为3类

(1)应用配置类:获取应用程序中加载的应用配置、环境变量、自动化配置报告等与Spring Boot应用密切相关的配置类信息。

/configprops /autoconfig /beans /env /info /mappings

(2)度量指标类:获取应用程序运行过程中用于监控的度量指标,比如内存信息、线程池信息、HTTP请求统计等;

/dump /health

(3)操作控制类:提供了对应用的关闭等操作类功能,/shutdown
### 集成 `spring-boot-starter-actuator` 和 Gateway 为了在 Spring Boot 项目中成功集成 `spring-boot-starter-actuator` 和 Gateway,需遵循特定配置方法。 #### 添加依赖项 首先,在项目的 `pom.xml` 文件中添加必要的 Maven 依赖项: ```xml <dependencies> <!-- Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- WebFlux for Gateway --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency> <!-- 移除 spring-boot-starter-web 并确保不会引入冲突的Web组件 [^2]--> </dependencies> ``` 注意移除了 `spring-boot-starter-web` 以防止与网关模块发生冲突。这一步骤对于避免潜在启动失败至关重要。 #### 启用端点暴露 接着修改 `application.yml` 或者 `application.properties` 来启用并自定义 actuator 的行为: ```yaml management: endpoints: web: exposure: include: "*" # 暴露所有默认端点 endpoint: health: show-details: always # 始终显示健康详情 ``` 此设置允许通过 HTTP 访问所有的管理端点,并且当查询 `/actuator/health` 路径时总是返回详细的健康状态信息。 #### 自定义路由规则 (可选) 如果希望进一步定制化 API 网关的行为,则可以在应用程序属性文件里指定额外的路由规则或其他配置选项。例如: ```yaml spring: cloud: gateway: routes: - id: example_route uri: http://example.org/ predicates: - Path=/api/** ``` 上述 YAML 片段创建了一个名为 "example_route" 的新路由,它会匹配任何以 "/api/" 开头的请求并将它们转发给目标 URI。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值