Metrics插件
- 插件是网关用来监控自身运行状态(
JVM
相关),请求的响应迟延,QPS
、TPS
等相关metrics
。
异步或者同步的方式,在
Apache ShenYu
网关里面进行metrics
埋点。prometheus
服务端通过http
请求来拉取metrics
,再使用Grafana
展示。
- 在网关的
pom.xml
文件中添加metrics
的依赖。
- 在网关的配置yaml文件中编辑如下内容:
shenyu:
metrics:
enabled: false #设置为 true 表示开启
name : prometheus
host: 127.0.0.1 #暴露的ip
jmxConfig: #jmx配置
props:
jvm_enabled: true #开启jvm的监控指标
所有的
JVM
,线程,内存,等相关信息都会埋点,可以在Grafana
面板中,新增一个JVM
模块,则会完全展示 具体请看:https://github.com/prometheus/jmx_exporter另外还有如下自定义的
metrics
name | type | labals | help |
---|---|---|---|
jmx_config_reload_success_total | counter | Number of times configuration have successfully been reloaded. | |
jmx_config_reload_failure_total | counter | Number of times configuration have failed to be reloaded. | |
jmx_scrape_duration_seconds | gauge | Time this JMX scrape took, in seconds. | |
jmx_scrape_error | gauge | Non-zero if this scrape failed. | |
jmx_scrape_cached_beans | gauge | Number of beans with their matching rule cached | |
jmx_scrape_duration_seconds | gauge | Time this JMX scrape took, in seconds. | |
jmx_scrape_error | gauge | Non-zero if this scrape failed. | |
jmx_scrape_cached_beans | gauge | Number of beans with their matching rule cached |
jvm 指标
StandardExports
name | type | labels | help |
---|---|---|---|
process_cpu_seconds_total | counter | Total user and system CPU time spent in seconds. | |
process_start_time_seconds | gauge | Start time of the process since unix epoch in seconds. | |
process_open_fds | gauge | Number of open file descriptors. | |
process_max_fds | gauge | Maximum number of open file descriptors. | |
process_virtual_memory_bytes | gauge | Virtual memory size in bytes. | |
process_resident_memory_bytes | gauge | Resident memory size in bytes. |
MemoryPoolsExports
MemoryAllocationExports
name | type | labels | help |
---|---|---|---|
jvm_memory_pool_allocated_bytes_total | counter | {pool} | Total bytes allocated in a given JVM memory pool. Only updated after GC, not continuously. |
BufferPoolsExports
name | type | labels | help |
---|---|---|---|
jvm_buffer_pool_used_bytes | gauge | {pool} | Used bytes of a given JVM buffer pool. |
jvm_buffer_pool_capacity_bytes | gauge | {pool} | Bytes capacity of a given JVM buffer pool. |
jvm_buffer_pool_used_buffers | gauge | {pool} | Used buffers of a given JVM buffer pool. |
GarbageCollectorExports
ThreadExports
name | type | labels | help |
---|---|---|---|
jvm_threads_current | gauge | Current thread count of a JVM | |
jvm_threads_daemon | gauge | Daemon thread count of a JVM | |
jvm_threads_peak | gauge | Peak thread count of a JVM | |
jvm_threads_started_total | counter | Started thread count of a JVM | |
jvm_threads_deadlocked | gauge | Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers | |
jvm_threads_deadlocked_monitor | gauge | Cycles of JVM-threads that are in deadlock waiting to acquire object monitors | |
jvm_threads_state | gauge | {state} | Current count of threads by state |
ClassLoadingExports
name | type | labels | help |
---|---|---|---|
jvm_classes_loaded | gauge | The number of classes that are currently loaded in the JVM | |
jvm_classes_loaded_total | counter | The total number of classes that have been loaded since the JVM has started execution | |
jvm_classes_unloaded_total | counter | The total number of classes that have been unloaded since the JVM has started execution |
VersionInfoExports
用户需部署Prometheus
服务来采集
选择对应环境的 安装
修改配置文件:
prometheus.yml
- 配置完成之后,在
windows
下可以直接双击prometheus.exe
启动即可,默认启动端口为9090
,访问 http://localhost:9090/ ,点击status
->Targets
,验证是否成功。
macos 环境下安装Prometheus
- 使用brew 安装 prometheus,安装完成后 在
homebrew
下的Cellar
文件夹中。
brew install prometheus
- 在prometheus.yml文件所在位置执行如下命令即可启动prometheus。
访问 http://localhost:9090/
验证是否正常启动。
下面介绍如何安装 Grafana
- 安装
Grafana
解压进入 bin
目录然后双击 grafana-server.exe
运行 访问 http://localhost:3000/?orgId=1
admin/admin 验证是否成功
macos环境下安装Grafana
- 使用brew 安装 grafana 。
brew install grafana
- 以服务方式启动grafana
访问 http://localhost:3000/
验证是否正常启动。
配置数据源,选择prometheus,注意数据源名字为prometheus。
点击 Create
- Import
输入dashboards
的 面板json配置
最终自定义 Http
请求监控面板效果如下: