From d5bd1d577549c32a27f5ec2d10ac475794752656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98niuerzhuang=E2=80=99?= <‘niuerzhuang@huoxian.cn’> Date: Thu, 23 Jun 2022 14:24:12 +0800 Subject: [PATCH 1/2] fix bug: 1. Memory rate upload 2. Disk rate upload --- .../agent/monitor/impl/PerformanceMonitor.java | 18 ++++++++++++++---- .../iast/agent/report/HeartBeatReport.java | 7 +++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/dongtai-agent/src/main/java/io/dongtai/iast/agent/monitor/impl/PerformanceMonitor.java b/dongtai-agent/src/main/java/io/dongtai/iast/agent/monitor/impl/PerformanceMonitor.java index 82366f873..5aad4b649 100644 --- a/dongtai-agent/src/main/java/io/dongtai/iast/agent/monitor/impl/PerformanceMonitor.java +++ b/dongtai-agent/src/main/java/io/dongtai/iast/agent/monitor/impl/PerformanceMonitor.java @@ -16,10 +16,7 @@ import org.json.JSONArray; import org.json.JSONObject; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; @@ -76,6 +73,19 @@ public static Integer getCpuUsage() { return CPU_USAGE; } + public static Integer getDiskUsage() { + try { + File[] files = File.listRoots(); + for (File file : files) { + double rate = ((file.getTotalSpace()-file.getUsableSpace())*1.0/file.getTotalSpace())*100; + return (int) rate; + } + }catch (Exception e){ + DongTaiLog.error(e); + } + return 0; + } + public static List getPerformanceMetrics() { return PERFORMANCE_METRICS; } diff --git a/dongtai-agent/src/main/java/io/dongtai/iast/agent/report/HeartBeatReport.java b/dongtai-agent/src/main/java/io/dongtai/iast/agent/report/HeartBeatReport.java index 0894cfc56..643552d6b 100644 --- a/dongtai-agent/src/main/java/io/dongtai/iast/agent/report/HeartBeatReport.java +++ b/dongtai-agent/src/main/java/io/dongtai/iast/agent/report/HeartBeatReport.java @@ -76,7 +76,8 @@ private static String getMemInfo() { JSONObject memoryReport = new JSONObject(); memoryReport.put("total", ByteUtils.formatByteSize(memoryUsage.getMax())); memoryReport.put("use", ByteUtils.formatByteSize(memoryUsage.getUsed())); - memoryReport.put("rate", memoryUsage.getUsed() / memoryUsage.getMax()); + double rate = (memoryUsage.getUsed()*1.0 / memoryUsage.getMax())*100; + memoryReport.put("rate", (int) rate); return memoryReport.toString(); } @@ -86,7 +87,9 @@ private static String getMemInfo() { * @return */ public static String getDiskInfo() { - return "{}"; + JSONObject diskInfo = new JSONObject(); + diskInfo.put("rate", PerformanceMonitor.getDiskUsage()); + return diskInfo.toString(); } From 84deda8829a6b2aee83c0a55cffd468ff6f478e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98niuerzhuang=E2=80=99?= <‘niuerzhuang@huoxian.cn’> Date: Thu, 23 Jun 2022 14:52:24 +0800 Subject: [PATCH 2/2] Release 1.7.1 --- dongtai-agent/pom.xml | 4 +- .../java/io/dongtai/iast/agent/Constant.java | 2 +- .../src/main/resources/iast.properties | 4 +- .../main/resources/iast.properties.example | 4 +- .../com/secnium/iast/agent/AgentTest.java | 76 +++++++------------ dongtai-api/pom.xml | 6 +- .../api/jakarta/JakartaResponseWrapper.java | 2 +- .../api/servlet2/ServletResponseWrapper.java | 2 +- dongtai-common/pom.xml | 2 +- dongtai-core/pom.xml | 6 +- .../io/dongtai/iast/core/utils/Constants.java | 2 +- .../com.secnium.iast.resources/blacklist.txt | 7 +- dongtai-log/pom.xml | 2 +- dongtai-plugins/dongtai-grpc/pom.xml | 2 +- dongtai-plugins/pom.xml | 4 +- dongtai-spring-api/pom.xml | 6 +- dongtai-spy/pom.xml | 2 +- pom.xml | 6 +- 18 files changed, 58 insertions(+), 81 deletions(-) diff --git a/dongtai-agent/pom.xml b/dongtai-agent/pom.xml index fff081191..d75709690 100755 --- a/dongtai-agent/pom.xml +++ b/dongtai-agent/pom.xml @@ -7,7 +7,7 @@ io.dongtai.iast iast - 1.7.0 + 1.7.1 dongtai-agent dongtai-agent @@ -48,7 +48,7 @@ io.dongtai.iast dongtai-log - 1.7.0 + 1.7.1 io.dongtai.iast diff --git a/dongtai-agent/src/main/java/io/dongtai/iast/agent/Constant.java b/dongtai-agent/src/main/java/io/dongtai/iast/agent/Constant.java index 0c3e52088..d4598e770 100644 --- a/dongtai-agent/src/main/java/io/dongtai/iast/agent/Constant.java +++ b/dongtai-agent/src/main/java/io/dongtai/iast/agent/Constant.java @@ -4,7 +4,7 @@ * @author dongzhiyong@huoxian.cn */ public class Constant { - public static final String AGENT_VERSION_VALUE = "v1.7.0"; + public static final String AGENT_VERSION_VALUE = "v1.7.1"; public static final String LANGUAGE = "JAVA"; public final static String API_AGENT_REGISTER = "/api/v1/agent/register"; diff --git a/dongtai-agent/src/main/resources/iast.properties b/dongtai-agent/src/main/resources/iast.properties index 9b740f274..d47ceda62 100644 --- a/dongtai-agent/src/main/resources/iast.properties +++ b/dongtai-agent/src/main/resources/iast.properties @@ -1,6 +1,6 @@ -iast.name=dongtai-Enterprise 1.7.0 +iast.name=dongtai-Enterprise 1.7.1 iast.response.name=dongtai -iast.response.value=1.7.0 +iast.response.value=1.7.1 iast.server.url=https://iast.io/openapi iast.server.token=39133a96f5735c253edd908078846c1051824edc iast.allhook.enable=false diff --git a/dongtai-agent/src/main/resources/iast.properties.example b/dongtai-agent/src/main/resources/iast.properties.example index 14b7cc61d..f58f8eed4 100644 --- a/dongtai-agent/src/main/resources/iast.properties.example +++ b/dongtai-agent/src/main/resources/iast.properties.example @@ -1,7 +1,7 @@ # iast.properties file example -iast.name=dongtai-Enterprise 1.7.0 +iast.name=dongtai-Enterprise 1.7.1 iast.response.name=dongtai -iast.response.value=1.7.0 +iast.response.value=1.7.1 iast.server.url=https://iast.io/openapi iast.server.token=39133a96f5735c253edd908078846c1051824edc iast.allhook.enable=false diff --git a/dongtai-agent/src/test/java/com/secnium/iast/agent/AgentTest.java b/dongtai-agent/src/test/java/com/secnium/iast/agent/AgentTest.java index c444d91db..4580d8061 100644 --- a/dongtai-agent/src/test/java/com/secnium/iast/agent/AgentTest.java +++ b/dongtai-agent/src/test/java/com/secnium/iast/agent/AgentTest.java @@ -46,18 +46,18 @@ public static void replace(String path) { StringBuffer buf = new StringBuffer(); // 保存该行前面的内容 while ((temp = br.readLine()) != null) { - if (temp.contains("${HOSTNAME_AGENT_ID}")){ - temp.replace("${HOSTNAME_AGENT_ID}", AgentRegisterReport.getInternalHostName()+"-"+AgentRegisterReport.getAgentFlag().toString()); - }else if (temp.contains("${HOSTNAME}")){ - temp.replace("${HOSTNAME}",AgentRegisterReport.getInternalHostName()); - }else if (temp.contains("${AGENT_ID}")){ - temp.replace("${AGENT_ID}",AgentRegisterReport.getAgentFlag().toString()); - }else if (temp.contains("${OPENAPI}")){ + if (temp.contains("${HOSTNAME_AGENT_ID}")) { + temp.replace("${HOSTNAME_AGENT_ID}", AgentRegisterReport.getInternalHostName() + "-" + AgentRegisterReport.getAgentFlag().toString()); + } else if (temp.contains("${HOSTNAME}")) { + temp.replace("${HOSTNAME}", AgentRegisterReport.getInternalHostName()); + } else if (temp.contains("${AGENT_ID}")) { + temp.replace("${AGENT_ID}", AgentRegisterReport.getAgentFlag().toString()); + } else if (temp.contains("${OPENAPI}")) { temp.replace("${OPENAPI}", IastProperties.getInstance().getBaseUrl()); - }else if (temp.contains("${LOG_PORT}")){ - temp.replace("${LOG_PORT}",IastProperties.getInstance().getLogPort()); - }else if (temp.contains("${LOG_PATH}")){ - temp.replace("${LOG_PATH}", System.getProperty("dongtai.log.path")+File.separator+"dongtai_javaagent.log"); + } else if (temp.contains("${LOG_PORT}")) { + temp.replace("${LOG_PORT}", IastProperties.getInstance().getLogPort()); + } else if (temp.contains("${LOG_PATH}")) { + temp.replace("${LOG_PATH}", System.getProperty("dongtai.log.path") + File.separator + "dongtai_javaagent.log"); } buf = buf.append(temp); buf = buf.append(System.getProperty("line.separator")); @@ -98,48 +98,24 @@ public void doAaaa() { } public static void main(String[] args) { -// com.sun.management.OperatingSystemMXBean osmxb = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); -// double systemCpuLoad = osmxb.getSystemCpuLoad()/osmxb.getAvailableProcessors(); -// double processCpuLoad = osmxb.getProcessCpuLoad(); -// System.out.println(systemCpuLoad); -// System.out.println(processCpuLoad); - - -// OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); -// for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) { -// method.setAccessible(true); -// if (method.getName().startsWith("get") -// && Modifier.isPublic(method.getModifiers())) { -// Object value; -// try { -// value = method.invoke(operatingSystemMXBean); -// } catch (Exception e) { -// value = e; -// } // try -// System.out.println(method.getName() + " = " + value); -// } // if -// } // for - - - OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean) - ManagementFactory.getOperatingSystemMXBean(); - double load; - for(int i=0; i<10; i++) { - load = ((com.sun.management.OperatingSystemMXBean) mbean).getSystemCpuLoad(); - System.out.println(load); - if((load<0.0 || load>1.0) && load != -1.0) { - throw new RuntimeException("getSystemCpuLoad() returns " + load - + " which is not in the [0.0,1.0] interval"); - } - try { - Thread.sleep(200); - } catch(InterruptedException e) { - e.printStackTrace(); - } + File[] files = File.listRoots(); + for (File file : files) { + System.out.println(file + "磁盘的空间大小为:" + file.getTotalSpace() / 1024 / 1024 / 1024 + "G"); + System.out.println(file + "磁盘的可使用空间大小为:" + file.getUsableSpace() / 1024 / 1024 / 1024 + "G"); + System.out.println(file + "磁盘的空闲空间大小为:" + file.getFreeSpace() / 1024 / 1024 / 1024 + "G"); + double rate = ((file.getTotalSpace()-file.getUsableSpace())*1.0/file.getTotalSpace())*100; + System.out.println((int) rate); } } + @Test private static void printUsage() { - + File[] files = File.listRoots(); + for (File file : files) { + System.out.println(file + "磁盘的空间大小为:" + file.getTotalSpace() / 1024 / 1024 / 1024 + "G"); + System.out.println(file + "磁盘的可使用空间大小为:" + file.getUsableSpace() / 1024 / 1024 / 1024 + "G"); + System.out.println(file + "磁盘的空闲空间大小为:" + file.getFreeSpace() / 1024 / 1024 / 1024 + "G"); + System.out.println("------------------------------------------------------------------"); + } } } diff --git a/dongtai-api/pom.xml b/dongtai-api/pom.xml index 28d4aac85..226fa25bd 100644 --- a/dongtai-api/pom.xml +++ b/dongtai-api/pom.xml @@ -5,7 +5,7 @@ iast io.dongtai.iast - 1.7.0 + 1.7.1 4.0.0 @@ -39,12 +39,12 @@ cn.huoxian.iast dongtai-spring-api - 1.7.0 + 1.7.1 io.dongtai.iast dongtai-log - 1.7.0 + 1.7.1 diff --git a/dongtai-api/src/main/java/io/dongtai/api/jakarta/JakartaResponseWrapper.java b/dongtai-api/src/main/java/io/dongtai/api/jakarta/JakartaResponseWrapper.java index 52760398d..f0aca305e 100644 --- a/dongtai-api/src/main/java/io/dongtai/api/jakarta/JakartaResponseWrapper.java +++ b/dongtai-api/src/main/java/io/dongtai/api/jakarta/JakartaResponseWrapper.java @@ -23,7 +23,7 @@ public class JakartaResponseWrapper extends HttpServletResponseWrapper implement public JakartaResponseWrapper(HttpServletResponse response) { super(response); - response.addHeader("DongTai", "v1.7.0"); + response.addHeader("DongTai", "v1.7.1"); } @Override diff --git a/dongtai-api/src/main/java/io/dongtai/api/servlet2/ServletResponseWrapper.java b/dongtai-api/src/main/java/io/dongtai/api/servlet2/ServletResponseWrapper.java index 8cd4623e3..58a7124d4 100644 --- a/dongtai-api/src/main/java/io/dongtai/api/servlet2/ServletResponseWrapper.java +++ b/dongtai-api/src/main/java/io/dongtai/api/servlet2/ServletResponseWrapper.java @@ -21,7 +21,7 @@ public class ServletResponseWrapper extends HttpServletResponseWrapper implement public ServletResponseWrapper(HttpServletResponse response) { super(response); - response.addHeader("DongTai", "v1.7.0"); + response.addHeader("DongTai", "v1.7.1"); } private String getLine() { diff --git a/dongtai-common/pom.xml b/dongtai-common/pom.xml index 592237e87..eb162099a 100644 --- a/dongtai-common/pom.xml +++ b/dongtai-common/pom.xml @@ -5,7 +5,7 @@ iast io.dongtai.iast - 1.7.0 + 1.7.1 4.0.0 diff --git a/dongtai-core/pom.xml b/dongtai-core/pom.xml index 59a08506a..681dada8d 100755 --- a/dongtai-core/pom.xml +++ b/dongtai-core/pom.xml @@ -7,7 +7,7 @@ io.dongtai.iast iast - 1.7.0 + 1.7.1 dongtai-core dongtai-core @@ -159,7 +159,7 @@ io.dongtai.iast dongtai-spy - 1.7.0 + 1.7.1 provided @@ -224,7 +224,7 @@ io.dongtai.iast dongtai-log - 1.7.0 + 1.7.1 io.dongtai.iast diff --git a/dongtai-core/src/main/java/io/dongtai/iast/core/utils/Constants.java b/dongtai-core/src/main/java/io/dongtai/iast/core/utils/Constants.java index 76a5319e3..a23b293e7 100644 --- a/dongtai-core/src/main/java/io/dongtai/iast/core/utils/Constants.java +++ b/dongtai-core/src/main/java/io/dongtai/iast/core/utils/Constants.java @@ -4,7 +4,7 @@ * @author dongzhiyong@huoxian.cn */ public class Constants { - public static final String AGENT_VERSION_VALUE = "v1.7.0"; + public static final String AGENT_VERSION_VALUE = "v1.7.1"; public final static String API_REPORT_UPLOAD = "/api/v1/report/upload"; public final static String SERVER_ADDRESS = "/api/v1/agent/update"; public final static String API_HOOK_PROFILE = "/api/v1/profiles"; diff --git a/dongtai-core/src/main/resources/com.secnium.iast.resources/blacklist.txt b/dongtai-core/src/main/resources/com.secnium.iast.resources/blacklist.txt index af42e9741..0cc1aa605 100644 --- a/dongtai-core/src/main/resources/com.secnium.iast.resources/blacklist.txt +++ b/dongtai-core/src/main/resources/com.secnium.iast.resources/blacklist.txt @@ -24747,6 +24747,7 @@ java/util/IllegalFormatException java/util/InvalidPropertiesFormatException java/util/JumboEnumSet java/util/JumboEnumSet$EnumSetIterator +java/util/LinkedHashMap java/util/LinkedHashMap$* java/util/LinkedHashMap$1 java/util/LinkedHashMap$2 @@ -24874,9 +24875,9 @@ java/util/spi/LocaleNameProvider java/util/spi/LocaleServiceProvider java/util/spi/TimeZoneNameProvider java/util/StringTokenizer -java/util/stream/BaseStream -java/util/stream/IntStream -java/util/stream/Stream +# java/util/stream/BaseStream +# java/util/stream/IntStream +# java/util/stream/Stream java/util/zip/* javassist/ByteArrayClassPath javassist/CannotCompileException diff --git a/dongtai-log/pom.xml b/dongtai-log/pom.xml index 5f96dc39b..c349c498c 100644 --- a/dongtai-log/pom.xml +++ b/dongtai-log/pom.xml @@ -5,7 +5,7 @@ iast io.dongtai.iast - 1.7.0 + 1.7.1 4.0.0 diff --git a/dongtai-plugins/dongtai-grpc/pom.xml b/dongtai-plugins/dongtai-grpc/pom.xml index 64c07f295..e73850f03 100644 --- a/dongtai-plugins/dongtai-grpc/pom.xml +++ b/dongtai-plugins/dongtai-grpc/pom.xml @@ -5,7 +5,7 @@ dongtai-plugins io.dongtai.iast - 1.7.0 + 1.7.1 4.0.0 diff --git a/dongtai-plugins/pom.xml b/dongtai-plugins/pom.xml index 99e02c4e4..dfbc7e7e1 100644 --- a/dongtai-plugins/pom.xml +++ b/dongtai-plugins/pom.xml @@ -5,7 +5,7 @@ iast io.dongtai.iast - 1.7.0 + 1.7.1 4.0.0 @@ -24,7 +24,7 @@ io.dongtai.iast dongtai-core - 1.7.0 + 1.7.1 provided diff --git a/dongtai-spring-api/pom.xml b/dongtai-spring-api/pom.xml index 83dac11dc..35edabb27 100644 --- a/dongtai-spring-api/pom.xml +++ b/dongtai-spring-api/pom.xml @@ -5,13 +5,13 @@ iast io.dongtai.iast - 1.7.0 + 1.7.1 4.0.0 cn.huoxian.iast dongtai-spring-api - 1.7.0 + 1.7.1 8 @@ -28,7 +28,7 @@ io.dongtai.iast dongtai-log - 1.7.0 + 1.7.1 diff --git a/dongtai-spy/pom.xml b/dongtai-spy/pom.xml index de5b96eaa..91eac35ba 100644 --- a/dongtai-spy/pom.xml +++ b/dongtai-spy/pom.xml @@ -5,7 +5,7 @@ iast io.dongtai.iast - 1.7.0 + 1.7.1 4.0.0 diff --git a/pom.xml b/pom.xml index 1503f2138..bf8a63931 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ io.dongtai.iast iast - 1.7.0 + 1.7.1 pom dongtai-agent-java @@ -118,12 +118,12 @@ io.dongtai.iast dongtai-spy - 1.7.0 + 1.7.1 io.dongtai.iast dongtai-core - 1.7.0 + 1.7.1 test