From b88ec185bff02dd114b207c2dfc7fae7e6f6e722 Mon Sep 17 00:00:00 2001
From: tfhddd <2272751277@qq.com>
Date: Tue, 13 Aug 2024 11:22:39 +0800
Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E7=BE=A4NPU=E7=AE=97=E5=8A=9B?=
=?UTF-8?q?=E6=80=A7=E8=83=BD=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
集群NPU算力性能数据统计
---
pom.xml | 57 ++++---
src/main/java/om/Module/PerformanceData.java | 169 +++++++++++++++++++
src/main/java/om/constant/PerfConstant.java | 51 ++++++
3 files changed, 249 insertions(+), 28 deletions(-)
create mode 100644 src/main/java/om/Module/PerformanceData.java
create mode 100644 src/main/java/om/constant/PerfConstant.java
diff --git a/pom.xml b/pom.xml
index f703527..254e779 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,37 +78,38 @@
log4j-core
2.17.1
-
-
- com.huaweicloud
- esdk-obs-java-bundle
- 3.21.8
-
-
-
- org.yaml
- snakeyaml
- 2.2
-
-
-
-
- org.apache.httpcomponents
- httpclient
- 4.5.14
-
-
-
-
- com.fasterxml.jackson.dataformat
- jackson-dataformat-cbor
- 2.17.2
-
-
-
+
+
+ com.huaweicloud
+ esdk-obs-java-bundle
+ 3.21.8
+
+
+
+ org.yaml
+ snakeyaml
+ 2.2
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.14
+
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-cbor
+ 2.17.2
+
+
+ org.apache.commons
+ commons-lang3
+ 3.11
+
diff --git a/src/main/java/om/Module/PerformanceData.java b/src/main/java/om/Module/PerformanceData.java
new file mode 100644
index 0000000..7a1eac4
--- /dev/null
+++ b/src/main/java/om/Module/PerformanceData.java
@@ -0,0 +1,169 @@
+/* This project is licensed under the Mulan PSL v2.
+ You can use this software according to the terms and conditions of the Mulan PSL v2.
+ You may obtain a copy of Mulan PSL v2 at:
+ http://license.coscl.org.cn/MulanPSL2
+ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ PURPOSE.
+ See the Mulan PSL v2 for more details.
+ Create: 2024
+*/
+
+package om.Module;
+
+import CommonClass.CommonInterface;
+import CommonClass.Parent;
+import Utils.EsClientUtils2;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import om.constant.PerfConstant;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 性能数据采集.
+ */
+public class PerformanceData extends Parent implements CommonInterface {
+ /**
+ * 日志打印.
+ */
+ private static Logger logger = LoggerFactory.getLogger(PerformanceData.class);
+
+ /**
+ * 构造类.
+ *
+ * @throws IOException IO异常
+ */
+ public PerformanceData() throws IOException {
+ }
+
+ /**
+ * json解析工具.
+ */
+ private static ObjectMapper objectMapper = new ObjectMapper();
+
+ /**
+ * kafka数据采集.
+ */
+ @Override
+ public void run() {
+ for (KafkaConsumer customer : this.KafkaConsumerList) {
+ Runnable task = () -> {
+ while (true) {
+ ConsumerRecords poll = customer.poll(Duration.ofSeconds(2));
+ dealData(poll);
+ EsClientUtils2.getBulkProcess().flush();
+ customer.commitSync();
+ }
+ };
+ this.thread_pool.execute(task);
+ }
+ }
+
+ /**
+ * 数据处理.
+ *
+ * @param records kafka数据
+ * @return 数据处理列表
+ */
+ @Override
+ public List