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

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new fcdb7680 :sparkles: Add Prometheus Metrics Sample (#705)
fcdb7680 is described below

commit fcdb76808d74085f525de91757f88fa342450a10
Author: songxiaosheng <[email protected]>
AuthorDate: Mon Jan 16 21:17:19 2023 +0800

    :sparkles: Add Prometheus Metrics Sample (#705)
---
 .../dubbo-samples-metrics-prometheus/README.md     |  41 ++++
 .../case-configuration.yml                         |  24 ++
 .../case-versions.conf                             |  25 ++
 .../dubbo-samples-metrics-prometheus/pom.xml       | 174 ++++++++++++++
 .../metrics/prometheus/EmbeddedZooKeeper.java      | 256 +++++++++++++++++++++
 .../metrics/prometheus/MetricsConsumer.java        |  59 +++++
 .../metrics/prometheus/MetricsProvider.java        |  51 ++++
 .../metrics/prometheus/api/DemoService.java        |  51 ++++
 .../metrics/prometheus/impl/DemoServiceImpl.java   |  88 +++++++
 .../samples/metrics/prometheus/model/Result.java   |  69 ++++++
 .../samples/metrics/prometheus/model/User.java     |  66 ++++++
 .../src/main/resources/log4j.properties            |  26 +++
 .../main/resources/spring/dubbo-demo-consumer.xml  |  36 +++
 .../main/resources/spring/dubbo-demo-provider.xml  |  40 ++++
 .../metrics/prometheus/ConsumerMetricsIT.java      |  55 +++++
 .../metrics/prometheus/ProviderMetricsIT.java      |  54 +++++
 4-governance/pom.xml                               |   1 +
 17 files changed, 1116 insertions(+)

diff --git a/4-governance/dubbo-samples-metrics-prometheus/README.md 
b/4-governance/dubbo-samples-metrics-prometheus/README.md
new file mode 100644
index 00000000..b0ee6e79
--- /dev/null
+++ b/4-governance/dubbo-samples-metrics-prometheus/README.md
@@ -0,0 +1,41 @@
+# 使用Metrics模块进行数据采集然后暴漏数据给普罗米修斯监控
+Dubbo使用开源的[Dubbo 
Metrics](https://github.com/alibaba/metrics)进行数据埋点,并且通过服务暴露,使用的时候,首先需要进行配置:  
+
+* 依赖(其中Dubbo版本在3.2.0-beta及以后)
+```xml
+  <dependency>
+    <groupId>org.apache.dubbo</groupId>
+    <artifactId>dubbo-spring-boot-actuator</artifactId>
+</dependency>
+
+<dependency>
+    <groupId>org.apache.dubbo</groupId>
+    <artifactId>dubbo-metrics-prometheus</artifactId>
+</dependency>
+
+```
+* 服务端
+```xml
+<dubbo:metrics protocol="prometheus">
+    <dubbo:aggregation enabled="true"/>
+    <dubbo:prometheus-exporter enabled="true"/>
+</dubbo:metrics>
+
+```
+
+* 客户端
+```xml
+ <dubbo:metrics protocol="prometheus">
+    <dubbo:aggregation enabled="true"/>
+    <dubbo:prometheus-exporter enabled="true" metrics-port="20889"/>
+</dubbo:metrics>
+
+```
+先启动服务端,然后启动客户端,
+提供端监控指标:http://localhost:20888/metrics
+消费端监控指标:http://localhost:20889/metrics
+
+其中,`<dubbo:metrics />`的配置指定了metrics暴露的协议和端口,这些信息会被放在元数据里面,而`<dubbo:provider 
/>`和`<dubbo: consumer 
/>`则在服务端和客户端分别激活了metrics的filter,如果你的服务分别含有服务端和客户端,选择在一端激活就可以。
+
+可观测性文档如下链接:
+  
[https://cn.dubbo.apache.org/zh/docs3-v2/java-sdk/advanced-features-and-usage/observability/](https://cn.dubbo.apache.org/zh/docs3-v2/java-sdk/advanced-features-and-usage/observability/)
\ No newline at end of file
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/case-configuration.yml 
b/4-governance/dubbo-samples-metrics-prometheus/case-configuration.yml
new file mode 100644
index 00000000..e44a79c0
--- /dev/null
+++ b/4-governance/dubbo-samples-metrics-prometheus/case-configuration.yml
@@ -0,0 +1,24 @@
+# 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.
+
+from: app-builtin-zookeeper.yml
+
+props:
+  project_name: dubbo-samples-metrics-prometheus
+  main_class: org.apache.dubbo.samples.metrics.prometheus.MetricsProvider
+  zookeeper_port: 2181
+  dubbo_port: 20880
+
diff --git a/4-governance/dubbo-samples-metrics-prometheus/case-versions.conf 
b/4-governance/dubbo-samples-metrics-prometheus/case-versions.conf
new file mode 100644
index 00000000..a370983f
--- /dev/null
+++ b/4-governance/dubbo-samples-metrics-prometheus/case-versions.conf
@@ -0,0 +1,25 @@
+#
+#
+#   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.
+#
+
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version=[ >=3.2.0 ]
+spring.version=4.*, 5.*
+java.version= [<= 11]
diff --git a/4-governance/dubbo-samples-metrics-prometheus/pom.xml 
b/4-governance/dubbo-samples-metrics-prometheus/pom.xml
new file mode 100644
index 00000000..0905b55e
--- /dev/null
+++ b/4-governance/dubbo-samples-metrics-prometheus/pom.xml
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <groupId>org.apache</groupId>
+        <artifactId>apache</artifactId>
+        <version>23</version>
+        <relativePath/>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.dubbo</groupId>
+    <artifactId>dubbo-samples-metrics-prometheus</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <name>Dubbo Samples Metrics</name>
+    <description>Dubbo Samples Metrics</description>
+
+    <properties>
+        <source.level>1.8</source.level>
+        <target.level>1.8</target.level>
+        <dubbo.version>3.2.0-beta.4-SNAPSHOT</dubbo.version>
+        <junit.version>4.13.1</junit.version>
+        <spring.version>4.3.29.RELEASE</spring.version>
+        <httpclient.version>4.5.13</httpclient.version>
+        <junit.version>4.13.1</junit.version>
+        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-framework-bom</artifactId>
+                <version>${spring.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-bom</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-dependencies-zookeeper</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.httpcomponents</groupId>
+                <artifactId>httpclient</artifactId>
+                <version>${httpclient.version}</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
+                <groupId>junit</groupId>
+                <artifactId>junit</artifactId>
+                <version>${junit.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-spring-boot-actuator</artifactId>
+        </dependency>
+
+        <!-- 
https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-metrics-prometheus -->
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-metrics-prometheus</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <type>pom</type>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.83_noneautotype</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <!-- For jdk 11 above JavaEE annotation -->
+        <profile>
+            <id>javax.annotation</id>
+            <activation>
+                <jdk>[1.11,)</jdk>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>javax.annotation</groupId>
+                    <artifactId>javax.annotation-api</artifactId>
+                    <version>1.3.2</version>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+                <configuration>
+                    <source>${source.level}</source>
+                    <target>${target.level}</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/EmbeddedZooKeeper.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/EmbeddedZooKeeper.java
new file mode 100644
index 00000000..b9440793
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/EmbeddedZooKeeper.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.dubbo.samples.metrics.prometheus;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.util.ErrorHandler;
+import org.springframework.util.SocketUtils;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * from: 
https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
+ *
+ * Helper class to start an embedded instance of standalone (non clustered) 
ZooKeeper.
+ *
+ * NOTE: at least an external standalone server (if not an ensemble) are 
recommended, even for
+ * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
+ *
+ * @author Patrick Peralta
+ * @author Mark Fisher
+ * @author David Turanski
+ */
+public class EmbeddedZooKeeper implements SmartLifecycle {
+
+    /**
+     * Logger.
+     */
+    private static final Logger logger = 
LoggerFactory.getLogger(EmbeddedZooKeeper.class);
+
+    /**
+     * ZooKeeper client port. This will be determined dynamically upon startup.
+     */
+    private final int clientPort;
+
+    /**
+     * Whether to auto-start. Default is true.
+     */
+    private boolean autoStartup = true;
+
+    /**
+     * Lifecycle phase. Default is 0.
+     */
+    private int phase = 0;
+
+    /**
+     * Thread for running the ZooKeeper server.
+     */
+    private volatile Thread zkServerThread;
+
+    /**
+     * ZooKeeper server.
+     */
+    private volatile ZooKeeperServerMain zkServer;
+
+    /**
+     * {@link ErrorHandler} to be invoked if an Exception is thrown from the 
ZooKeeper server thread.
+     */
+    private ErrorHandler errorHandler;
+
+    private boolean daemon = true;
+
+    /**
+     * Construct an EmbeddedZooKeeper with a random port.
+     */
+    public EmbeddedZooKeeper() {
+        clientPort = SocketUtils.findAvailableTcpPort();
+    }
+
+    /**
+     * Construct an EmbeddedZooKeeper with the provided port.
+     *
+     * @param clientPort  port for ZooKeeper server to bind to
+     */
+    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
+        this.clientPort = clientPort;
+        this.daemon = daemon;
+    }
+
+    /**
+     * Returns the port that clients should use to connect to this embedded 
server.
+     *
+     * @return dynamically determined client port
+     */
+    public int getClientPort() {
+        return this.clientPort;
+    }
+
+    /**
+     * Specify whether to start automatically. Default is true.
+     *
+     * @param autoStartup whether to start automatically
+     */
+    public void setAutoStartup(boolean autoStartup) {
+        this.autoStartup = autoStartup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isAutoStartup() {
+        return this.autoStartup;
+    }
+
+    /**
+     * Specify the lifecycle phase for the embedded server.
+     *
+     * @param phase the lifecycle phase
+     */
+    public void setPhase(int phase) {
+        this.phase = phase;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int getPhase() {
+        return this.phase;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isRunning() {
+        return (zkServerThread != null);
+    }
+
+    /**
+     * Start the ZooKeeper server in a background thread.
+     * <p>
+     * Register an error handler via {@link #setErrorHandler} in order to 
handle
+     * any exceptions thrown during startup or execution.
+     */
+    @Override
+    public synchronized void start() {
+        if (zkServerThread == null) {
+            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper 
Server Starter");
+            zkServerThread.setDaemon(daemon);
+            zkServerThread.start();
+        }
+    }
+
+    /**
+     * Shutdown the ZooKeeper server.
+     */
+    @Override
+    public synchronized void stop() {
+        if (zkServerThread != null) {
+            // The shutdown method is protected...thus this hack to invoke it.
+            // This will log an exception on shutdown; see
+            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for 
details.
+            try {
+                Method shutdown = 
ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
+                shutdown.setAccessible(true);
+                shutdown.invoke(zkServer);
+            }
+
+            catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+
+            // It is expected that the thread will exit after
+            // the server is shutdown; this will block until
+            // the shutdown is complete.
+            try {
+                zkServerThread.join(5000);
+                zkServerThread = null;
+            }
+            catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                logger.warn("Interrupted while waiting for embedded ZooKeeper 
to exit");
+                // abandoning zk thread
+                zkServerThread = null;
+            }
+        }
+    }
+
+    /**
+     * Stop the server if running and invoke the callback when complete.
+     */
+    @Override
+    public void stop(Runnable callback) {
+        stop();
+        callback.run();
+    }
+
+    /**
+     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown 
from the ZooKeeper server thread. If none
+     * is provided, only error-level logging will occur.
+     *
+     * @param errorHandler the {@link ErrorHandler} to be invoked
+     */
+    public void setErrorHandler(ErrorHandler errorHandler) {
+        this.errorHandler = errorHandler;
+    }
+
+    /**
+     * Runnable implementation that starts the ZooKeeper server.
+     */
+    private class ServerRunnable implements Runnable {
+
+        @Override
+        public void run() {
+            try {
+                Properties properties = new Properties();
+                File file = new File(System.getProperty("java.io.tmpdir")
+                    + File.separator + UUID.randomUUID());
+                file.deleteOnExit();
+                properties.setProperty("dataDir", file.getAbsolutePath());
+                properties.setProperty("clientPort", 
String.valueOf(clientPort));
+
+                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
+                quorumPeerConfig.parseProperties(properties);
+
+                zkServer = new ZooKeeperServerMain();
+                ServerConfig configuration = new ServerConfig();
+                configuration.readFrom(quorumPeerConfig);
+
+                zkServer.runFromConfig(configuration);
+            }
+            catch (Exception e) {
+                if (errorHandler != null) {
+                    errorHandler.handleError(e);
+                }
+                else {
+                    logger.error("Exception running embedded ZooKeeper", e);
+                }
+            }
+        }
+    }
+
+}
+
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/MetricsConsumer.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/MetricsConsumer.java
new file mode 100644
index 00000000..3481e30c
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/MetricsConsumer.java
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.dubbo.samples.metrics.prometheus;
+
+import org.apache.dubbo.samples.metrics.prometheus.api.DemoService;
+import org.apache.dubbo.samples.metrics.prometheus.model.Result;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MetricsConsumer {
+
+    public static void main(String[] args) {
+        ClassPathXmlApplicationContext context = new 
ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
+        context.start();
+
+        DemoService demoService = context.getBean("demoService", 
DemoService.class);
+
+        while (true) {
+            try {
+                Thread.sleep(3000);
+                Result hello = demoService.sayHello("world");
+                System.out.println(hello.getMsg());
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/MetricsProvider.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/MetricsProvider.java
new file mode 100644
index 00000000..3d90a8a4
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/MetricsProvider.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.dubbo.samples.metrics.prometheus;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class MetricsProvider {
+
+    public static void main(String[] args) throws Exception {
+        new EmbeddedZooKeeper(2181, false).start();
+
+        ClassPathXmlApplicationContext context = new 
ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
+        context.start();
+
+        System.out.println("dubbo service started");
+        new CountDownLatch(1).await();
+    }
+}
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/api/DemoService.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/api/DemoService.java
new file mode 100644
index 00000000..fe683087
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/api/DemoService.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.dubbo.samples.metrics.prometheus.api;
+
+import org.apache.dubbo.samples.metrics.prometheus.model.Result;
+import org.apache.dubbo.samples.metrics.prometheus.model.User;
+
+import java.util.concurrent.CompletableFuture;
+
+public interface DemoService {
+    CompletableFuture<Integer> sayHello();
+
+    Result sayHello(String name);
+
+    Result sayHello(Long id, String name);
+
+    Result sayHello(User user);
+
+    String stringArray(String[] bytes);
+}
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/impl/DemoServiceImpl.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/impl/DemoServiceImpl.java
new file mode 100644
index 00000000..ad632eb8
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/impl/DemoServiceImpl.java
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.dubbo.samples.metrics.prometheus.impl;
+
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.samples.metrics.prometheus.model.Result;
+import org.apache.dubbo.samples.metrics.prometheus.model.User;
+import org.apache.dubbo.samples.metrics.prometheus.api.DemoService;
+
+import com.alibaba.dubbo.rpc.RpcContext;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.CompletableFuture;
+
+public class DemoServiceImpl implements DemoService {
+
+    public static final Logger logger = 
LoggerFactory.getLogger(DemoServiceImpl.class);
+
+    private String name = "Han MeiMei";
+
+    @Override
+    public CompletableFuture<Integer> sayHello() {
+        return CompletableFuture.completedFuture(2122);
+    }
+
+
+
+    @Override
+    public Result sayHello(String localName) {
+        logger.info("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) 
+ "] Hello " + name + ", request from consumer: " + RpcContext
+                .getContext().getRemoteAddress());
+        return new Result(name, "Hello " + localName + ", response from 
provider: " + RpcContext.getContext().getLocalAddress());
+    }
+
+    @Override
+    public Result sayHello(final Long id, final String name) {
+        return sayHello(new User(id, name));
+    }
+
+    @Override
+    public Result sayHello(final User user) {
+        String localName = user.getUsername();
+        Long id = user.getId();
+        logger.info("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) 
+ "] Hello " + name + ", request from consumer: " + RpcContext
+                .getContext().getRemoteAddress());
+        return new Result(name, "Hello " + id + " " + localName +
+//                " " + "bytes: " + user.getBytes().toString() +
+                ", response from provider: " + 
RpcContext.getContext().getLocalAddress());
+    }
+
+    @Override
+    public String stringArray(String[] bytes) {
+        return bytes.toString();
+    }
+}
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/model/Result.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/model/Result.java
new file mode 100644
index 00000000..1e083596
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/model/Result.java
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.dubbo.samples.metrics.prometheus.model;
+
+import java.io.Serializable;
+
+/**
+ * @author zmx ON 2019-07-03
+ */
+public class Result implements Serializable {
+    public Result(){
+
+    }
+
+    public Result(String userName, String msg){
+        this.msg = msg;
+        this.userName = userName;
+    }
+
+    private String userName;
+    private String msg;
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+}
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/model/User.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/model/User.java
new file mode 100644
index 00000000..dce5aa08
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/java/org/apache/dubbo/samples/metrics/prometheus/model/User.java
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.dubbo.samples.metrics.prometheus.model;
+
+import java.io.Serializable;
+
+public class User implements Serializable {
+    private Long id;
+    private String username;
+
+    public User() {
+    }
+
+    public User(final Long id, final String username) {
+        this.id = id;
+        this.username = username;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(final Long id) {
+        this.id = id;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(final String username) {
+        this.username = username;
+    }
+
+}
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/log4j.properties
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/log4j.properties
new file mode 100644
index 00000000..d6ecd5ce
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/log4j.properties
@@ -0,0 +1,26 @@
+#
+#
+#   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.
+#
+#
+
+###set log levels###
+log4j.rootLogger=info, stdout
+###output to the console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy hh:mm:ss:sss z}] 
%t %5p %c{2}: %m%n
\ No newline at end of file
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/spring/dubbo-demo-consumer.xml
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/spring/dubbo-demo-consumer.xml
new file mode 100644
index 00000000..9481d646
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo";
+       xmlns="http://www.springframework.org/schema/beans"; 
xmlns:context="http://www.springframework.org/schema/context";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://dubbo.apache.org/schema/dubbo 
http://dubbo.apache.org/schema/dubbo/dubbo.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd";>
+    <context:property-placeholder/>
+
+    <dubbo:application name="metrics-demo-consumer"/>
+
+    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+
+    <dubbo:reference id="demoService" check="false" 
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService"/>
+    <dubbo:metrics protocol="prometheus" enable-jvm-metrics="true">
+        <dubbo:aggregation enabled="true"/>
+        <dubbo:prometheus-exporter enabled="true" metrics-port="20889"/>
+    </dubbo:metrics>
+
+</beans>
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/spring/dubbo-demo-provider.xml
 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/spring/dubbo-demo-provider.xml
new file mode 100644
index 00000000..09ae86e9
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/main/resources/spring/dubbo-demo-provider.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo";
+       xmlns="http://www.springframework.org/schema/beans"; 
xmlns:context="http://www.springframework.org/schema/context";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://dubbo.apache.org/schema/dubbo 
http://dubbo.apache.org/schema/dubbo/dubbo.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd";>
+    <context:property-placeholder/>
+
+    <dubbo:application name="metrics-provider"/>
+
+    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+    <dubbo:config-center 
address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />
+    <dubbo:metadata-report 
address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />
+
+    <dubbo:metrics protocol="prometheus" enable-jvm-metrics="true">
+        <dubbo:aggregation enabled="true"/>
+        <dubbo:prometheus-exporter enabled="true"  metrics-port="20888"/>
+    </dubbo:metrics>
+
+    <bean id="demoService" 
class="org.apache.dubbo.samples.metrics.prometheus.impl.DemoServiceImpl"/>
+
+    <dubbo:service 
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService" 
ref="demoService"/>
+</beans>
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ConsumerMetricsIT.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ConsumerMetricsIT.java
new file mode 100644
index 00000000..de861d8d
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ConsumerMetricsIT.java
@@ -0,0 +1,55 @@
+/*
+ * 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.dubbo.samples.metrics.prometheus;
+
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.stream.Collectors;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = 
{"classpath:/spring/dubbo-demo-consumer.xml"})
+public class ConsumerMetricsIT {
+
+
+    private final String port = "20889";
+
+    @Test
+    public void test() throws Exception {
+        try (CloseableHttpClient client = HttpClients.createDefault()) {
+            HttpGet request = new HttpGet("http://localhost:"; + port + 
"/metrics");
+            CloseableHttpResponse response = client.execute(request);
+            InputStream inputStream = response.getEntity().getContent();
+            String text = new BufferedReader(new 
InputStreamReader(inputStream, 
StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
+            
Assert.assertTrue(text.contains("jvm_gc_memory_promoted_bytes_total"));
+        } catch (Exception e) {
+           Assert.fail(e.getMessage());
+        }
+    }
+}
diff --git 
a/4-governance/dubbo-samples-metrics-prometheus/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ProviderMetricsIT.java
 
b/4-governance/dubbo-samples-metrics-prometheus/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ProviderMetricsIT.java
new file mode 100644
index 00000000..35c34013
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-prometheus/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ProviderMetricsIT.java
@@ -0,0 +1,54 @@
+/*
+ * 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.dubbo.samples.metrics.prometheus;
+
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.stream.Collectors;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = 
{"classpath:/spring/dubbo-demo-provider.xml"})
+public class ProviderMetricsIT {
+
+    private  final String port = "20888";
+
+    @Test
+    public void test() throws Exception {
+        try (CloseableHttpClient client = HttpClients.createDefault()) {
+            HttpGet request = new HttpGet("http://localhost:"; + port + 
"/metrics");
+            CloseableHttpResponse response = client.execute(request);
+            InputStream inputStream = response.getEntity().getContent();
+            String text = new BufferedReader(new 
InputStreamReader(inputStream, 
StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
+            
Assert.assertTrue(text.contains("jvm_gc_memory_promoted_bytes_total"));
+        } catch (Exception e) {
+            Assert.fail(e.getMessage());
+        }
+    }
+}
diff --git a/4-governance/pom.xml b/4-governance/pom.xml
index 9efe1645..8a7b1541 100644
--- a/4-governance/pom.xml
+++ b/4-governance/pom.xml
@@ -31,6 +31,7 @@
         <module>dubbo-samples-configconditionrouter</module>
         <module>dubbo-samples-meshrule-router</module>
         <module>dubbo-samples-metrics</module>
+        <module>dubbo-samples-metrics-prometheus</module>
         <module>dubbo-samples-monitor</module>
         <module>dubbo-samples-sentinel</module>
         <module>dubbo-samples-servicelevel-override</module>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to