From 9f64646c776a35c72e4565d8cfcea9c28417bd44 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Tue, 5 Dec 2023 09:22:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E5=88=86=E6=9E=90gamma=E9=87=8D=E6=96=B0=E5=88=86=E6=9E=90?= =?UTF-8?q?=E5=B3=B0=E6=95=B0=E6=8D=AE=E8=B0=83=E7=94=A8=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?dll=E6=94=B9=E4=B8=BA=E8=B0=83=E7=94=A8http=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/handler/HttpClient.java | 103 ++++++++++++++++++ .../service/impl/GammaServiceImpl.java | 3 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/handler/HttpClient.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/handler/HttpClient.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/handler/HttpClient.java new file mode 100644 index 00000000..0a950086 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/handler/HttpClient.java @@ -0,0 +1,103 @@ +package org.jeecg.common.handler; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Objects; + +public class HttpClient { + private static final String URL_ADDRESS = "http://127.0.0.1:7080/"; + + public static String fitPeakFull(String phdStr, List Af, List Cf, List Ff) { + //接收算法返回内容 + String resultJson = ""; + //拼接请求路径 + String url = URL_ADDRESS + "fitPeakFull"; + HttpURLConnection connection = null; + OutputStream out = null; + BufferedReader in = null; + try { + //创建请求参数 以json的形式 + JsonObject requestJson = new JsonObject(); + requestJson.addProperty("phd", phdStr); + JsonArray AfJson = new JsonArray(); + for (int i = 0; i < Af.size(); i++) { + AfJson.add(Af.get(i)); + } + requestJson.add("Af", AfJson); + JsonArray CfJson = new JsonArray(); + for (int i = 0; i < Cf.size(); i++) { + CfJson.add(Cf.get(i)); + } + requestJson.add("Cf", CfJson); + JsonArray FfJson = new JsonArray(); + for (int i = 0; i < Ff.size(); i++) { + FfJson.add(Ff.get(i)); + } + requestJson.add("Ff", FfJson); + //请求的json参数转换为字符串 + String requestParam = requestJson.toString(); + //请求的json字符串转为字节数组的方式 + byte[] requestParamBytes = requestParam.getBytes(StandardCharsets.UTF_8); + //建立Http连接 + connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Content-Length", String.valueOf(requestParamBytes.length)); + connection.setDoOutput(true); + connection.setConnectTimeout(300000); + connection.setReadTimeout(300000); + //获取http连接的输出流 + out = connection.getOutputStream(); + //向输出流写入传递的参数字节数组信息 + out.write(requestParamBytes); + //接收http请求的响应编码 + int responseCode = connection.getResponseCode(); + //如果是成功的响应编码 + if (responseCode == HttpURLConnection.HTTP_OK) { + StringBuilder responseBuilder = new StringBuilder(); + in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); + String line; + while ((line = in.readLine()) != null) { + responseBuilder.append(line); + } + resultJson = responseBuilder.toString(); + } else { + System.out.println("Error while sending request to C++ server, response code: " + responseCode); + } + } catch (ProtocolException e) { + throw new RuntimeException(e); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(out)) { + out.close(); + } + if (Objects.nonNull(connection)) { + connection.disconnect(); + } + if (Objects.nonNull(in)) { + in.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return resultJson; + } + + +} diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java index 8c0937db..7cd44626 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java @@ -23,6 +23,7 @@ import org.apache.shiro.SecurityUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.cache.LocalCache; import org.jeecg.common.constant.DateConstant; +import org.jeecg.common.handler.HttpClient; import org.jeecg.common.properties.ParameterProperties; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.system.util.JwtUtil; @@ -1491,7 +1492,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi } ObjectMapper mapper = new ObjectMapper(); String phdStr = mapper.writeValueAsString(phd); - String strValue = CalValuesHandler.fitPeakFull(phdStr, Af, Cf, Ff); + String strValue = HttpClient.fitPeakFull(phdStr, Af, Cf, Ff); Map parseMap = JSON.parseObject(strValue, Map.class); for (Map.Entry entry : parseMap.entrySet()) { if (entry.getKey().equalsIgnoreCase("vPeak")) { From d24be7eda1baf3d8b29ea97cd4411bd16de63cc7 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Wed, 6 Dec 2023 17:12:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=EF=BC=9A=E6=95=B0=E6=8D=AE=E9=87=87?= =?UTF-8?q?=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/jeecg/common/constant/DBSQL.java | 6 ++++++ .../java/org/jeecg/modules/databaseStatus/ConnFetcher.java | 7 +++++-- .../main/java/org/jeecg/JeecgAbnormalAlarmApplication.java | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DBSQL.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DBSQL.java index 48bf4457..d2eb2622 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DBSQL.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DBSQL.java @@ -19,6 +19,8 @@ public interface DBSQL { String DBSTATUS_CONN_PG = "SELECT COUNT(*) FROM pg_stat_activity WHERE query_start >= now() - interval '1 minute'"; + String DBSTATUS_DATASIZE_PG = "SELECT ROUND(SUM(pg_database_size(datname)) / 1024 / 1024, 0) FROM pg_database"; + /* Oracle */ String DBNAMES_OR = "SELECT username FROM all_users"; String DBINFO_OR = "SELECT a.table_name AS tableName, a.num_rows AS numRow," + @@ -54,6 +56,10 @@ public interface DBSQL { String DBSTATUS_CONN_OR = "SELECT COUNT(*) FROM V$SESSION WHERE LOGON_TIME >= SYSDATE - 1 / 24 / 60"; + String DBSTATUS_LOGRESIDUE_OR = "SELECT SUM(BYTES) / 1024 / 1024 FROM V$log WHERE ARCHIVED = 'NO'"; + + String DBSTATUS_DATASIZE_OR = "SELECT SUM(BYTES) / 1024 / 1024 AS dataSize FROM dba_data_files"; + /* MySQL */ String DBNAMES_MY = "SHOW DATABASES"; String DBINFO_MY = "SELECT TABLE_NAME AS tableName, TABLE_ROWS AS numRow," + diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/databaseStatus/ConnFetcher.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/databaseStatus/ConnFetcher.java index 3c396c61..51b132ab 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/databaseStatus/ConnFetcher.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/databaseStatus/ConnFetcher.java @@ -1,6 +1,8 @@ package org.jeecg.modules.databaseStatus; +import cn.hutool.core.collection.ArrayIter; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.constant.DBSQL; @@ -39,8 +41,9 @@ public class ConnFetcher implements Runnable{ public void run() { if (CollUtil.isEmpty(databases)) return; List statusList = new ArrayList<>(); - Iterator iterator = databases.iterator(); while (true){ + Iterator iterator = CollUtil + .addAll(new ArrayList<>() ,databases).iterator(); LocalDateTime now = LocalDateTime.now(); while (iterator.hasNext()) { try { @@ -88,7 +91,7 @@ public class ConnFetcher implements Runnable{ databaseStatus.setCollectTime(now); // 数据达到一定数量,进行批量保存 statusList.add(databaseStatus); - if (statusList.size() == 5){ + if (statusList.size() == 100){ connService.saveBatch(statusList); statusList = new ArrayList<>(); } diff --git a/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/java/org/jeecg/JeecgAbnormalAlarmApplication.java b/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/java/org/jeecg/JeecgAbnormalAlarmApplication.java index e1763c58..fc18c401 100644 --- a/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/java/org/jeecg/JeecgAbnormalAlarmApplication.java +++ b/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/java/org/jeecg/JeecgAbnormalAlarmApplication.java @@ -63,7 +63,7 @@ public class JeecgAbnormalAlarmApplication extends SpringBootServletInitializer // 启动监测服务器连接状态的线程 serverStatusManager.start(); // 启动采集数据库状态信息线程组 - databaseStatusFetcher.start(); + // databaseStatusFetcher.start(); } } \ No newline at end of file