This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 4fc8a7758e2 Add MetricsExporter (#23646)
4fc8a7758e2 is described below

commit 4fc8a7758e2b8f4cc8217764e43979c226ec25c9
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Jan 19 12:41:35 2023 +0800

    Add MetricsExporter (#23646)
---
 agent/plugins/metrics/core/pom.xml                 | 43 ++++++++++++++++++++++
 .../metrics/core/exporter/MetricsExporter.java}    | 22 +++++++----
 .../core/exporter/impl/JDKBuildInfoExporter.java}  | 35 +++++++++---------
 .../impl/proxy/ProxyMetaDataInfoExporter.java}     | 23 +++++-------
 .../exporter/impl/proxy/ProxyStateExporter.java}   | 27 ++++++--------
 .../PrometheusPluginLifecycleService.java          | 12 +++---
 .../exoprter/PrometheusJDKBuildInfoExporter.java}  | 23 ++++++++----
 .../proxy/PrometheusProxyMetaDataInfoExporter.java | 39 ++++++++++++++++++++
 .../proxy/PrometheusProxyStateExporter.java}       | 23 ++++++++----
 .../PrometheusJDKBuildInfoExporterTest.java}       |  6 +--
 .../PrometheusProxyMetaDataInfoExporterTest.java}  |  6 +--
 .../proxy/PrometheusProxyStateExporterTest.java}   |  6 +--
 .../observability/_index.cn.md                     | 30 +++++++--------
 .../observability/_index.en.md                     | 10 ++---
 14 files changed, 200 insertions(+), 105 deletions(-)

diff --git a/agent/plugins/metrics/core/pom.xml 
b/agent/plugins/metrics/core/pom.xml
index 064eb875de2..c66c40c2b7a 100644
--- a/agent/plugins/metrics/core/pom.xml
+++ b/agent/plugins/metrics/core/pom.xml
@@ -32,6 +32,18 @@
     </properties>
     
     <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-infra-context</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.h2database</groupId>
+                    <artifactId>h2</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
             <artifactId>shardingsphere-infra-route</artifactId>
@@ -44,6 +56,37 @@
             <version>${project.version}</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-proxy-bootstrap</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.h2database</groupId>
+                    <artifactId>h2</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-proxy-frontend-core</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-proxy-backend</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.h2database</groupId>
+                    <artifactId>h2</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
             
<artifactId>shardingsphere-data-pipeline-distsql-statement</artifactId>
diff --git 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/MetricsExporter.java
similarity index 63%
copy from 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
copy to 
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/MetricsExporter.java
index a2a54c99686..b9d07c4aca6 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/MetricsExporter.java
@@ -15,16 +15,22 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business;
+package org.apache.shardingsphere.agent.plugin.metrics.core.exporter;
 
-import org.junit.Test;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
 
-import static org.junit.Assert.assertFalse;
+import java.util.Optional;
 
