Spring Cloud Gateway監控

 

歡迎加入Spring Cloud Gateway監控豪華套餐——web

只要爲Spring Cloud Gateway添加Spring Boot Actuator( spring-boot-starter-actuator )的依賴,並將 gateway 端點暴露,便可得到若干監控端點,監控 & 操做Spring Cloud Gateway的方方面面。spring

  •  
management:  endpoints:    web:      exposure:        include: gateway

監控端點一覽表:緩存

TIPS 如下全部端點都掛在/actuator/gateway/ 下面。例如:routes 的全路徑是 /actuator/gateway/routes ,以此類推。ide

ID HTTP Method Description
globalfilters GET 展現全部的全局過濾器
routefilters GET 展現全部的過濾器工廠(GatewayFilter factories)
refresh POST【無消息體】 清空路由緩存
routes GET 展現路由列表
routes/{id} GET 展現指定id的路由的信息
routes/{id} POST【消息體以下】 新增一個路由
routes/{id} DELETE【無消息體】 刪除一個路由

其中,要想動態添加路由配置,只需發送POST請求,消息體以下:spring-boot

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

TIPS測試

技巧:消息體實際上是有規律的,你能夠先在配置文件中配置一個路由規則,而後訪問${GATEWAY_URL}/actuator/gateway/routes 端點,每一個路由id的對應段落,就是你的消息體啦。3d

如使用 POSTMAN 測試,可配置以下:blog

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

操做完成後,可再次訪問 ${GATEWAY_URL}/actuator/gateway/routes 端點,能夠看到,新的路由已被動態添加了。ip

TIPS路由

若是沒有實時生效,使用refresh端點刷新一下路由信息便可。

 


想知道更多?長按/掃碼關注我吧↓↓↓watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

相關文章
相關標籤/搜索