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

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


The following commit(s) were added to refs/heads/master by this push:
     new aa4d28bf3 [Refactor] Preventing Unnecessary Object Creation and Using 
Utility Methods (#1818)
aa4d28bf3 is described below

commit aa4d28bf34b38bae8b097324d2402f656c14e7c7
Author: Hyeon Sung <[email protected]>
AuthorDate: Wed Apr 24 01:36:17 2024 +0900

    [Refactor] Preventing Unnecessary Object Creation and Using Utility Methods 
(#1818)
    
    Co-authored-by: Logic <[email protected]>
---
 .../collect/database/JdbcCommonCollect.java        |  2 +-
 .../collector/collect/dns/DnsCollectImpl.java      |  6 ++-
 .../collector/collect/http/HttpCollectImpl.java    | 29 +++++++------
 .../collect/http/SslCertificateCollectImpl.java    | 11 +++--
 .../http/promethus/AbstractPrometheusParse.java    | 12 +++---
 .../http/promethus/exporter/ExporterParser.java    | 49 +++++++++++-----------
 .../http/promethus/exporter/MetricFamily.java      |  9 ++--
 .../http/promethus/exporter/MetricType.java        |  4 +-
 .../collector/collect/nginx/NginxCollectImpl.java  | 41 +++++++++---------
 .../collect/redis/RedisCommonCollectImpl.java      |  2 +-
 10 files changed, 84 insertions(+), 81 deletions(-)

diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/database/JdbcCommonCollect.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/database/JdbcCommonCollect.java
index e8ae11cc4..6d25fbdbb 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/database/JdbcCommonCollect.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/database/JdbcCommonCollect.java
@@ -94,7 +94,7 @@ public class JdbcCommonCollect extends AbstractCollect {
         } catch (PSQLException psqlException) {
             // for PostgreSQL 08001
             if 
(CollectorConstants.POSTGRESQL_UN_REACHABLE_CODE.equals(psqlException.getSQLState()))
 {
-                // 对端链接失败 不可达
+                // Peer connection failed, unreachable
                 builder.setCode(CollectRep.Code.UN_REACHABLE);
             } else {
                 builder.setCode(CollectRep.Code.FAIL);
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/dns/DnsCollectImpl.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/dns/DnsCollectImpl.java
index 138720c9e..58cb70409 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/dns/DnsCollectImpl.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/dns/DnsCollectImpl.java
@@ -31,6 +31,7 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.hertzbeat.collector.collect.AbstractCollect;
 import org.apache.hertzbeat.collector.dispatch.DispatchConstants;
@@ -164,7 +165,7 @@ public class DnsCollectImpl extends AbstractCollect {
 
         Message response = res.send(query);
         responseTimeStopWatch.stop();
-        return resolve(response, 
responseTimeStopWatch.getLastTaskTimeMillis());
+        return resolve(response, 
responseTimeStopWatch.lastTaskInfo().getTimeMillis());
     }
 
     private DnsResolveResult resolve(Message message, Long responseTime) {
@@ -193,7 +194,8 @@ public class DnsCollectImpl extends AbstractCollect {
 
     private List<String> getSectionInfo(Message message, int section) {
         List<RRset> currentSetList = message.getSectionRRsets(section);
-        if (currentSetList == null || currentSetList.size() <= 0) {
+        
+        if (CollectionUtils.isEmpty(currentSetList)) {
             return Lists.newArrayList();
         }
 
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java
index db44abeab..62f39fa22 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java
@@ -121,10 +121,12 @@ public class HttpCollectImpl extends AbstractCollect {
                 builder.setMsg("StatusCode " + statusCode);
                 return;
             }
-            // todo 这里直接将InputStream转为了String, 对于prometheus exporter大数据来说, 
会生成大对象, 可能会严重影响JVM内存空间
-            // todo 方法一、使用InputStream进行解析, 代码改动大; 方法二、手动触发gc, 可以参考dubbo for 
long i
+            // todo This code converts an InputStream directly to a String. 
For large data in Prometheus exporters,
+            // this could create large objects, potentially impacting JVM 
memory space significantly.
+            // Option 1: Parse using InputStream, but this requires 
significant code changes; 
+            // Option 2: Manually trigger garbage collection, similar to how 
it's done in Dubbo for large inputs.
             String resp = EntityUtils.toString(response.getEntity(), 
StandardCharsets.UTF_8);
-            if (resp == null || "".equals(resp)) {
+            if (StringUtils.hasText(resp)) {
                 log.info("http response entity is empty, status: {}.", 
statusCode);
             }
             Long responseTime = System.currentTimeMillis() - startTime;
@@ -193,11 +195,12 @@ public class HttpCollectImpl extends AbstractCollect {
         if (metrics == null || metrics.getHttp() == null) {
             throw new Exception("Http/Https collect must has http params");
         }
+        
         HttpProtocol httpProtocol = metrics.getHttp();
-        if (httpProtocol.getUrl() == null
-                    || "".equals(httpProtocol.getUrl())
-                    || !httpProtocol.getUrl().startsWith(RIGHT_DASH)) {
-            httpProtocol.setUrl(httpProtocol.getUrl() == null ? RIGHT_DASH : 
RIGHT_DASH + httpProtocol.getUrl().trim());
+        String url = httpProtocol.getUrl();
+        
+        if (StringUtils.hasText(url) || !url.startsWith(RIGHT_DASH)) {
+            httpProtocol.setUrl(url == null ? RIGHT_DASH : RIGHT_DASH + 
url.trim());
         }
         
         if (CollectionUtils.isEmpty(httpProtocol.getSuccessCodes())) {
@@ -235,9 +238,9 @@ public class HttpCollectImpl extends AbstractCollect {
                 NodeList childNodes = urlNode.getChildNodes();
                 for (int k = 0; k < childNodes.getLength(); k++) {
                     Node currentNode = childNodes.item(k);
-                    // 区分出text类型的node以及element类型的node
+                    // distinguish between text nodes and element nodes
                     if (currentNode.getNodeType() == Node.ELEMENT_NODE && 
"loc".equals(currentNode.getNodeName())) {
-                        //获取了loc节点的值
+                        // retrieves the value of the loc node
                         
siteUrls.add(currentNode.getFirstChild().getNodeValue());
                         break;
                     }
@@ -247,11 +250,11 @@ public class HttpCollectImpl extends AbstractCollect {
             log.warn(e.getMessage());
             isXmlFormat = false;
         }
-        // 若xml解析失败 用txt格式解析
+        // if XML parsing fails, parse in TXT format
         if (!isXmlFormat) {
             try {
                 String[] urls = resp.split("\n");
-                // 校验是否是URL
+                // validate whether the given value is a URL
                 if (IpDomainUtil.isHasSchema(urls[0])) {
                     siteUrls.addAll(Arrays.asList(urls));
                 }
@@ -259,7 +262,7 @@ public class HttpCollectImpl extends AbstractCollect {
                 log.warn(e.getMessage(), e);
             }
         }
-        // 开始循环访问每个site url 采集其 http status code, responseTime, 异常信息
+        // start looping through each site URL to collect its HTTP status 
code, response time, and exception information
         for (String siteUrl : siteUrls) {
             String errorMsg = "";
             Integer statusCode = null;
@@ -314,7 +317,7 @@ public class HttpCollectImpl extends AbstractCollect {
         int keywordNum = CollectUtil.countMatchKeyword(resp, 
http.getKeyword());
         for (int i = 0; i < results.size(); i++) {
             Object objectValue = results.get(i);
-            // 监控目标版本问题可能出现属性不存在,为空时过滤。参考app-elasticsearch.yml的name: nodes
+            // if a property is missing or empty due to target version issues, 
filter it. Refer to the app-elasticsearch.yml configuration under name: nodes
             if (objectValue == null) {
                 continue;
             }
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/SslCertificateCollectImpl.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/SslCertificateCollectImpl.java
index 4e3340d21..561c76353 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/SslCertificateCollectImpl.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/SslCertificateCollectImpl.java
@@ -39,7 +39,7 @@ import 
org.apache.hertzbeat.common.entity.job.protocol.HttpProtocol;
 import org.apache.hertzbeat.common.entity.message.CollectRep;
 import org.apache.hertzbeat.common.util.CommonUtil;
 import org.apache.hertzbeat.common.util.IpDomainUtil;
-
+import org.springframework.util.StringUtils;
 
 /**
  * ssl Certificate
@@ -96,7 +96,7 @@ public class SslCertificateCollectImpl extends 
AbstractCollect {
                     if 
(CollectorConstants.RESPONSE_TIME.equalsIgnoreCase(alias)) {
                         
valueRowBuilder.addColumns(Long.toString(responseTime));
                     } else if (NAME_SUBJECT.equalsIgnoreCase(alias)) {
-                        
valueRowBuilder.addColumns(x509Certificate.getSubjectDN().getName());
+                        
valueRowBuilder.addColumns(x509Certificate.getSubjectX500Principal().getName());
                     } else if (NAME_EXPIRED.equalsIgnoreCase(alias)) {
                         valueRowBuilder.addColumns(Boolean.toString(expired));
                     } else if (NAME_START_TIME.equalsIgnoreCase(alias)) {
@@ -158,10 +158,9 @@ public class SslCertificateCollectImpl extends 
AbstractCollect {
             throw new Exception("Http/Https collect must has http params");
         }
         HttpProtocol httpProtocol = metrics.getHttp();
-        if (httpProtocol.getUrl() == null
-                || "".equals(httpProtocol.getUrl())
-                || !httpProtocol.getUrl().startsWith(RIGHT_DASH)) {
-            httpProtocol.setUrl(httpProtocol.getUrl() == null ? RIGHT_DASH : 
RIGHT_DASH + httpProtocol.getUrl().trim());
+        String url = httpProtocol.getUrl();
+        if (StringUtils.hasText(url) || !url.startsWith(RIGHT_DASH)) {
+            httpProtocol.setUrl(url == null ? RIGHT_DASH : RIGHT_DASH + 
url.trim());
         }
     }
 }
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/AbstractPrometheusParse.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/AbstractPrometheusParse.java
index d2417aff5..2195ac2ef 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/AbstractPrometheusParse.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/AbstractPrometheusParse.java
@@ -23,7 +23,7 @@ import org.apache.hertzbeat.common.entity.message.CollectRep;
 
 /**
  * prometheus parse abstract class
- * todo: string类型 和 scalar类型 响应格式解析
+ * todo: parse response formats for string and scalar types
  */
 public abstract class AbstractPrometheusParse {
 
@@ -41,16 +41,16 @@ public abstract class AbstractPrometheusParse {
     }
 
     /**
-     * prom response type check: string, matrix, vector, scalar
-     * todo:string、scalar类型响应未实现
-     * @param responseStr 返回字符串
-     * @return return
+     * checks the Prometheus response type: string, matrix, vector, scalar
+     * todo:implementation for string and scalar types is missing
+     * @param responseStr The returned string
+     * @return boolean indicating the result
      */
     abstract Boolean checkType(String responseStr);
 
     /**
      * Parse the prom interface response data
-     * @param resp 返回数据
+     * @param resp The returned data
      * @param aliasFields alias fields
      * @param http httpProtocol
      * @param builder builder
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/ExporterParser.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/ExporterParser.java
index 33ddab46e..9a1a21402 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/ExporterParser.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/ExporterParser.java
@@ -142,8 +142,9 @@ public class ExporterParser {
             metricList = new ArrayList<>();
             this.currentMetricFamily.setMetricList(metricList);
         }
-        // todo 这里可能存在问题, 目前逻辑是HISTOGRAM和SUMMARY只创建一个metric
-        //  相比源码有所改动: 源码通过属性存储解析结果; 这边通过参数传递
+        // TODO: This part may have issues. The current logic creates only one 
metric for both HISTOGRAM and SUMMARY
+        // compared to the source code, there is a slight modification: the 
source code stores parsing results in a property
+        // here, the results are passed through parameters.
         MetricFamily.Metric metric;
         if (!metricList.isEmpty()
                 && 
(this.currentMetricFamily.getMetricType().equals(MetricType.HISTOGRAM)
@@ -249,15 +250,15 @@ public class ExporterParser {
                     summary = new MetricFamily.Summary();
                     metric.setSummary(summary);
                 }
-                // 处理 xxx_sum 的数据
+                // Process data for xxx_sum
                 if (label != null && this.isSum(label.getName())) {
                     summary.setSum(buffer.toDouble());
                 }
-                // 处理 xxx_count 的数据
+                // Process data for xxx_count
                 else if (label != null && this.isCount(label.getName())) {
                     summary.setCount(buffer.toLong());
                 }
-                // 处理 "xxx{quantile=\"0\"} 0" 的格式
+                // Handle format for "xxx{quantile=\"0\"} 0"
                 else if (StringUtils.hasText(this.currentQuantile)) {
                     List<MetricFamily.Quantile> quantileList = 
summary.getQuantileList();
                     MetricFamily.Quantile quantile = new 
MetricFamily.Quantile();
@@ -277,7 +278,7 @@ public class ExporterParser {
                 } else if (label != null && this.isCount(label.getName())) {
                     histogram.setCount(buffer.toLong());
                 }
-                // 处理 "xxx{quantile=\"0\"} 0" 的格式
+                // Process the format "xxx{quantile=\"0\"} 0"
                 else if (StringUtils.hasText(this.currentBucket)) {
                     List<MetricFamily.Bucket> bucketList = 
histogram.getBucketList();
                     MetricFamily.Bucket bucket = new MetricFamily.Bucket();
@@ -291,9 +292,9 @@ public class ExporterParser {
     }
 
     /**
-     * 读取第一个空格符前的token
+     * Reads the token before the first whitespace
      *
-     * @param buffer 行数据对象
+     * @param buffer A line data object
      * @return token unit
      */
     private String readTokenUnitWhitespace(StrBuffer buffer) {
@@ -309,9 +310,9 @@ public class ExporterParser {
     }
 
     /**
-     * 获取指标的名称
+     * Gets the name of the metric
      *
-     * @param buffer 行数据对象
+     * @param buffer A line data object
      * @return token name
      */
     private String readTokenAsMetricName(StrBuffer buffer) {
@@ -332,9 +333,9 @@ public class ExporterParser {
     }
 
     /**
-     * 获取label的名称
+     * Gets the name of the label
      *
-     * @param buffer 行数据对象
+     * @param buffer A line data object
      * @return label name
      */
     private String readTokenAsLabelName(StrBuffer buffer) {
@@ -357,9 +358,9 @@ public class ExporterParser {
     }
 
     /**
-     * 获取Label的值
+     * Gets the value of the label
      *
-     * @param buffer 行数据对象
+     * @param buffer A line data object
      * @return label value
      */
     private String readTokenAsLabelValue(StrBuffer buffer) {
@@ -367,7 +368,7 @@ public class ExporterParser {
         boolean escaped = false;
         while (!buffer.isEmpty()) {
             char c = buffer.read();
-            // 处理 '\\' 转义
+            // Handle '\\' escape sequences
             if (escaped) {
                 switch (c) {
                     case QUOTES, '\\' -> builder.append(c);
@@ -393,9 +394,9 @@ public class ExporterParser {
     }
 
     /**
-     * 是否符合metric name首字符规则
+     * Checks whether a character conforms to the first character rule for 
metric names
      *
-     * @param c metric字符
+     * @param c metric character
      * @return true/false
      */
     private boolean isValidMetricNameStart(char c) {
@@ -403,9 +404,9 @@ public class ExporterParser {
     }
 
     /**
-     * 是否符合metric name除首字符其他字符规则
+     * Checks whether a character conforms to rules for metric name characters 
other than the first
      *
-     * @param c metric字符
+     * @param c metric character
      * @return true/false
      */
     private boolean isValidMetricNameContinuation(char c) {
@@ -413,9 +414,9 @@ public class ExporterParser {
     }
 
     /**
-     * 是否符合label name首字符规则
+     * Checks whether a character conforms to the first character rule for 
label names
      *
-     * @param c metric字符
+     * @param c metric character
      * @return true/false
      */
     private boolean isValidLabelNameStart(char c) {
@@ -423,9 +424,9 @@ public class ExporterParser {
     }
 
     /**
-     * 是否符合label name除首字符其他字符规则
+     * Checks whether a character conforms to rules for label name characters 
other than the first
      *
-     * @param c metric字符
+     * @param c metric character
      * @return true/false
      */
     private boolean isValidLabelNameContinuation(char c) {
@@ -433,7 +434,7 @@ public class ExporterParser {
     }
 
     /**
-     * 检测是否是有效的utf8编码的字符串
+     * Checks if a string is a valid UTF-8 encoded string
      *
      * @param s label value
      * @return true/false
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/MetricFamily.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/MetricFamily.java
index e1b90ad35..447996d88 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/MetricFamily.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/MetricFamily.java
@@ -29,25 +29,22 @@ import lombok.ToString;
 @ToString
 public class MetricFamily {
     /**
-     * 指标名称
      * metric name
      */
     private String name;
 
     /**
-     * 指标描述
      * metric help
      */
     private String help;
 
     /**
-     * 指标类型
      * metric type
      */
     private MetricType metricType;
 
     /**
-     * 具体的指标
+     * Specific metric
      */
     private List<Metric> metricList;
 
@@ -58,7 +55,7 @@ public class MetricFamily {
     public static class Metric {
 
         /**
-         * 标签数据, 主要对应{}内容
+         * Label data, mainly corresponding to the content within {}
          */
         private List<Label> labelPair;
 
@@ -194,7 +191,7 @@ public class MetricFamily {
     @Data
     public static class Quantile {
         /**
-         * 对应 prometheus 的 quantile 字段
+         * Corresponding to the quantile field in Prometheus
          */
         private double xLabel;
 
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/MetricType.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/MetricType.java
index 91ab39e69..44d36367e 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/MetricType.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/exporter/MetricType.java
@@ -23,9 +23,9 @@ package 
org.apache.hertzbeat.collector.collect.http.promethus.exporter;
 public enum MetricType {
     // for string metric info
     INFO("info"),
-    // 代表单调递增的计数器, 例: 统计次数
+    // Represents a monotonically increasing counter, e.g., counting 
occurrences
     COUNTER("counter"),
-    // 任意上下波动的指标类型, 例: CPU的使用率
+    // A metric type that can fluctuate up and down, e.g., CPU usage rate
     GAUGE("gauge"),
     SUMMARY("summary"),
     UNTYPED("untyped"),
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/nginx/NginxCollectImpl.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/nginx/NginxCollectImpl.java
index 2704c59df..5a3935a3b 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/nginx/NginxCollectImpl.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/nginx/NginxCollectImpl.java
@@ -54,6 +54,7 @@ import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.EntityUtils;
 
+
 /**
  * nginx collect
  */
@@ -83,7 +84,7 @@ public class NginxCollectImpl extends AbstractCollect {
     public void collect(CollectRep.MetricsData.Builder builder, long 
monitorId, String app, Metrics metrics) {
         long startTime = System.currentTimeMillis();
 
-        // 校验参数
+        // validate parameters
         try {
             validateParams(metrics);
         } catch (Exception e) {
@@ -95,7 +96,7 @@ public class NginxCollectImpl extends AbstractCollect {
         HttpContext httpContext = createHttpContext(metrics.getNginx());
         HttpUriRequest request = createHttpRequest(metrics.getNginx());
         try (CloseableHttpResponse response = 
CommonHttpClient.getHttpClient().execute(request, httpContext)){
-            // 发起http请求,获取响应数据
+            // send an HTTP request and get the response data
             int statusCode = response.getStatusLine().getStatusCode();
             if (statusCode != SUCCESS_CODE) {
                 builder.setCode(CollectRep.Code.FAIL);
@@ -105,8 +106,8 @@ public class NginxCollectImpl extends AbstractCollect {
             String resp = EntityUtils.toString(response.getEntity(), 
StandardCharsets.UTF_8);
 
             Long responseTime = System.currentTimeMillis() - startTime;
-            // 根据metrics name选择调用不同解析方法
-            if (NGINX_STATUS_NAME.equals(metrics.getName()) || 
AVAILABLE.equals(metrics.getName())) {
+            // call different parsing methods based on the metrics name
+            if (StringUtils.equalsAny(metrics.getName(), NGINX_STATUS_NAME, 
AVAILABLE)) {
                 parseNginxStatusResponse(builder, resp, metrics, responseTime);
             } else if (REQ_STATUS_NAME.equals(metrics.getName())) {
                 parseReqStatusResponse(builder, resp, metrics, responseTime);
@@ -131,15 +132,15 @@ public class NginxCollectImpl extends AbstractCollect {
 
     private void validateParams(Metrics metrics) throws Exception {
         final NginxProtocol nginxProtocol;
-
+        
         if (metrics == null || (nginxProtocol = metrics.getNginx()) == null || 
nginxProtocol.isInValid()) {
             throw new Exception("Nginx collect must has nginx params");
         }
-
-        if (nginxProtocol.getUrl() == null
-                || nginxProtocol.getUrl().isEmpty()
-                || !nginxProtocol.getUrl().startsWith(RIGHT_DASH)) {
-            nginxProtocol.setUrl(nginxProtocol.getUrl() == null ? RIGHT_DASH : 
RIGHT_DASH + nginxProtocol.getUrl().trim());
+        
+        String url = nginxProtocol.getUrl();
+        
+        if (StringUtils.isEmpty(url) || !url.startsWith(RIGHT_DASH)) {
+            nginxProtocol.setUrl(url == null ? RIGHT_DASH : RIGHT_DASH + 
url.trim());
         }
     }
 
@@ -152,22 +153,22 @@ public class NginxCollectImpl extends AbstractCollect {
 
     private HttpUriRequest createHttpRequest(NginxProtocol nginxProtocol) {
         RequestBuilder requestBuilder = RequestBuilder.get();
-        // uri
-        String uri = CollectUtil.replaceUriSpecialChar(nginxProtocol.getUrl());
-        if (IpDomainUtil.isHasSchema(nginxProtocol.getHost())) {
-            requestBuilder.setUri(nginxProtocol.getHost() + ":" + 
nginxProtocol.getPort() + uri);
+        String portWithUri = nginxProtocol.getPort() + 
CollectUtil.replaceUriSpecialChar(nginxProtocol.getUrl());
+        String host = nginxProtocol.getHost();
+        
+        if (IpDomainUtil.isHasSchema(host)) {
+            requestBuilder.setUri(host + ":" + portWithUri);
         } else {
-            String ipAddressType = 
IpDomainUtil.checkIpAddressType(nginxProtocol.getHost());
+            String ipAddressType = IpDomainUtil.checkIpAddressType(host);
             String baseUri = CollectorConstants.IPV6.equals(ipAddressType)
-                    ? String.format("[%s]:%s", nginxProtocol.getHost(), 
nginxProtocol.getPort() + uri)
-                    : String.format("%s:%s", nginxProtocol.getHost(), 
nginxProtocol.getPort() + uri);
+                    ? String.format("[%s]:%s", host, portWithUri)
+                    : String.format("%s:%s", host, portWithUri);
 
             requestBuilder.setUri(CollectorConstants.HTTP_HEADER + baseUri);
         }
 
         requestBuilder.addHeader(HttpHeaders.CONNECTION, "keep-alive");
         requestBuilder.addHeader(HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows 
NT 6.1; WOW64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 
Safari/537.36");
-
         requestBuilder.addHeader(HttpHeaders.ACCEPT, "text/plain");
 
         int timeout = Integer.parseInt(nginxProtocol.getTimeout());
@@ -183,7 +184,7 @@ public class NginxCollectImpl extends AbstractCollect {
     }
 
     /**
-     * 解析nginx自带ngx_http_stub_status_module模块暴露信息
+     * analyze the information exposed by nginx's built-in 
ngx_http_stub_status_module
      *
      * @param builder builder
      * @param resp resp
@@ -199,7 +200,7 @@ public class NginxCollectImpl extends AbstractCollect {
         //Reading: 0 Writing: 1 Waiting: 1
         List<String> aliasFields = metrics.getAliasFields();
         Map<String, Object> metricMap = regexNginxStatusMatch(resp, 
metrics.getAliasFields().size());
-        // 返回数据
+        // Returned data
         CollectRep.ValueRow.Builder valueRowBuilder = 
CollectRep.ValueRow.newBuilder();
         for (String alias : aliasFields) {
             Object value = metricMap.get(alias);
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/redis/RedisCommonCollectImpl.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/redis/RedisCommonCollectImpl.java
index eb022844d..289b7ed26 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/redis/RedisCommonCollectImpl.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/redis/RedisCommonCollectImpl.java
@@ -305,7 +305,7 @@ public class RedisCommonCollectImpl extends AbstractCollect 
{
     }
 
     private Map<String, String> parseInfo(String info, Metrics metrics) {
-        // yml配置的指标总和
+        // total of metrics configured in yml
         int fieldTotalSize = metrics.getFields().size();
         String[] lines = info.split(SignConstants.LINE_FEED);
         Map<String, String> result = new 
HashMap<>(MapCapUtil.calInitMap(fieldTotalSize));


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

Reply via email to