本文目标
预计介绍如下内容:
- 在SCG中如何使用actuator?
- SCG中的actuator能做什么?
- 在代码层面上,SCG如何实现actuator?
- 如何基于SCG的actuator进行监控?
1、在SCG中如何使用actuator?
参见 https://docs.spring.io/spring-cloud-gateway/docs/2.2.5.RELEASE/reference/html/#actuator-api
只需要在配置中开启如下配置(以properties配置方式为例,YAML方式属性一样、写法不同而已):
management.endpoint.gateway.enabled=true # default value
management.endpoints.web.exposure.include=gateway
即可打开SCG中的/gateway
这个endpoint,利用该接口我们可以监控SCG、与SCG交互。
使用actuator的准备工作
事前准备参考源码分析之spring_cloud_gateway_3_请求被路由的过程解析 准备工作
小节,然后参照上面修改management.endpoint.gateway.enabled
和management.endpoints.web.exposure.include
配置,然后启动SCG项目,访问http://localhost:8080/actuator/gateway/routes
,可以看到如下内容:
[{
"predicate": "(Hosts: [kotlin.abc.org] && Paths: [/image/png], match trailing slash: true)",
"route_id": "test-kotlin",
"filters": ["[[PrefixPath prefix = '/httpbin'], order = 0]", "[[AddResponseHeader