You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/01/09 08:57:35 UTC

[GitHub] liubao68 closed pull request #480: [SCB-118] add prometheus integration impl

liubao68 closed pull request #480: [SCB-118] add prometheus integration impl
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/480
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/SpringmvcClient.java
index bd2343374..f03b9b45c 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/SpringmvcClient.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/SpringmvcClient.java
@@ -128,6 +128,38 @@ public static void run() throws Exception {
     } catch (Exception e) {
       TestMgr.check("true", "false");
     }
+
+    //prometheus integration test
+    try {
+      String content = restTemplate.getForObject("cse://springmvc/codeFirstSpringmvc/prometheusForTest", String.class);
+
+      TestMgr.check(true,content.contains("servicecomb_springmvc_codeFirst_addDate"));
+      TestMgr.check(true,content.contains("servicecomb_springmvc_codeFirst_sayHello"));
+      TestMgr.check(true,content.contains("servicecomb_springmvc_codeFirst_fallbackFromCache"));
+      TestMgr.check(true,content.contains("servicecomb_springmvc_codeFirst_isTrue_producer"));
+      TestMgr.check(true,content.contains("servicecomb_springmvc_codeFirst_add"));
+      TestMgr.check(true,content.contains("servicecomb_springmvc_codeFirst_sayHi2"));
+      TestMgr.check(true,content.contains("servicecomb_springmvc_codeFirst_saySomething"));
+
+      String[] metricLines = content.split("\n");
+      if (metricLines.length > 0) {
+        for (String metricLine : metricLines) {
+          if (!metricLine.startsWith("#")) {
+            String[] metricKeyAndValue = metricLine.split(" ");
+            if (!metricKeyAndValue[0].startsWith("servicecomb_instance_system")) {
+              if (Double.parseDouble(metricKeyAndValue[1]) < 0) {
+                TestMgr.check("true", "false");
+                break;
+              }
+            }
+          }
+        }
+      } else {
+        TestMgr.check("true", "false");
+      }
+    } catch (Exception e) {
+      TestMgr.check("true", "false");
+    }
   }
 
   private static void testController(RestTemplate template, String microserviceName) {
diff --git a/demo/demo-springmvc/springmvc-server/pom.xml b/demo/demo-springmvc/springmvc-server/pom.xml
index 772e35f05..43a7551c1 100644
--- a/demo/demo-springmvc/springmvc-server/pom.xml
+++ b/demo/demo-springmvc/springmvc-server/pom.xml
@@ -39,7 +39,7 @@
 
 		<dependency>
 			<groupId>io.servicecomb</groupId>
-			<artifactId>metrics-core</artifactId>
+			<artifactId>metrics-prometheus</artifactId>
 		</dependency>
 
 	</dependencies>
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java b/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
index a244e03cd..8011dbf75 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
@@ -50,6 +50,7 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RequestPart;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.client.RestTemplate;
 import org.springframework.web.multipart.MultipartFile;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -352,6 +353,13 @@ public String metricsForTest() {
     }
   }
 
