This is an automated email from the ASF dual-hosted git repository.
gaoxingcun 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 49db98ade [refactor] trans and use assert (#1841)
49db98ade is described below
commit 49db98ade4ed90e764ec4653924c22064e2d1f18
Author: Hyeon Sung <[email protected]>
AuthorDate: Thu Apr 25 16:50:23 2024 +0900
[refactor] trans and use assert (#1841)
Co-authored-by: tomsun28 <[email protected]>
Co-authored-by: 铁甲小宝 <[email protected]>
---
.../collect/memcached/MemcachedCollectImpl.java | 8 +++----
.../collect/mongodb/MongodbSingleCollectImpl.java | 4 +---
.../collect/mq/RocketmqSingleCollectImpl.java | 7 +++---
.../nebulagraph/NebulaGraphCollectImpl.java | 16 ++++++-------
.../collector/collect/nginx/NginxCollectImpl.java | 26 +++++++++++-----------
5 files changed, 29 insertions(+), 32 deletions(-)
diff --git
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/memcached/MemcachedCollectImpl.java
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/memcached/MemcachedCollectImpl.java
index a09d10073..4c7d1df2e 100644
---
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/memcached/MemcachedCollectImpl.java
+++
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/memcached/MemcachedCollectImpl.java
@@ -74,7 +74,7 @@ public class MemcachedCollectImpl extends AbstractCollect {
long responseTime = System.currentTimeMillis() - startTime;
PrintWriter out = new PrintWriter(socket.getOutputStream(),
true);
BufferedReader in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
- // 发送统计命令
+ // Send a command to collect statistics
Map<String, String> resultMap = new HashMap<>(128);
parseCmdResponse(resultMap, in, out, STATS);
parseCmdResponse(resultMap, in, out, STATS_SETTINGS);
@@ -82,7 +82,7 @@ public class MemcachedCollectImpl extends AbstractCollect {
resultMap.put(CollectorConstants.RESPONSE_TIME,
Long.toString(responseTime));
- // 关闭输出流和Socket连接
+ // Close the output stream and socket connection
in.close();
out.close();
socket.close();
@@ -130,7 +130,7 @@ public class MemcachedCollectImpl extends AbstractCollect {
out.println(cmd);
String line;
while ((line = in.readLine()) != null && !line.equals(STATS_END_RSP)) {
- // 解析每一行,将键值对存入HashMap
+ // Parse each line and store the key-value pairs in a HashMap
String[] parts = line.split(" ");
if (parts.length == 3) {
statsMap.put(parts[1], parts[2]);
@@ -145,7 +145,7 @@ public class MemcachedCollectImpl extends AbstractCollect {
String line;
while ((line = in.readLine()) != null && !line.equals(STATS_END_RSP)) {
String[] parts = line.split("\\s+");
- // 提取 slab size 和 slab count,并放入HashMap
+ // Extract slab size and slab count, then add them to the HashMap
if (parts.length >= 3 && "STAT".equals(parts[0])) {
statsMap.put("item_size", parts[1]);
statsMap.put("item_count", parts[2]);
diff --git
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java
index 78c95e810..000f4937c 100644
---
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java
+++
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java
@@ -169,9 +169,7 @@ public class MongodbSingleCollectImpl extends
AbstractCollect {
* Check that the mongodb connection information in metrics is complete
*/
private void preCheck(Metrics metrics) {
- if (metrics == null || metrics.getMongodb() == null) {
- throw new IllegalArgumentException("Mongodb collect must has
mongodb params");
- }
+ Assert.isTrue(metrics != null && metrics.getMongodb() != null,
"Mongodb collect must has mongodb params");
MongodbProtocol mongodbProtocol = metrics.getMongodb();
Assert.hasText(mongodbProtocol.getCommand(), "Mongodb Protocol command
is required.");
Assert.hasText(mongodbProtocol.getHost(), "Mongodb Protocol host is
required.");
diff --git
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/mq/RocketmqSingleCollectImpl.java
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/mq/RocketmqSingleCollectImpl.java
index f39c24beb..7547012d2 100644
---
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/mq/RocketmqSingleCollectImpl.java
+++
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/mq/RocketmqSingleCollectImpl.java
@@ -146,9 +146,7 @@ public class RocketmqSingleCollectImpl extends
AbstractCollect implements Dispos
* @param metrics metrics config
*/
private void preCheck(Metrics metrics) {
- if (metrics == null || metrics.getRocketmq() == null) {
- throw new IllegalArgumentException("Mongodb collect must has
rocketmq params");
- }
+ Assert.isTrue(metrics != null && metrics.getRocketmq() != null,
"Mongodb collect must has rocketmq params");
RocketmqProtocol rocketmq = metrics.getRocketmq();
Assert.hasText(rocketmq.getNamesrvHost(), "Rocketmq Protocol
namesrvHost is required.");
Assert.hasText(rocketmq.getNamesrvPort(), "Rocketmq Protocol
namesrvPort is required.");
@@ -339,7 +337,8 @@ public class RocketmqSingleCollectImpl extends
AbstractCollect implements Dispos
Map<String, List<RocketmqCollectData.TopicQueueInfo>>
topicQueueInfoTable = new HashMap<>(32);
List<RocketmqCollectData.TopicQueueInfo> topicQueueInfoList =
new ArrayList<>();
- // todo 查询topic的queue信息需要for循环调用
mqAdminExt.examineTopicStats(), topic数量很大的情况, 调用次数也会很多
+ // When querying queue information for a topic, you need to
use a for-loop to call mqAdminExt.examineTopicStats().
+ // If the number of topics is large, the number of calls will
also be high
topicQueueInfoTable.put(topic, topicQueueInfoList);
topicInfoList.add(topicQueueInfoTable);
rocketmqCollectData.setTopicInfoList(topicInfoList);
diff --git
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/nebulagraph/NebulaGraphCollectImpl.java
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/nebulagraph/NebulaGraphCollectImpl.java
index 135bb42ad..1ffb6b674 100644
---
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/nebulagraph/NebulaGraphCollectImpl.java
+++
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/nebulagraph/NebulaGraphCollectImpl.java
@@ -99,7 +99,7 @@ public class NebulaGraphCollectImpl extends AbstractCollect {
HttpUriRequest request = createHttpRequest(nebulaGraph.getHost(),
nebulaGraph.getPort(),
nebulaGraph.getUrl(), nebulaGraph.getTimeout());
try {
- // 发起http请求,获取响应数据
+ // Send an HTTP request to obtain response data
response = CommonHttpClient.getHttpClient().execute(request,
httpContext);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != SUCCESS_CODE) {
@@ -110,7 +110,7 @@ public class NebulaGraphCollectImpl extends AbstractCollect
{
resp = EntityUtils.toString(response.getEntity(),
StandardCharsets.UTF_8);
responseTime = System.currentTimeMillis() - startTime;
resultMap.put(CollectorConstants.RESPONSE_TIME,
Long.toString(responseTime));
- // 根据API进行不同解析
+ // Parse the response differently depending on the API
if (GRAPH_API.equals(nebulaGraph.getUrl())) {
parseStatsResponse(resp, nebulaGraph.getTimePeriod(),
resultMap);
} else if (STORAGE_API.equals(nebulaGraph.getUrl())) {
@@ -177,13 +177,13 @@ public class NebulaGraphCollectImpl extends
AbstractCollect {
}
/**
- * 解析Stats响应通过时间间隔进行筛选
+ * Parse Stats response and filter by time period
*
- * @param responseBody 响应体
- * @param timePeriod 时间间隔
+ * @param responseBody response body
+ * @param timePeriod time period
*/
private void parseStatsResponse(String responseBody, String timePeriod,
HashMap<String, String> resultMap) {
- // 设置正则匹配
+ // Set up regular expression matching
String timeRegex = String.format(REGEX, timePeriod);
Pattern pattern = Pattern.compile(timeRegex);
String[] strArray = responseBody.split(STR_SPLIT);
@@ -198,9 +198,9 @@ public class NebulaGraphCollectImpl extends AbstractCollect
{
/**
- * 解析Storage响应通过时间间隔进行筛选
+ * Parse the Storage response and filter by time period
*
- * @param responseBody 响应体
+ * @param responseBody response body
*/
private void parseStorageResponse(String responseBody, HashMap<String,
String> resultMap) {
String[] strArray = responseBody.split(STR_SPLIT);
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 5a3935a3b..d9804182e 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
@@ -218,7 +218,7 @@ public class NginxCollectImpl extends AbstractCollect {
}
/**
- * 解析ngx_http_reqstat_module模块暴露信息
+ * Analyze the information exposed by the ngx_http_reqstat_module module
*
* @param builder builder
* @param resp resp
@@ -228,17 +228,17 @@ public class NginxCollectImpl extends AbstractCollect {
private void parseReqStatusResponse(CollectRep.MetricsData.Builder
builder, String resp, Metrics metrics,
Long responseTime) {
//example
- //zone_name key max_active max_bw traffic requests
active bandwidth
- //imgstore_appid 43 27 6M 63G 374063 0 0
- //imgstore_appid 53 329 87M 2058G 7870529 50 25M
- //server_addr 10.128.1.17 2 8968 24M 1849 0
0
- //server_addr 127.0.0.1 1 6M 5G 912 1
0
- //server_addr 180.96.x.1 3358 934M 27550G 141277391
891 356M
- //server_addr 180.96.x.2 78 45M 220G 400704 0
0
- //server_addr 180.96.x.3 242 58M 646G 2990547 42
7M
- //server_name d.123.sogou.com 478 115M 2850G 30218726
115 39M
- //server_name dl.pinyin.sogou.com 913 312M 8930G
35345453 225 97M
- //server_name download.ie.sogou.com 964 275M 7462G
7979817 297 135M
+ //zone_name key max_active max_bw
traffic requests active bandwidth
+ //imgstore_appid 43 27 6M 63G
374063 0 0
+ //imgstore_appid 53 329 87M 2058G
7870529 50 25M
+ //server_addr 10.128.1.17 2 8968 24M
1849 0 0
+ //server_addr 127.0.0.1 1 6M 5G
912 1 0
+ //server_addr 180.96.x.1 3358 934M
27550G 141277391 891 356M
+ //server_addr 180.96.x.2 78 45M 220G
400704 0 0
+ //server_addr 180.96.x.3 242 58M 646G
2990547 42 7M
+ //server_name d.123.sogou.com 478 115M 2850G
30218726 115 39M
+ //server_name dl.pinyin.sogou.com 913 312M 8930G
35345453 225 97M
+ //server_name download.ie.sogou.com 964 275M 7462G
7979817 297 135M
List<ReqStatusResponse> reqStatusResponses = regexReqStatusMatch(resp);
List<String> aliasFields = metrics.getAliasFields();
@@ -273,7 +273,7 @@ public class NginxCollectImpl extends AbstractCollect {
private Map<String, Object> regexNginxStatusMatch(String resp, Integer
aliasFieldsSize) {
Map<String, Object> metricsMap = new HashMap<>(aliasFieldsSize);
- // 正则提取监控信息
+ // Extract monitoring information using regular expressions
Pattern pattern = Pattern.compile(REGEX_SERVER);
Matcher matcher = pattern.matcher(resp);
while (matcher.find()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]