title: Metrics Plugin keywords: [“Metrics”] description: Metrics plugin

Description

  • Metrics plugin is used to monitor its own running status(JVM-related) by gateway, include request response delay, QPS, TPS, and other related metrics.

Technical Solutions

  • Flow Diagram

  • Make even tracking in ShenYu Gateway by asynchronous or synchronous mode.

  • The prometheus server pulls metrics' through http request, and then displays it by Grafana.

Plugin Setting

  • Introduce metrics dependency in the pom.xml file of the gateway.
  <!-- apache shenyu metrics plugin start-->
  <dependency>
      <groupId>org.apache.shenyu</groupId>
      <artifactId>shenyu-spring-boot-starter-plugin-metrics</artifactId>
      <version>${project.version}</version>
  </dependency>
  <!-- apache shenyu metrics plugin end-->
  • modify this config in shenyu gateway yaml
shenyu:
  metrics:
    enabled: false #false is close, true is open
    name : prometheus 
    host: 127.0.0.1
    port: 8090
    jmxConfig:
    props:
      jvm_enabled: true #enable jvm monitoring

Metrics Detail

  • All JVM,thread,memory,and other related information will be made event tracking,you can add a JVM module in the Grafana' panel, and it will be fully displayed, please refer to: https://github.com/prometheus/jmx_exporter

  • There are also the following custom metrics

shenyu gateway custom metrics

Nametypelabelsdescription
shenyu_request_totalCounternonecollecting all requests of Apache ShenYu Gateway
shenyu_request_throw_totalCounternonecollecting all exception requests of Apache ShenYu Gateway
shenyu_request_type_totalCounterpath,typecollecting all matched requests of monitor
shenyu_execute_latency_millishistogramnoneShenYu gateway execute time interval

jmx 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 metrics

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

nametypelabelshelp
jvm_memory_objects_pending_finalizationgauge{area=“heap|nonheap”}The number of objects waiting in the finalizer queue.
jvm_memory_bytes_usedgauge{area=“heap|nonheap”}Used bytes of a given JVM memory area.
jvm_memory_bytes_committedgauge{area=“heap|nonheap”}Committed (bytes) of a given JVM memory area.
jvm_memory_bytes_maxgauge{area=“heap|nonheap”}Max (bytes) of a given JVM memory area.
jvm_memory_bytes_initgauge{area=“heap|nonheap”}Initial bytes of a given JVM memory area.
jvm_memory_pool_bytes_usedgauge{pool}Used bytes of a given JVM memory pool.
jvm_memory_pool_bytes_committedgauge{pool}Committed bytes of a given JVM memory pool.
jvm_memory_pool_bytes_maxgauge{pool}Max bytes of a given JVM memory pool.
jvm_memory_pool_bytes_initgauge{pool}Initial bytes of a given JVM memory pool.
jvm_memory_pool_collection_used_bytesgauge{pool}Used bytes after last collection of a given JVM memory pool.
jvm_memory_pool_collection_committed_bytesgauge{pool}Committed after last collection bytes of a given JVM memory pool.
jvm_memory_pool_collection_max_bytesgauge{pool}Max bytes after last collection of a given JVM memory pool.
jvm_memory_pool_collection_init_bytesgauge{pool}Initial after last collection bytes of a given JVM memory pool.

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

nametypelabelshelp
jvm_gc_collection_secondssummary{gc}Time spent in a given JVM garbage collector in seconds.

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

nametypelabelshelp
jvminfo{version(java.runtime.version),vendor(java.vm.vendor),runtime(java.runtime.name)}VM version info

Collect metrics

Users need to install Prometheus service to collect

Install Prometheus in windows

  • Choose the corresponding environment download address to install
  • Modify configuration file: prometheus.yml
scrape_configs:
  - job_name: 'Apache ShenYu'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['localhost:8090'] # metrics of apache shenyu are exposed on port 8090 by default
  • After the configuration is completed, you can directly double-click prometheus.exe in the window to start. The default boot port is 9090,check status->Targets . Success can be verified at http://localhost:9090/

Install Prometheus in the macOS

  • Install prometheus with brew,After installation prometheus is in the Cellar folder under homebrew
brew install prometheus
  • Execute the following command in the location of the prometheus.yml file to start prometheus。
prometheus --config.file=prometheus.yml &

Visit http://localhost:9090/ to verify that it starts normally。

Panel Display

It is recommended to use Grafana, Users can customize the query to personalize the display panel.

Here's how to install and deploy Grafana

Install Grafana in windows

  • Install Grafana

download Unzip it and enter the bin directory and double-click grafana-server.exe to run it. Go to http://localhost:3000/?orgId=1 admin/admin to verify the success

Install Grafana in macOS

  • Install grafana using brew.
brew install grafana
  • Start grafana as a service
brew services start grafana

Visit http://localhost:3000/ to verify that it starts normally.

View monitoring data with Grafana

  • Configure the data source, select prometheus, note that the data source name is prometheus.

  • Config Custom Metric Dashboard request_totalhttp_request_total

Click Create - Import and enter the panel config json

The final custom HTTP request monitoring panel looks like this: