rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wlliqip...@apache.org
Subject [rocketmq-exporter] 21/43: Verify and Polish
Date Sun, 08 Mar 2020 13:16:41 GMT
This is an automated email from the ASF dual-hosted git repository.

wlliqipeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-exporter.git

commit d5cb07639156cd356bbfd78ac81e922595e668d1
Author: vongosling <vongosling@apache.org>
AuthorDate: Fri Jul 5 19:03:42 2019 +0800

    Verify and Polish
---
 README.md                                              |  4 ++--
 src/main/docker/Dockerfile                             |  4 ++--
 .../rocketmq/exporter/RocketMQExporterApplication.java |  2 --
 .../rocketmq/exporter/aspect/admin/MQAdminAspect.java  |  2 +-
 .../rocketmq/exporter/service/RMQMetricsService.java   |  4 ++--
 .../rocketmq/exporter/task/MetricsCollectTask.java     | 18 +++++++++---------
 .../org/apache/rocketmq/exporter/util/JsonUtil.java    |  2 +-
 .../rocketmq/exporter/util/{Mix.java => Utils.java}    | 10 +++++-----
 src/main/resources/application.properties              |  2 +-
 9 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/README.md b/README.md
index 5313655..2d116dc 100644
--- a/README.md
+++ b/README.md
@@ -52,13 +52,13 @@ Run
 ### Run Binary
 
 ```shell
-java -jar rocketmq-exporter-0.0.1-SNAPSHOT.jar [--rocketmq.config.namesrvAddr="127.0.0.1:9876"
...]
+java -jar rocketmq-exporter-0.0.1-SNAPSHOT.jar
 ```
 
 ### Run Docker Image
 
 ```
-docker container run -itd --rm  -p 5557:5557  breezecoolyang/rocketmq-exporter [--rocketmq.config.namesrvAddr="127.0.0.1:9876"
...]
+docker container run -itd --rm  -p 5557:5557  docker.io/rocketmq-exporter
 ```
 
 Flags
diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile
index 27f209c..cae410d 100644
--- a/src/main/docker/Dockerfile
+++ b/src/main/docker/Dockerfile
@@ -1,5 +1,5 @@
 FROM java:8
 MAINTAINER breeze
-ADD rocketmq-exporter-0.0.1-SNAPSHOT.jar demo.jar
+ADD rocketmq-exporter-0.0.1-SNAPSHOT.jar quickstart.jar
 EXPOSE 5557
-ENTRYPOINT ["java","-jar","demo.jar"]
+ENTRYPOINT ["java","-jar","quickstart.jar"]
diff --git a/src/main/java/org/apache/rocketmq/exporter/RocketMQExporterApplication.java b/src/main/java/org/apache/rocketmq/exporter/RocketMQExporterApplication.java
index 0866aef..05c5654 100644
--- a/src/main/java/org/apache/rocketmq/exporter/RocketMQExporterApplication.java
+++ b/src/main/java/org/apache/rocketmq/exporter/RocketMQExporterApplication.java
@@ -17,12 +17,10 @@
 package org.apache.rocketmq.exporter;
 
 import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
-@EnableAutoConfiguration
 @SpringBootApplication
 @ServletComponentScan
 @EnableScheduling
