Metrics插件
说明
Metrics插件插件是网关用来监控自身运行状态(JVM相关),请求的响应迟延,QPS、TPS等相关metrics。
技术方案
-
流程图

-
异步或者同步的方式,在
Apache ShenYu网关里面进行metrics埋点。 -
prometheus服务端通过http请求来拉取metrics,再使用Grafana展示。
插件使用
- 在网关的
pom.xml文件中添加metrics的依赖。
<!-- apache shenyu metrics plugin starter-->
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-metrics</artifactId>
<version>${project.version}</version>
</dependency>
<!-- apache shenyu metrics plugin end-->
- 在网关的配置yaml文件中编辑如下内容:
shenyu:
metrics:
enabled: false #设置为 true 表示开启
name : prometheus
host: 127.0.0.1 #暴露的ip
port: 8090 #暴露的端口
jmxConfig: #jmx配置
props:
jvm_enabled: true #开启jvm的监控指标
metrics信息
-
所有的
JVM,线程,内存,等相关信息都会埋点,可以在Grafana面板中,新增一个JVM模块,则会完全展示 具体请看:https://github.com/prometheus/jmx_exporter -
另外还有如下自定义的
metrics
| 名称 | 类型 | 标签名称 | 说明 |
|---|---|---|---|
| shenyu_request_total | Counter | none | collecting all requests of Apache ShenYu Gateway |
| shenyu_request_throw_total | Counter | none | collecting all exception requests of Apache ShenYu Gateway |
| shenyu_request_type_total | Counter | path,type | collecting all matched requests of monitor |
| shenyu_execute_latency_millis | histogram | none | ShenYu gateway execute time interval |