Metrics插件

    • 插件是网关用来监控自身运行状态(JVM相关),请求的响应迟延,QPSTPS等相关metrics
    • 异步或者同步的方式,在 Apache ShenYu 网关里面进行 metrics 埋点。

    • prometheus 服务端通过 http 请求来拉取 metrics,再使用 Grafana 展示。

    • 在网关的 pom.xml 文件中添加 metrics 的依赖。
    • 在网关的配置yaml文件中编辑如下内容:
    1. shenyu:
    2. metrics:
    3. enabled: false #设置为 true 表示开启
    4. name : prometheus
    5. host: 127.0.0.1 #暴露的ip
    6. jmxConfig: #jmx配置
    7. props:
    8. jvm_enabled: true #开启jvm的监控指标
    • 所有的JVM,线程,内存,等相关信息都会埋点,可以在 Grafana 面板中,新增一个 JVM 模块,则会完全展示 具体请看:https://github.com/prometheus/jmx_exporter

    • 另外还有如下自定义的 metrics

    nametypelabalshelp
    jmx_config_reload_success_totalcounterNumber of times configuration have successfully been reloaded.
    jmx_config_reload_failure_totalcounterNumber of times configuration have failed to be reloaded.
    jmx_scrape_duration_secondsgaugeTime this JMX scrape took, in seconds.
    jmx_scrape_errorgaugeNon-zero if this scrape failed.
    jmx_scrape_cached_beansgaugeNumber of beans with their matching rule cached
    jmx_scrape_duration_secondsgaugeTime this JMX scrape took, in seconds.
    jmx_scrape_errorgaugeNon-zero if this scrape failed.
    jmx_scrape_cached_beansgaugeNumber of beans with their matching rule cached

    jvm 指标

    StandardExports

    nametypelabelshelp
    process_cpu_seconds_totalcounterTotal user and system CPU time spent in seconds.
    process_start_time_secondsgaugeStart time of the process since unix epoch in seconds.
    process_open_fdsgaugeNumber of open file descriptors.
    process_max_fdsgaugeMaximum number of open file descriptors.
    process_virtual_memory_bytesgaugeVirtual memory size in bytes.
    process_resident_memory_bytesgaugeResident memory size in bytes.

    MemoryPoolsExports

    MemoryAllocationExports

    nametypelabelshelp
    jvm_memory_pool_allocated_bytes_totalcounter{pool}Total bytes allocated in a given JVM memory pool. Only updated after GC, not continuously.

    BufferPoolsExports

    nametypelabelshelp
    jvm_buffer_pool_used_bytesgauge{pool}Used bytes of a given JVM buffer pool.
    jvm_buffer_pool_capacity_bytesgauge{pool}Bytes capacity of a given JVM buffer pool.
    jvm_buffer_pool_used_buffersgauge{pool}Used buffers of a given JVM buffer pool.

    GarbageCollectorExports

    ThreadExports

    nametypelabelshelp
    jvm_threads_currentgaugeCurrent thread count of a JVM
    jvm_threads_daemongaugeDaemon thread count of a JVM
    jvm_threads_peakgaugePeak thread count of a JVM
    jvm_threads_started_totalcounterStarted thread count of a JVM
    jvm_threads_deadlockedgaugeCycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers
    jvm_threads_deadlocked_monitorgaugeCycles of JVM-threads that are in deadlock waiting to acquire object monitors
    jvm_threads_stategauge{state}Current count of threads by state

    ClassLoadingExports

    nametypelabelshelp
    jvm_classes_loadedgaugeThe number of classes that are currently loaded in the JVM
    jvm_classes_loaded_totalcounterThe total number of classes that have been loaded since the JVM has started execution
    jvm_classes_unloaded_totalcounterThe 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 文件夹中。
    1. 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 。
    1. brew install grafana
    • 以服务方式启动grafana

    访问 http://localhost:3000/ 验证是否正常启动。

    配置数据源,选择prometheus,注意数据源名字为prometheus。

    Metrics插件 - 图3

    点击 Create - Import 输入dashboards面板json配置

    最终自定义 Http 请求监控面板效果如下:

    Metrics插件 - 图6

    Metrics插件 - 图8