diff --git a/src/main/java/org/apache/rocketmq/exporter/aspect/admin/MQAdminAspect.java b/src/main/java/org/apache/rocketmq/exporter/aspect/admin/MQAdminAspect.java
index bc3c38e..6b5435f 100644
--- a/src/main/java/org/apache/rocketmq/exporter/aspect/admin/MQAdminAspect.java
+++ b/src/main/java/org/apache/rocketmq/exporter/aspect/admin/MQAdminAspect.java
@@ -49,7 +49,7 @@ public class MQAdminAspect {
     @Around(value = "mQAdminMethodPointCut() || multiMQAdminMethodPointCut()")
     public Object aroundMQAdminMethod(ProceedingJoinPoint joinPoint) throws Throwable {
         long start = System.currentTimeMillis();
-        Object obj = null;
+        Object obj;
         try {
             MethodSignature signature = (MethodSignature)joinPoint.getSignature();
             Method method = signature.getMethod();
diff --git a/src/main/java/org/apache/rocketmq/exporter/service/RMQMetricsService.java b/src/main/java/org/apache/rocketmq/exporter/service/RMQMetricsService.java
index 3b2e403..c1f8802 100644
--- a/src/main/java/org/apache/rocketmq/exporter/service/RMQMetricsService.java
+++ b/src/main/java/org/apache/rocketmq/exporter/service/RMQMetricsService.java
@@ -24,6 +24,6 @@ import java.io.StringWriter;
 
 
 public interface RMQMetricsService  {
-    public RMQMetricsCollector getCollector();
-    public void Metrics(StringWriter writer) throws IOException;
+    RMQMetricsCollector getCollector();
+    void Metrics(StringWriter writer) throws IOException;
 }
diff --git a/src/main/java/org/apache/rocketmq/exporter/task/MetricsCollectTask.java b/src/main/java/org/apache/rocketmq/exporter/task/MetricsCollectTask.java
index 7797d2a..c6e6a5e 100644
--- a/src/main/java/org/apache/rocketmq/exporter/task/MetricsCollectTask.java
+++ b/src/main/java/org/apache/rocketmq/exporter/task/MetricsCollectTask.java
@@ -35,7 +35,7 @@ import org.apache.rocketmq.exporter.aspect.admin.annotation.MultiMQAdminCmdMetho
 import org.apache.rocketmq.exporter.config.RMQConfigure;
 import org.apache.rocketmq.exporter.service.RMQMetricsService;
 import org.apache.rocketmq.exporter.service.client.MQAdminExtImpl;
-import org.apache.rocketmq.exporter.util.Mix;
+import org.apache.rocketmq.exporter.util.Utils;
 import org.apache.rocketmq.store.stats.BrokerStatsManager;
 import org.apache.rocketmq.tools.admin.MQAdminExt;
 import org.slf4j.Logger;
@@ -159,14 +159,14 @@ public class MetricsCollectTask {
                             BrokerStatsData bsd = null;
                             try {
                                 bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS,
topic);
-                                metricsService.getCollector().AddTopicPutNumsMetric(bd.getCluster(),
bd.getBrokerName(), topic, Mix.getFixedDouble(bsd.getStatsMinute().getTps()));
+                                metricsService.getCollector().AddTopicPutNumsMetric(bd.getCluster(),
bd.getBrokerName(), topic, Utils.getFixedDouble(bsd.getStatsMinute().getTps()));
                             }
                             catch (Exception e) {
                                 log.info("error is " + e.getMessage());
                             }
                             try {
                                 bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_SIZE,
topic);
-                                metricsService.getCollector().AddTopicPutSizeMetric(bd.getCluster(),
bd.getBrokerName(), topic, Mix.getFixedDouble(bsd.getStatsMinute().getTps()));
+                                metricsService.getCollector().AddTopicPutSizeMetric(bd.getCluster(),
bd.getBrokerName(), topic, Utils.getFixedDouble(bsd.getStatsMinute().getTps()));
                             }
                             catch (Exception e) {
                                 log.info("error is " + e.getMessage());
@@ -186,20 +186,20 @@ public class MetricsCollectTask {
                                     BrokerStatsData bsd = null;
                                     try {
                                         bsd = mqAdminExt.viewBrokerStatsData(masterAddr,
BrokerStatsManager.GROUP_GET_NUMS, statsKey);
-                                        metricsService.getCollector().AddGroupGetNumsMetric(bd.getCluster(),
bd.getBrokerName(), topic, group, Mix.getFixedDouble(bsd.getStatsMinute().getTps()));
+                                        metricsService.getCollector().AddGroupGetNumsMetric(bd.getCluster(),
bd.getBrokerName(), topic, group, Utils.getFixedDouble(bsd.getStatsMinute().getTps()));
                                     } catch (Exception e) {
                                         log.info("error is " + e.getMessage());
                                     }
                                     try {
                                         bsd = mqAdminExt.viewBrokerStatsData(masterAddr,
BrokerStatsManager.GROUP_GET_SIZE, statsKey);
-                                        metricsService.getCollector().AddGroupGetSizeMetric(bd.getCluster(),
bd.getBrokerName(), topic, group, Mix.getFixedDouble(bsd.getStatsMinute().getTps()));
+                                        metricsService.getCollector().AddGroupGetSizeMetric(bd.getCluster(),
bd.getBrokerName(), topic, group, Utils.getFixedDouble(bsd.getStatsMinute().getTps()));
                                     } catch (Exception e) {
                                         log.info("error is " + e.getMessage());
                                     }
                                     try {
 
                                         bsd = mqAdminExt.viewBrokerStatsData(masterAddr,
BrokerStatsManager.SNDBCK_PUT_NUMS, statsKey);
-                                        metricsService.getCollector().AddsendBackNumsMetric(bd.getCluster(),
bd.getBrokerName(), topic, group, Mix.getFixedDouble(bsd.getStatsMinute().getTps()));
+                                        metricsService.getCollector().AddsendBackNumsMetric(bd.getCluster(),
bd.getBrokerName(), topic, group, Utils.getFixedDouble(bsd.getStatsMinute().getTps()));
                                     } catch (Exception e) {
                                         log.info("error is " + e.getMessage());
                                     }
@@ -239,14 +239,14 @@ public class MetricsCollectTask {
                         BrokerStatsData bsd = null;
                         try {
                             bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.BROKER_PUT_NUMS,clusterEntry.getValue().getCluster());
-                            metricsService.getCollector().AddBrokerPutNumsMetric(clusterEntry.getValue().getCluster(),
clusterEntry.getValue().getBrokerName(), Mix.getFixedDouble(bsd.getStatsMinute().getTps()));
+                            metricsService.getCollector().AddBrokerPutNumsMetric(clusterEntry.getValue().getCluster(),
clusterEntry.getValue().getBrokerName(), Utils.getFixedDouble(bsd.getStatsMinute().getTps()));
                         }
                         catch (Exception e) {
                             log.info("error is " + e.getMessage());
                         }
                         try {
                             bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.BROKER_GET_NUMS,
clusterEntry.getValue().getCluster());
-                            metricsService.getCollector().AddBrokerGetNumsMetric(clusterEntry.getValue().getCluster(),
clusterEntry.getValue().getBrokerName(), Mix.getFixedDouble(bsd.getStatsMinute().getTps()));
+                            metricsService.getCollector().AddBrokerGetNumsMetric(clusterEntry.getValue().getCluster(),
clusterEntry.getValue().getBrokerName(), Utils.getFixedDouble(bsd.getStatsMinute().getTps()));
                         }
                         catch (Exception e) {
                             log.info("error is " + e.getMessage());
@@ -274,7 +274,7 @@ public class MetricsCollectTask {
             statsKey = String.format("%d@%s@%s", queueId, topic, group);
             try {
                 bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_LATENCY,
statsKey);
-                metricsService.getCollector().AddGroupGetLatencyMetric(bd.getCluster(), bd.getBrokerName(),
topic, group, String.format("%d", queueId), Mix.getFixedDouble(bsd.getStatsMinute().getTps()));
+                metricsService.getCollector().AddGroupGetLatencyMetric(bd.getCluster(), bd.getBrokerName(),
topic, group, String.format("%d", queueId), Utils.getFixedDouble(bsd.getStatsMinute().getTps()));
             } catch (Exception e) {
                 log.info("error is " + e.getMessage());
             }
diff --git a/src/main/java/org/apache/rocketmq/exporter/util/JsonUtil.java b/src/main/java/org/apache/rocketmq/exporter/util/JsonUtil.java
index a80e998..29317f9 100644
--- a/src/main/java/org/apache/rocketmq/exporter/util/JsonUtil.java
+++ b/src/main/java/org/apache/rocketmq/exporter/util/JsonUtil.java
@@ -47,7 +47,7 @@ public class JsonUtil {
         objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
         objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
         objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
-        objectMapper.setFilters(new SimpleFilterProvider().setFailOnUnknownId(false));
+        objectMapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
         objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
     }
diff --git a/src/main/java/org/apache/rocketmq/exporter/util/Mix.java b/src/main/java/org/apache/rocketmq/exporter/util/Utils.java
similarity index 83%
rename from src/main/java/org/apache/rocketmq/exporter/util/Mix.java
rename to src/main/java/org/apache/rocketmq/exporter/util/Utils.java
index 469be71..ccdcabe 100644
--- a/src/main/java/org/apache/rocketmq/exporter/util/Mix.java
+++ b/src/main/java/org/apache/rocketmq/exporter/util/Utils.java
@@ -17,11 +17,11 @@
 
 package org.apache.rocketmq.exporter.util;
 
-public class Mix {
+import java.text.DecimalFormat;
+
+public class Utils {
     public static double getFixedDouble(double value) {
-        if (value >= 1) {
-            return Math.round(value);
-        }
-        return Math.round(value * 100) / 100.0;
+        DecimalFormat df = new DecimalFormat("#.##");
+        return new Double(df.format(value));
     }
 }
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index ad1d563..083738e 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -6,7 +6,7 @@ spring.http.encoding.enabled=true
 spring.http.encoding.force=true
 logging.config=classpath:logback.xml
 #if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR
-rocketmq.config.namesrvAddr=192.168.0.48:9876
+rocketmq.config.namesrvAddr=127.0.0.1:9876
 
 
 rocketmq.config.enableCollect=true


Mime
View raw message