-public final class BuildInfoCollectorTest {
+/**
+ * Metrics exporter.
+ */
+public interface MetricsExporter {
     
-    @Test
-    public void assertCollect() {
-        assertFalse(new BuildInfoCollector(true).collect().isEmpty());
-    }
+    /**
+     * Export.
+     * 
+     * @param pluginType plugin type
+     * @return gauge metric family metrics collector
+     */
+    Optional<GaugeMetricFamilyMetricsCollector> export(String pluginType);
 }
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/JDKBuildInfoExporter.java
similarity index 60%
rename from 
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
rename to 
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/JDKBuildInfoExporter.java
index 7957a0ed102..28e28fe3286 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/JDKBuildInfoExporter.java
@@ -15,45 +15,44 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business;
+package org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl;
 
-import io.prometheus.client.Collector;
-import io.prometheus.client.GaugeMetricFamily;
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.MetricsExporter;
 import org.apache.shardingsphere.proxy.Bootstrap;
 
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.List;
+import java.util.Optional;
 
 /**
- * Build information collector.
+ * JDK build information collector.
  */
 @RequiredArgsConstructor
-public final class BuildInfoCollector extends Collector {
+public final class JDKBuildInfoExporter implements MetricsExporter {
     
-    private final MetricConfiguration config = new 
MetricConfiguration("build_info",
-            MetricCollectorType.GAUGE_METRIC_FAMILY, "Build information", 
Arrays.asList("version", "name"), Collections.emptyMap());
-    
-    private final boolean isEnhancedForProxy;
+    private final MetricConfiguration config = new 
MetricConfiguration("jdk_build_info",
+            MetricCollectorType.GAUGE_METRIC_FAMILY, "JDK build information", 
Arrays.asList("version", "name"), Collections.emptyMap());
     
     @Override
-    public List<MetricFamilySamples> collect() {
-        GaugeMetricFamilyMetricsCollector artifactInfo = 
MetricsCollectorRegistry.get(config, "Prometheus");
-        addMetric(artifactInfo, getClass().getPackage());
-        if (isEnhancedForProxy) {
-            addMetric(artifactInfo, Bootstrap.class.getPackage());
+    public Optional<GaugeMetricFamilyMetricsCollector> export(final String 
pluginType) {
+        GaugeMetricFamilyMetricsCollector result = 
MetricsCollectorRegistry.get(config, pluginType);
+        addJDKBuildInfo(result, getClass().getPackage());
+        try {
+            Class.forName(Bootstrap.class.getCanonicalName());
+            addJDKBuildInfo(result, Bootstrap.class.getPackage());
+        } catch (final ClassNotFoundException ignored) {
         }
-        return Collections.singletonList((GaugeMetricFamily) 
artifactInfo.getRawMetricFamilyObject());
+        return Optional.of(result);
     }
     
-    private void addMetric(final GaugeMetricFamilyMetricsCollector 
artifactInfo, final Package pkg) {
+    private void addJDKBuildInfo(final GaugeMetricFamilyMetricsCollector 
collector, final Package pkg) {
         String version = null == pkg.getImplementationVersion() ? "unknown" : 
pkg.getImplementationVersion();
         String name = null == pkg.getImplementationTitle() ? "unknown" : 
pkg.getImplementationTitle();
-        artifactInfo.addMetric(Arrays.asList(version, name), 1L);
+        collector.addMetric(Arrays.asList(version, name), 1d);
     }
 }
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java
similarity index 80%
rename from 
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
rename to 
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java
index 4038bce626c..2f83fcba0f2 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java
@@ -15,15 +15,14 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
+package 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.proxy;
 
-import io.prometheus.client.Collector;
-import io.prometheus.client.GaugeMetricFamily;
 import lombok.extern.slf4j.Slf4j;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.MetricsExporter;
 import 
org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -35,32 +34,28 @@ import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Optional;
 
 /**
  * Proxy meta data information collector.
  */
 @Slf4j
-public final class ProxyMetaDataInfoCollector extends Collector {
+public final class ProxyMetaDataInfoExporter implements MetricsExporter {
     
     private final MetricConfiguration config = new 
MetricConfiguration("proxy_meta_data_info",
             MetricCollectorType.GAUGE_METRIC_FAMILY, "Meta data information of 
ShardingSphere-Proxy. schema_count is logic number of databases; database_count 
is actual number of databases",
             Collections.singletonList("name"), Collections.emptyMap());
     
     @Override
-    public List<MetricFamilySamples> collect() {
-        List<MetricFamilySamples> result = new LinkedList<>();
+    public Optional<GaugeMetricFamilyMetricsCollector> export(final String 
pluginType) {
         if (null == ProxyContext.getInstance().getContextManager()) {
-            return result;
+            return Optional.empty();
         }
-        GaugeMetricFamilyMetricsCollector metaDataInfo = 
MetricsCollectorRegistry.get(config, "Prometheus");
+        GaugeMetricFamilyMetricsCollector result = 
MetricsCollectorRegistry.get(config, pluginType);
         MetaDataContexts metaDataContexts = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts();
-        metaDataInfo.addMetric(Collections.singletonList("schema_count"), 
metaDataContexts.getMetaData().getDatabases().size());
-        metaDataInfo.addMetric(Collections.singletonList("database_count"), 
getDatabaseNames(metaDataContexts).size());
-        result.add((GaugeMetricFamily) 
metaDataInfo.getRawMetricFamilyObject());
-        return result;
+        result.addMetric(Collections.singletonList("schema_count"), 
metaDataContexts.getMetaData().getDatabases().size());
+        result.addMetric(Collections.singletonList("database_count"), 
getDatabaseNames(metaDataContexts).size());
+        return Optional.of(result);
     }
     
     private Collection<String> getDatabaseNames(final MetaDataContexts 
metaDataContexts) {
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporter.java
similarity index 66%
rename from 
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
rename to 
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporter.java
index aa05acce15f..3acb294877e 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporter.java
@@ -15,43 +15,38 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
+package 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.proxy;
 
-import io.prometheus.client.Collector;
-import io.prometheus.client.GaugeMetricFamily;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeMetricFamilyCollector;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.MetricsExporter;
 import org.apache.shardingsphere.infra.state.StateContext;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 
 import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Optional;
 
 /**
- * Proxy state collector.
+ * Proxy state exporter.
  */
-public final class ProxyStateCollector extends Collector {
+public final class ProxyStateExporter implements MetricsExporter {
     
     private final MetricConfiguration config = new 
MetricConfiguration("proxy_state",
             MetricCollectorType.GAUGE_METRIC_FAMILY, "State of 
ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK", 
Collections.emptyList(), Collections.emptyMap());
     
     @Override
-    public List<MetricFamilySamples> collect() {
-        List<MetricFamilySamples> result = new LinkedList<>();
+    public Optional<GaugeMetricFamilyMetricsCollector> export(final String 
pluginType) {
         if (null == ProxyContext.getInstance().getContextManager()) {
-            return result;
+            return Optional.empty();
         }
         Optional<StateContext> stateContext = 
ProxyContext.getInstance().getStateContext();
         if (!stateContext.isPresent()) {
-            return result;
+            return Optional.empty();
         }
-        PrometheusGaugeMetricFamilyCollector collector = 
MetricsCollectorRegistry.get(config, "Prometheus");
-        collector.addMetric(Collections.emptyList(), 
stateContext.get().getCurrentState().ordinal());
-        result.add((GaugeMetricFamily) collector.getRawMetricFamilyObject());
-        return result;
+        GaugeMetricFamilyMetricsCollector result = 
MetricsCollectorRegistry.get(config, pluginType);
+        result.addMetric(Collections.emptyList(), 
stateContext.get().getCurrentState().ordinal());
+        return Optional.of(result);
     }
 }
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
index c5409d84032..59f08821812 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
@@ -24,9 +24,9 @@ import io.prometheus.client.hotspot.DefaultExports;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.agent.api.PluginConfiguration;
 import 
org.apache.shardingsphere.agent.plugin.core.config.validator.PluginConfigurationValidator;
-import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.BuildInfoCollector;
-import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy.ProxyMetaDataInfoCollector;
-import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy.ProxyStateCollector;
+import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter.PrometheusJDKBuildInfoExporter;
+import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter.proxy.PrometheusProxyMetaDataInfoExporter;
+import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter.proxy.PrometheusProxyStateExporter;
 import org.apache.shardingsphere.agent.spi.PluginLifecycleService;
 
 import java.io.IOException;
@@ -60,10 +60,10 @@ public final class PrometheusPluginLifecycleService 
implements PluginLifecycleSe
     }
     
     private void registerCollector(final boolean isCollectJVMInformation, 
final boolean isEnhancedForProxy) {
-        new BuildInfoCollector(isEnhancedForProxy).register();
+        new PrometheusJDKBuildInfoExporter().register();
         if (isEnhancedForProxy) {
-            new ProxyStateCollector().register();
-            new ProxyMetaDataInfoCollector().register();
+            new PrometheusProxyStateExporter().register();
+            new PrometheusProxyMetaDataInfoExporter().register();
         }
         if (isCollectJVMInformation) {
             DefaultExports.initialize();
diff --git 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/PrometheusJDKBuildInfoExporter.java
similarity index 50%
copy from 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
copy to 
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/PrometheusJDKBuildInfoExporter.java
index a2a54c99686..8ff0d4756a4 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/PrometheusJDKBuildInfoExporter.java
@@ -15,16 +15,25 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business;
+package org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter;
 
-import org.junit.Test;
+import io.prometheus.client.Collector;
+import io.prometheus.client.GaugeMetricFamily;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.JDKBuildInfoExporter;
 
-import static org.junit.Assert.assertFalse;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
 
-public final class BuildInfoCollectorTest {
+/**
+ * Prometheus JDK build information exporter.
+ */
+public final class PrometheusJDKBuildInfoExporter extends Collector {
     
-    @Test
-    public void assertCollect() {
-        assertFalse(new BuildInfoCollector(true).collect().isEmpty());
+    @Override
+    public List<MetricFamilySamples> collect() {
+        Optional<GaugeMetricFamilyMetricsCollector> collector = new 
JDKBuildInfoExporter().export("Prometheus");
+        return collector.<List<MetricFamilySamples>>map(optional -> 
Collections.singletonList((GaugeMetricFamily) 
optional.getRawMetricFamilyObject())).orElse(Collections.emptyList());
     }
 }
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyMetaDataInfoExporter.java
 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyMetaDataInfoExporter.java
new file mode 100644
index 00000000000..ec06d0a12ba
--- /dev/null
+++ 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyMetaDataInfoExporter.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter.proxy;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.GaugeMetricFamily;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.proxy.ProxyMetaDataInfoExporter;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Prometheus proxy meta data information exporter.
+ */
+public final class PrometheusProxyMetaDataInfoExporter extends Collector {
+    
+    @Override
+    public List<MetricFamilySamples> collect() {
+        Optional<GaugeMetricFamilyMetricsCollector> collector = new 
ProxyMetaDataInfoExporter().export("Prometheus");
+        return collector.<List<MetricFamilySamples>>map(optional -> 
Collections.singletonList((GaugeMetricFamily) 
optional.getRawMetricFamilyObject())).orElse(Collections.emptyList());
+    }
+}
diff --git 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyStateExporter.java
similarity index 50%
copy from 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
copy to 
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyStateExporter.java
index a2a54c99686..90563785668 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyStateExporter.java
@@ -15,16 +15,25 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business;
+package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter.proxy;
 
-import org.junit.Test;
+import io.prometheus.client.Collector;
+import io.prometheus.client.GaugeMetricFamily;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.proxy.ProxyStateExporter;
 
-import static org.junit.Assert.assertFalse;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
 
-public final class BuildInfoCollectorTest {
+/**
+ * Prometheus proxy state exporter.
+ */
+public final class PrometheusProxyStateExporter extends Collector {
     
-    @Test
-    public void assertCollect() {
-        assertFalse(new BuildInfoCollector(true).collect().isEmpty());
+    @Override
+    public List<MetricFamilySamples> collect() {
+        Optional<GaugeMetricFamilyMetricsCollector> collector = new 
ProxyStateExporter().export("Prometheus");
+        return collector.<List<MetricFamilySamples>>map(optional -> 
Collections.singletonList((GaugeMetricFamily) 
optional.getRawMetricFamilyObject())).orElse(Collections.emptyList());
     }
 }
diff --git 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
 
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/PrometheusJDKBuildInfoExporterTest.java
similarity index 87%
rename from 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
rename to 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/PrometheusJDKBuildInfoExporterTest.java
index a2a54c99686..14828250961 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/PrometheusJDKBuildInfoExporterTest.java
@@ -15,16 +15,16 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business;
+package org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter;
 
 import org.junit.Test;
 
 import static org.junit.Assert.assertFalse;
 
-public final class BuildInfoCollectorTest {
+public final class PrometheusJDKBuildInfoExporterTest {
     
     @Test
     public void assertCollect() {
-        assertFalse(new BuildInfoCollector(true).collect().isEmpty());
+        assertFalse(new PrometheusJDKBuildInfoExporter().collect().isEmpty());
     }
 }
diff --git 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollectorTest.java
 
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyMetaDataInfoExporterTest.java
similarity index 87%
rename from 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollectorTest.java
rename to 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyMetaDataInfoExporterTest.java
index 9db96d5201c..0f781931e06 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollectorTest.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyMetaDataInfoExporterTest.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
+package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter.proxy;
 
 import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.ProxyContextRestorer;
 import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -26,11 +26,11 @@ import static org.junit.Assert.assertFalse;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 
-public final class ProxyMetaDataInfoCollectorTest extends ProxyContextRestorer 
{
+public final class PrometheusProxyMetaDataInfoExporterTest extends 
ProxyContextRestorer {
     
     @Test
     public void assertCollect() {
         ProxyContext.init(mock(ContextManager.class, RETURNS_DEEP_STUBS));
-        assertFalse(new ProxyMetaDataInfoCollector().collect().isEmpty());
+        assertFalse(new 
PrometheusProxyMetaDataInfoExporter().collect().isEmpty());
     }
 }
diff --git 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollectorTest.java
 
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyStateExporterTest.java
similarity index 93%
rename from 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollectorTest.java
rename to 
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyStateExporterTest.java
index 439ef37d947..1eeb9b85ae5 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollectorTest.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/exoprter/proxy/PrometheusProxyStateExporterTest.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
+package 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.exoprter.proxy;
 
 import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.ProxyContextRestorer;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
@@ -36,7 +36,7 @@ import org.junit.Test;
 import static org.junit.Assert.assertFalse;
 import static org.mockito.Mockito.mock;
 
-public final class ProxyStateCollectorTest extends ProxyContextRestorer {
+public final class PrometheusProxyStateExporterTest extends 
ProxyContextRestorer {
     
     @Test
     public void assertCollect() {
@@ -45,6 +45,6 @@ public final class ProxyStateCollectorTest extends 
ProxyContextRestorer {
                 new ComputeNodeInstance(mock(InstanceMetaData.class)), new 
StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null),
                 mock(ModeContextManager.class), mock(LockContext.class), new 
EventBusContext());
         ProxyContext.init(new ContextManager(metaDataContexts, 
instanceContext));
-        assertFalse(new ProxyStateCollector().collect().isEmpty());
+        assertFalse(new PrometheusProxyStateExporter().collect().isEmpty());
     }
 }
diff --git 
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
 
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
index 35aa3861e4f..8b2cc43556b 100644
--- 
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
+++ 
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
@@ -154,18 +154,18 @@ services:
 
 ## Metrics
 
-| 指标名称                            | 指标类型                | 指标描述                 
                                                                     |
-| :-------------------------------- 
|:--------------------|:------------------------------------------------------------------------------------------------|
-| build_info                        | GAUGE               | 构建信息               
                                                                          |
-| parsed_sql_total                  | COUNTER             | 按类型分类的解析总数 
(INSERT、UPDATE、DELETE、SELECT、DDL、DCL、DAL、TCL、RQL、RDL、RAL、RUL)          |
-| routed_sql_total                  | COUNTER             | 按类型分类的路由总数 
(INSERT、UPDATE、DELETE、SELECT)                                               |
-| routed_data_sources_total         | COUNTER             | 数据源路由总数            
                                                                        |
-| routed_tables_total               | COUNTER             | 表路由总数              
                                                                         |
-| proxy_state                       | GAUGE               | 
ShardingSphere-Proxy 状态信息。0 表示正常状态;1 表示熔断状态;2 锁定状态                              
|
-| proxy_meta_data_info              | GAUGE_METRIC_FAMILY | 
ShardingSphere-Proxy 元数据信息,schema_count:逻辑库数量, database_count:数据源数量             
   |
-| proxy_current_connections         | GAUGE               | 
ShardingSphere-Proxy 的当前连接数                                                     
            |
-| proxy_requests_total              | COUNTER             | 
ShardingSphere-Proxy 的接受请求总数                                                    
           |
-| proxy_commit_transactions_total   | COUNTER             | 
ShardingSphere-Proxy 的事务提交总数                                                    
           |
-| proxy_rollback_transactions_total | COUNTER             | 
ShardingSphere-Proxy 的事务回滚总数                                                    
           |
-| proxy_execute_latency_millis      | HISTOGRAM           | 
ShardingSphere-Proxy 的执行耗时毫秒直方图                                                 
         |
-| proxy_execute_errors_total        | COUNTER             | 
ShardingSphere-Proxy 的执行异常总数                                                    
           |
+| 指标名称                            | 指标类型             | 指标描述                    
                                                            |
+| :-------------------------------- | :------------------ | 
:------------------------------------------------------------------------------------
 |
+| jdk_build_info                    | GAUGE_METRIC_FAMILY | 构建信息               
                                                                 |
+| parsed_sql_total                  | COUNTER             | 
按类型(INSERT、UPDATE、DELETE、SELECT、DDL、DCL、DAL、TCL、RQL、RDL、RAL、RUL)分类的解析总数 |
+| routed_sql_total                  | COUNTER             | 
按类型(INSERT、UPDATE、DELETE、SELECT)分类的路由总数                                      |
+| routed_data_sources_total         | COUNTER             | 数据源路由总数            
                                                               |
+| routed_tables_total               | COUNTER             | 表路由总数              
                                                                |
+| proxy_state                       | GAUGE_METRIC_FAMILY | 
ShardingSphere-Proxy 状态信息。0 表示正常状态;1 表示熔断状态;2 锁定状态                      |
+| proxy_meta_data_info              | GAUGE_METRIC_FAMILY | 
ShardingSphere-Proxy 元数据信息,schema_count:逻辑库数量, database_count:数据源数量        |
+| proxy_current_connections         | GAUGE               | 
ShardingSphere-Proxy 的当前连接数                                                     
   |
+| proxy_requests_total              | COUNTER             | 
ShardingSphere-Proxy 的接受请求总数                                                    
  |
+| proxy_commit_transactions_total   | COUNTER             | 
ShardingSphere-Proxy 的事务提交总数                                                    
  |
+| proxy_rollback_transactions_total | COUNTER             | 
ShardingSphere-Proxy 的事务回滚总数                                                    
  |
+| proxy_execute_latency_millis      | HISTOGRAM           | 
ShardingSphere-Proxy 的执行耗时毫秒直方图                                                 
|
+| proxy_execute_errors_total        | COUNTER             | 
ShardingSphere-Proxy 的执行异常总数                                                    
  |
diff --git 
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
 
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
index 7733b7b0a34..ad4a0143e2b 100644
--- 
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
+++ 
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
@@ -158,13 +158,13 @@ services:
 ## Metrics
 
 | Name                              | Type                | Description        
                                                                                
                                    |
-| :-------------------------------- 
|:--------------------|:---------------------------------------------------------------------------------------------------------------------------------------|
-| build_info                        | GAUGE               | Build information  
                                                                                
                                    |
-| parsed_sql_total                  | COUNTER             | Total count of 
parsed by type. (INSERT, UPDATE, DELETE, SELECT, DDL, DCL, DAL, TCL, RQL, RDL, 
RAL, RUL)                                |
-| routed_sql_total                  | COUNTER             | Total count of 
routed by type. (INSERT, UPDATE, DELETE, SELECT)                                
                                        |
+| :-------------------------------- | :------------------ | 
:-------------------------------------------------------------------------------------------------------------------------------------
 |
+| jdk_build_info                    | GAUGE_METRIC_FAMILY | Build information  
                                                                                
                                    |
+| parsed_sql_total                  | COUNTER             | Total count of 
parsed by type (INSERT, UPDATE, DELETE, SELECT, DDL, DCL, DAL, TCL, RQL, RDL, 
RAL, RUL)                                 |
+| routed_sql_total                  | COUNTER             | Total count of 
routed by type (INSERT, UPDATE, DELETE, SELECT)                                 
                                        |
 | routed_data_sources_total         | COUNTER             | Total count of 
data source routed                                                              
                                        |
 | routed_tables_total               | COUNTER             | Total count of 
table routed                                                                    
                                        |
-| proxy_state                       | GAUGE               | Status information 
of ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK                 
                                    |
+| proxy_state                       | GAUGE_METRIC_FAMILY | Status information 
of ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK                 
                                    |
 | proxy_meta_data_info              | GAUGE_METRIC_FAMILY | Meta data 
information of ShardingSphere-Proxy. schema_count is logic number of databases; 
database_count is actual number of databases |
 | proxy_current_connections         | GAUGE               | Current 
connections of ShardingSphere-Proxy                                             
                                               |
 | proxy_requests_total              | COUNTER             | Total requests of 
ShardingSphere-Proxy                                                            
                                     |


Reply via email to