+  //Only for Prometheus integration test
+  @RequestMapping(path = "/prometheusForTest", method = RequestMethod.GET)
+  public String prometheusForTest() {
+    RestTemplate defaultRestTemplate = new RestTemplate();
+    return defaultRestTemplate.getForObject("http://localhost:9696/metrics", String.class);
+  }
+
   @GetMapping(path = "/traceId")
   public String getTraceId() {
     return ContextUtils.getInvocationContext().getContext(Const.TRACE_ID_NAME);
diff --git a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
index f5d230404..034f0d074 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
@@ -20,7 +20,7 @@ servicecomb:
 APPLICATION_ID: springmvctest
 service_description:
   name: springmvc
-  version: 0.0.2
+  version: 0.0.3
   paths:
     - path: /test1/testpath
       property:
diff --git a/java-chassis-dependencies/pom.xml b/java-chassis-dependencies/pom.xml
index 7c7f351b9..a111a3ff1 100644
--- a/java-chassis-dependencies/pom.xml
+++ b/java-chassis-dependencies/pom.xml
@@ -698,6 +698,17 @@
         <version>${brave.version}</version>
       </dependency>
 
+      <dependency>
+        <groupId>io.prometheus</groupId>
+        <artifactId>simpleclient</artifactId>
+        <version>0.1.0</version>
+      </dependency>
+      <dependency>
+        <groupId>io.prometheus</groupId>
+        <artifactId>simpleclient_httpserver</artifactId>
+        <version>0.1.0</version>
+      </dependency>
+
       <dependency>
         <groupId>io.servicecomb</groupId>
         <artifactId>foundation-common</artifactId>
@@ -954,6 +965,11 @@
         <artifactId>metrics-common</artifactId>
         <version>0.6.0-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>io.servicecomb</groupId>
+        <artifactId>metrics-prometheus</artifactId>
+        <version>0.6.0-SNAPSHOT</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 
diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/ConsumerInvocationMetric.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/ConsumerInvocationMetric.java
index d4aee4aa9..bbd5f0722 100644
--- a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/ConsumerInvocationMetric.java
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/ConsumerInvocationMetric.java
@@ -46,8 +46,8 @@ public ConsumerInvocationMetric(@JsonProperty("operationName") String operationN
 
   public ConsumerInvocationMetric merge(ConsumerInvocationMetric metric) {
     return new ConsumerInvocationMetric(this.getOperationName(), this.getPrefix(),
-        metric.getConsumerLatency().merge(consumerLatency),
-        metric.getConsumerCall().merge(consumerCall));
+        consumerLatency.merge(metric.getConsumerLatency()),
+        consumerCall.merge(metric.getConsumerCall()));
   }
 
   public Map<String, Number> toMap() {
diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/InstanceMetric.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/InstanceMetric.java
index b8dd03ebe..c7dd0c2f2 100644
--- a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/InstanceMetric.java
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/InstanceMetric.java
@@ -17,6 +17,9 @@
 
 package io.servicecomb.metrics.common;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 public class InstanceMetric {
@@ -45,4 +48,12 @@ public InstanceMetric(@JsonProperty("systemMetric") SystemMetric systemMetric,
     this.consumerMetric = consumerMetric;
     this.producerMetric = producerMetric;
   }
+
+  public Map<String, Number> toMap() {
+    Map<String, Number> metrics = new HashMap<>();
+    metrics.putAll(systemMetric.toMap());
+    metrics.putAll(consumerMetric.toMap());
+    metrics.putAll(producerMetric.toMap());
+    return metrics;
+  }
 }
diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/MetricsPublisher.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/MetricsPublisher.java
index 5e66a10ea..c2c2be5b5 100644
--- a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/MetricsPublisher.java
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/MetricsPublisher.java
@@ -55,5 +55,5 @@
    * @param windowTime getAppliedWindowTime() item
    * @return RegistryMetric
    */
-  RegistryMetric metricsWithWindowTimeIndex(long windowTime);
+  RegistryMetric metricsWithWindowTime(long windowTime);
 }
diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/ProducerInvocationMetric.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/ProducerInvocationMetric.java
index aced1c71e..511d792ac 100644
--- a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/ProducerInvocationMetric.java
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/ProducerInvocationMetric.java
@@ -71,10 +71,10 @@ public ProducerInvocationMetric(@JsonProperty("operationName") String operationN
   public ProducerInvocationMetric merge(ProducerInvocationMetric metric) {
     return new ProducerInvocationMetric(this.getOperationName(), this.getPrefix(),
         this.getWaitInQueue() + metric.getWaitInQueue(),
-        metric.getLifeTimeInQueue().merge(lifeTimeInQueue),
-        metric.getExecutionTime().merge(executionTime),
-        metric.getProducerLatency().merge(producerLatency),
-        metric.getProducerCall().merge(producerCall));
+        lifeTimeInQueue.merge(metric.getLifeTimeInQueue()),
+        executionTime.merge(metric.getExecutionTime()),
+        producerLatency.merge(metric.getProducerLatency()),
+        producerCall.merge(metric.getProducerCall()));
   }
 
   public Map<String, Number> toMap() {
diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/RegistryMetric.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/RegistryMetric.java
index 1dad927a2..29958ec20 100644
--- a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/RegistryMetric.java
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/RegistryMetric.java
@@ -57,7 +57,7 @@ public RegistryMetric(SystemMetric systemMetric,
 
     ConsumerInvocationMetric instanceConsumerInvocationMetric = new ConsumerInvocationMetric("instance",
         MetricsConst.INSTANCE_CONSUMER_PREFIX,
-        new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerLatency"),
+        new TimerMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerLatency"),
         new CallMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerCall"));
     ProducerInvocationMetric instanceProducerInvocationMetric = new ProducerInvocationMetric("instance",
         MetricsConst.INSTANCE_PRODUCER_PREFIX, 0,
@@ -80,9 +80,7 @@ public RegistryMetric(SystemMetric systemMetric,
 
   public Map<String, Number> toMap() {
     Map<String, Number> metrics = new HashMap<>();
-    metrics.putAll(instanceMetric.getSystemMetric().toMap());
-    metrics.putAll(instanceMetric.getConsumerMetric().toMap());
-    metrics.putAll(instanceMetric.getProducerMetric().toMap());
+    metrics.putAll(instanceMetric.toMap());
     for (ConsumerInvocationMetric metric : consumerMetrics.values()) {
       metrics.putAll(metric.toMap());
     }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultMetricsPublisher.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultMetricsPublisher.java
index e0311615d..1e313d064 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultMetricsPublisher.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultMetricsPublisher.java
@@ -60,7 +60,7 @@ public RegistryMetric metrics() {
   @RequestMapping(path = "/{windowTime}", method = RequestMethod.GET)
   @CrossOrigin
   @Override
-  public RegistryMetric metricsWithWindowTimeIndex(@PathVariable(name = "windowTime") long windowTime) {
+  public RegistryMetric metricsWithWindowTime(@PathVariable(name = "windowTime") long windowTime) {
     return dataSource.getRegistryMetric(windowTime);
   }
 }
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
index 7c6ced3df..6ae2a95bd 100644
--- a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
@@ -250,7 +250,7 @@ public void test() throws InterruptedException {
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTotal(), 1);
 
     Map<String, Number> metrics = model.toMap();
-    Assert.assertEquals(metrics.size(), 72);
+    Assert.assertEquals(96, metrics.size());
 
     Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getCpuLoad(), 1.0, 0);
     Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getCpuRunningThreads(), 2, 0);
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestPublisher.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestPublisher.java
index 4c6016734..a0921da4f 100644
--- a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestPublisher.java
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestPublisher.java
@@ -45,11 +45,11 @@ public void test() throws IOException {
 
     RegistryMetric registryMetric = publisher.metrics();
     Map<String, Number> metricsMap = registryMetric.toMap();
-    Assert.assertEquals(metricsMap.size(), 30);
+    Assert.assertEquals(35, metricsMap.size());
 
-    registryMetric = publisher.metricsWithWindowTimeIndex(1000);
+    registryMetric = publisher.metricsWithWindowTime(1000);
     metricsMap = registryMetric.toMap();
-    Assert.assertEquals(metricsMap.size(), 30);
+    Assert.assertEquals(35, metricsMap.size());
 
     List<Long> appliedWindowTime = publisher.getAppliedWindowTime();
     Assert.assertEquals(appliedWindowTime.size(), 3);
diff --git a/metrics/metrics-integration/metrics-prometheus/pom.xml b/metrics/metrics-integration/metrics-prometheus/pom.xml
new file mode 100644
index 000000000..70a1ff2ec
--- /dev/null
+++ b/metrics/metrics-integration/metrics-prometheus/pom.xml
@@ -0,0 +1,48 @@
+<?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>
+    <artifactId>metrics-integration</artifactId>
+    <groupId>io.servicecomb</groupId>
+    <version>0.6.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>metrics-prometheus</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>io.prometheus</groupId>
+      <artifactId>simpleclient</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.prometheus</groupId>
+      <artifactId>simpleclient_httpserver</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>io.servicecomb</groupId>
+      <artifactId>metrics-core</artifactId>
+    </dependency>
+
+  </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsCollector.java b/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsCollector.java
new file mode 100644
index 000000000..c6dd37ecb
--- /dev/null
+++ b/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsCollector.java
@@ -0,0 +1,77 @@
+/*
+ * 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 io.servicecomb.metrics.prometheus;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.Collector.MetricFamilySamples.Sample;
+import io.servicecomb.metrics.common.ConsumerInvocationMetric;
+import io.servicecomb.metrics.common.ProducerInvocationMetric;
+import io.servicecomb.metrics.common.RegistryMetric;
+import io.servicecomb.metrics.core.publish.DataSource;
+
+@Component
+public class MetricsCollector extends Collector implements Collector.Describable {
+
+  private final DataSource dataSource;
+
+  @Autowired
+  public MetricsCollector(DataSource dataSource) {
+    this.dataSource = dataSource;
+  }
+
+  @Override
+  public List<MetricFamilySamples> collect() {
+    return load();
+  }
+
+  @Override
+  public List<MetricFamilySamples> describe() {
+    return load();
+  }
+
+  private List<MetricFamilySamples> load() {
+    RegistryMetric registryMetric = dataSource.getRegistryMetric();
+    List<MetricFamilySamples> familySamples = new ArrayList<>();
+    familySamples.add(getFamilySamples("Instance Level", registryMetric.getInstanceMetric().toMap()));
+    for (Entry<String, ConsumerInvocationMetric> consumerMetric : registryMetric.getConsumerMetrics().entrySet()) {
+      familySamples
+          .add(getFamilySamples(consumerMetric.getKey() + " Consumer Side", consumerMetric.getValue().toMap()));
+    }
+    for (Entry<String, ProducerInvocationMetric> producerMetric : registryMetric.getProducerMetrics().entrySet()) {
+      familySamples
+          .add(getFamilySamples(producerMetric.getKey() + " Producer Side", producerMetric.getValue().toMap()));
+    }
+    return familySamples;
+  }
+
+  private MetricFamilySamples getFamilySamples(String name, Map<String, Number> metrics) {
+    List<Sample> samples = metrics.entrySet().stream().map((entry) ->
+        new Sample(entry.getKey().replace(".", "_"),
+            new ArrayList<>(), new ArrayList<>(), entry.getValue().doubleValue())).collect(Collectors.toList());
+    return new MetricFamilySamples(name, Type.UNTYPED, name + " Metrics", samples);
+  }
+}
diff --git a/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsPublisher.java b/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsPublisher.java
new file mode 100644
index 000000000..dc83a56f1
--- /dev/null
+++ b/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsPublisher.java
@@ -0,0 +1,52 @@
+/*
+ * 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 io.servicecomb.metrics.prometheus;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.netflix.config.DynamicPropertyFactory;
+
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.exporter.HTTPServer;
+import io.servicecomb.foundation.common.exceptions.ServiceCombException;
+
+@Component
+public class MetricsPublisher {
+  private static final String METRICS_PROMETHEUS_PORT = "servicecomb.metrics.prometheus.port";
+
+  private final MetricsCollector metricsCollector;
+
+  private final HTTPServer httpServer;
+
+  @Autowired
+  public MetricsPublisher(MetricsCollector metricsCollector) {
+    //prometheus default port allocation is here : https://github.com/prometheus/prometheus/wiki/Default-port-allocations
+    int publishPort = DynamicPropertyFactory.getInstance().getIntProperty(METRICS_PROMETHEUS_PORT, 9696).get();
+    this.metricsCollector = metricsCollector;
+    this.metricsCollector.register();
+    try {
+      this.httpServer = new HTTPServer(new InetSocketAddress(publishPort), CollectorRegistry.defaultRegistry, true);
+    } catch (IOException e) {
+      throw new ServiceCombException("create http publish server failed", e);
+    }
+  }
+}
diff --git a/metrics/metrics-integration/pom.xml b/metrics/metrics-integration/pom.xml
new file mode 100644
index 000000000..a59715247
--- /dev/null
+++ b/metrics/metrics-integration/pom.xml
@@ -0,0 +1,32 @@
+<?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>
+    <artifactId>metrics</artifactId>
+    <groupId>io.servicecomb</groupId>
+    <version>0.6.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>metrics-integration</artifactId>
+  <packaging>pom</packaging>
+
+</project>
\ No newline at end of file
diff --git a/metrics/pom.xml b/metrics/pom.xml
index 7331a3b0b..cd5adcc1e 100644
--- a/metrics/pom.xml
+++ b/metrics/pom.xml
@@ -34,5 +34,6 @@
     <module>metrics-common</module>
     <module>metrics-core</module>
     <module>metrics-extension</module>
+    <module>metrics-integration</module>
   </modules>
 </project>
\ No newline at end of file
diff --git a/samples/bmi/calculator/src/main/resources/microservice.yaml b/samples/bmi/calculator/src/main/resources/microservice.yaml
deleted file mode 100644
index a7a7a6b41..000000000
--- a/samples/bmi/calculator/src/main/resources/microservice.yaml
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-# all interconnected microservices must belong to an application wth the same ID
-APPLICATION_ID: bmi
-service_description:
-# name of the declaring microservice
-  name: calculator
-  version: 0.0.1
-cse:
-  service:
-    registry:
-      address: http://127.0.0.1:30100
-  rest:
-    address: 0.0.0.0:7777
-  handler:
-    chain:
-      Provider:
-        default: bizkeeper-provider
\ No newline at end of file
diff --git a/samples/metrics-write-file-sample/metrics-write-file-log4j-springboot/src/main/java/io/servicecomb/samples/mwf/ServiceApplication.java b/samples/metrics-write-file-sample/metrics-write-file-log4j-springboot/src/main/java/io/servicecomb/samples/mwf/ServiceApplication.java
deleted file mode 100644
index bfb4354db..000000000
--- a/samples/metrics-write-file-sample/metrics-write-file-log4j-springboot/src/main/java/io/servicecomb/samples/mwf/ServiceApplication.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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 io.servicecomb.samples.mwf;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-import io.servicecomb.springboot.starter.provider.EnableServiceComb;
-
-@SpringBootApplication
-@EnableServiceComb
-public class ServiceApplication {
-  public static void main(String[] args) {
-    SpringApplication.run(ServiceApplication.class, args);
-  }
-}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services