Spring Cloud Gateway 监控器API

/ gateway执行器端点允许监视Spring Cloud Gateway应用程序并与之交互。要进行远程访问,必须在应用程序属性中通过HTTP或JMX启用和公开端点。

application.properties

management.endpoint.gateway.enabled=true # default value
management.endpoints.web.exposure.include=gateway

检索路由过滤器 

一、全局过滤器

要检索应用于所有路由的全局过滤器,请向/ actuator / gateway / globalfilters发出GET请求。结果响应类似于以下内容:

{
  "org.springframework.cloud.gateway.filter.LoadBalancerClientFilter@77856cc5": 10100,
  "org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@4f6fd101": 10000,
  "org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@32d22650": -1,
  "org.springframework.cloud.gateway.filter.ForwardRoutingFilter@106459d9": 2147483647,
  "org.springframework.cloud.gateway.filter.NettyRoutingFilter@1fbd5e0": 2147483647,
  "org.springframework.cloud.gateway.filter.ForwardPathFilter@33a71d23": 0,
  "org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@135064ea": 2147483637,
  "org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@23c05889": 2147483646
}

响应包含有关全局过滤器的详细信息。对于每个全局过滤器,提供过滤器对象的字符串表示(例如,org.springframework.cloud.gateway.filter.LoadBalancerClientFilter@77856cc5)以及过滤器链中的相应顺序。

二、路由过滤器

要检索应用于路由的GatewayFilter工厂,请向/ actuator / gateway / routefilters发出GET请求。结果响应类似于以下内容:

{
  "[AddRequestHeaderGatewayFilterFactory@570ed9c configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null,
  "[SecureHeadersGatewayFilterFactory@fceab5d configClass = Object]": null,
  "[SaveSessionGatewayFilterFactory@4449b273 configClass = Object]": null
}

响应包含应用于任何特定路由的GatewayFilter工厂的详细信息。为每个工厂提供相应对象的字符串表示(例如,[SecureHeadersGatewayFilterFactory @ fceab5d configClass = Object])。请注意,null值是由于端点控制器的实现不完整,因为它尝试设置过滤器链中对象的顺序,这不适用于GatewayFilter工厂对象。

三、刷新路由缓存

要清除路由缓存,请对/ actuator / gateway / refresh发出POST请求。

请求返回200没有响应正文。检索网关中定义的路由要检索网关中定义的路由,请对/ actuator / gateway / routes发出GET请求。

结果响应类似于以下内容:

[{
  "route_id": "first_route",
  "route_object": {
    "predicate": "org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateFactory$$Lambda$432/1736826640@1e9d7e7d",
    "filters": [
      "OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.PreserveHostHeaderGatewayFilterFactory$$Lambda$436/674480275@6631ef72, order=0}"
    ]
  },
  "order": 0
},
{
  "route_id": "second_route",
  "route_object": {
    "predicate": "org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateFactory$$Lambda$432/1736826640@cd8d298",
    "filters": []
  },
  "order": 0
}]

响应包含网关中定义的所有路由的详细信息。下表描述了响应的每个元素(即路由)的结构。

Path Type Description

route_id

String

The route id.

route_object.predicate

Object

The route predicate.

route_object.filters

Array

The GatewayFilter factories applied to the route.

order

Number

The route order.

 四、检索有关特定路线的信息

要检索有关单个路由的信息,请向/ actuator / gateway / routes / {id}发出GET请求(例如,/ actuator / gateway / routes / first_route)。结果响应类似于以下内容:

{
  "id": "first_route",
  "predicates": [{
    "name": "Path",
    "args": {"_genkey_0":"/first"}
  }],
  "filters": [],
  "uri": "http://www.uri-destination.org",
  "order": 0
}]

下表描述了响应的结构。

Path Type Description

id

String

The route id.

predicates

Array

The collection of route predicates. Each item defines the name and the arguments of a given predicate.

filters

Array

The collection of filters applied to the route.

uri

String

The destination URI of the route.

order

Number

The route order.

 五、创建和删除特定路由

要创建路由请使用指定路由字段的JSON主体向/ gateway / routes / {id_route_to_create}发出POST请求(请参阅上一小节)。要删除路由,请对/ gateway / routes / {id_route_to_delete}发出DELETE请求。

六、所有端点的列表

下表总结了Spring Cloud Gateway执行器端点。请注意,每个端点都有/ actuator / gateway作为基本路径。

ID HTTP Method Description

globalfilters

GET

Displays the list of global filters applied to the routes.

routefilters

GET

Displays the list of GatewayFilter factories applied to a particular route.

refresh

POST

Clears the routes cache.

routes

GET

Displays the list of routes defined in the gateway.

routes/{id}

GET

Displays information about a particular route.

routes/{id}

POST

Add a new route to the gateway.

routes/{id}

DELETE

Remove an existing route from the gateway.

猜你喜欢

转载自blog.csdn.net/u013702678/article/details/88760892