Spring Cloud Gateway监控

Spring Cloud Gateway提供了若干多的监控端点,这些端点都非常的实用

Spring Cloud Gateway监控

TIPS

本文基于Spring Cloud Hoxton M2编写,理论支持Spring Cloud Finchley及更高版本。

欢迎加入Spring Cloud Gateway监控豪华套餐——

只要为Spring Cloud Gateway添加Spring Boot Actuator( spring-boot-starter-actuator )的依赖,并将 gateway 端点暴露,即可获得若干监控端点,监控 & 操作Spring Cloud Gateway的方方面面。

management:
  endpoints:
    web:
      exposure:
        include: gateway

监控端点一览表:

TIPS
以下所有端点都挂在/actuator/gateway/ 下面。
例如:routes 的全路径是 /actuator/gateway/routes ,以此类推。

IDHTTP MethodDescription
globalfiltersGET展示所有的全局过滤器
routefiltersGET展示所有的过滤器工厂(GatewayFilter factories)
refreshPOST【无消息体】清空路由缓存
routesGET展示路由列表,默认会展示详情,如果希望展示概要信息,添加 spring.cloud.gateway.actuator.verbose.enabled=false
routes/{id}GET展示指定id的路由的信息
routes/{id}POST【消息体如下】新增一个路由
routes/{id}DELETE【无消息体】删除一个路由

其中,要想动态添加路由配置,只需发送POST请求,消息体如下:

{
  "predicates": [
    {
      "name": "Path",
      "args": {
        "_genkey_0": "/test"
      }
    }
  ],
  "filters": [
    {
      "name": "AddRequestHeader",
      "args": {
        "_genkey_0": "X-Request-Foo",
        "_genkey_1": "Bar"
      }
    },
    {
      "name": "MyLog",
      "args": {
        "_genkey_0": "a",
        "_genkey_1": "b"
      }
    }
  ],
  "uri": "https://www.itmuch.com",
  "order": 0
}

TIPS

技巧:消息体其实是有规律的,你可以先在配置文件中配置一个路由规则,然后访问 ${GATEWAY_URL}/actuator/gateway/routes 端点,找到每个路由id的对应段落,就可以作为这边的消息体啦。

如使用 POSTMAN 测试,可配置如下:

image-20210712221438049

操作完成后,可再次访问 ${GATEWAY_URL}/actuator/gateway/routes 端点,可以看到,新的路由已被动态添加了。

TIPS

如果没有实时生效,使用refresh端点刷新一下路由信息即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

铁根

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值