From 67c4f2b25941392d66f282fd67a7f2b16388ef45 Mon Sep 17 00:00:00 2001 From: retime123 <781816703@qq.com> Date: Mon, 6 Jun 2022 11:06:33 +0800 Subject: [PATCH] [Feature][Monitoring] Added disk available capacity monitoring (#10287) * Added disk available capacity monitoring * resolve conflict Added disk available capacity monitoring * resolve conflict Added disk available capacity monitoring * resolve conflict Added disk available capacity monitoring --- .../dolphinscheduler/common/Constants.java | 2 +- .../common/utils/HeartBeat.java | 15 ++++++++++++++- .../dolphinscheduler/common/utils/OSUtils.java | 18 ++++++++++++++++++ .../common/os/OSUtilsTest.java | 7 +++++++ .../common/utils/HeartBeatTest.java | 3 ++- .../src/locales/en_US/monitor.ts | 2 ++ .../src/locales/zh_CN/monitor.ts | 2 ++ .../src/views/monitor/servers/master/index.tsx | 15 ++++++++++++++- .../src/views/monitor/servers/worker/index.tsx | 15 ++++++++++++++- 9 files changed, 74 insertions(+), 5 deletions(-) diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java index 997ead7ef2..7af48d14d2 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java @@ -389,7 +389,7 @@ public final class Constants { /** * heartbeat for zk info length */ - public static final int HEARTBEAT_FOR_ZOOKEEPER_INFO_LENGTH = 13; + public static final int HEARTBEAT_FOR_ZOOKEEPER_INFO_LENGTH = 14; /** * jar diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HeartBeat.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HeartBeat.java index b4df08f4b7..ecfa814cc6 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HeartBeat.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HeartBeat.java @@ -41,6 +41,16 @@ public class HeartBeat { private int workerWaitingTaskCount; // worker waiting task count private int workerExecThreadCount; // worker thread pool thread count + private double diskAvailable; + + public double getDiskAvailable() { + return diskAvailable; + } + + public void setDiskAvailable(double diskAvailable) { + this.diskAvailable = diskAvailable; + } + public long getStartupTime() { return startupTime; } @@ -176,6 +186,7 @@ public class HeartBeat { this.loadAverage = OSUtils.loadAverage(); this.availablePhysicalMemorySize = OSUtils.availablePhysicalMemorySize(); this.memoryUsage = OSUtils.memoryUsage(); + this.diskAvailable = OSUtils.diskAvailable(); this.processId = OSUtils.getProcessID(); } @@ -216,7 +227,8 @@ public class HeartBeat { builder.append(processId).append(Constants.COMMA); builder.append(workerHostWeight).append(Constants.COMMA); builder.append(workerExecThreadCount).append(Constants.COMMA); - builder.append(workerWaitingTaskCount); + builder.append(workerWaitingTaskCount).append(Constants.COMMA); + builder.append(diskAvailable); return builder.toString(); } @@ -243,6 +255,7 @@ public class HeartBeat { heartBeat.workerHostWeight = Integer.parseInt(parts[10]); heartBeat.workerExecThreadCount = Integer.parseInt(parts[11]); heartBeat.workerWaitingTaskCount = Integer.parseInt(parts[12]); + heartBeat.diskAvailable = Double.parseDouble(parts[13]); return heartBeat; } } diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java index 1cec5a2913..723a6639c3 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java @@ -26,6 +26,7 @@ import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.File; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; import java.lang.management.RuntimeMXBean; @@ -92,6 +93,23 @@ public class OSUtils { return Double.parseDouble(df.format(memoryUsage)); } + /** + * get disk usage + * Keep 2 decimal + * + * @return disk free size, unit: GB + */ + public static double diskAvailable() { + File file = new File("."); + long freeSpace = file.getFreeSpace(); //unallocated / free disk space in bytes. + + double diskAvailable = freeSpace / 1024.0 / 1024 / 1024; + + DecimalFormat df = new DecimalFormat(TWO_DECIMAL); + df.setRoundingMode(RoundingMode.HALF_UP); + return Double.parseDouble(df.format(diskAvailable)); + } + /** * get available physical memory size *

diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/os/OSUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/os/OSUtilsTest.java index 5300a64d82..caea9322c7 100644 --- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/os/OSUtilsTest.java +++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/os/OSUtilsTest.java @@ -42,6 +42,13 @@ public class OSUtilsTest { Assert.assertTrue(memoryUsage >= 0.0); } + @Test + public void diskAvailable() { + double diskAvailable = OSUtils.diskAvailable(); + logger.info("diskAvailable : {}", diskAvailable); + Assert.assertTrue(diskAvailable >= 0.0); + } + @Test public void loadAverage() { double loadAverage = OSUtils.loadAverage(); diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HeartBeatTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HeartBeatTest.java index c71450fa3d..c207f6bfb5 100644 --- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HeartBeatTest.java +++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HeartBeatTest.java @@ -55,7 +55,7 @@ public class HeartBeatTest { @Test public void testDecodeHeartBeat() throws Exception { - String heartBeatInfo = "0.35,0.58,3.09,6.47,5.0,1.0,1634033006749,1634033006857,1,29732,1,199,200"; + String heartBeatInfo = "0.35,0.58,3.09,6.47,5.0,1.0,1634033006749,1634033006857,1,29732,1,199,200,65.86"; HeartBeat heartBeat = HeartBeat.decodeHeartBeat(heartBeatInfo); double delta = 0.001; @@ -71,6 +71,7 @@ public class HeartBeatTest { assertEquals(29732, heartBeat.getProcessId()); assertEquals(199, heartBeat.getWorkerExecThreadCount()); assertEquals(200, heartBeat.getWorkerWaitingTaskCount()); + assertEquals(65.86, heartBeat.getDiskAvailable(), delta); } } diff --git a/dolphinscheduler-ui/src/locales/en_US/monitor.ts b/dolphinscheduler-ui/src/locales/en_US/monitor.ts index 2b9102f20e..27bd82ce70 100644 --- a/dolphinscheduler-ui/src/locales/en_US/monitor.ts +++ b/dolphinscheduler-ui/src/locales/en_US/monitor.ts @@ -19,6 +19,7 @@ export default { master: { cpu_usage: 'CPU Usage', memory_usage: 'Memory Usage', + disk_available: 'Disk Available', load_average: 'Load Average', create_time: 'Create Time', last_heartbeat_time: 'Last Heartbeat Time', @@ -32,6 +33,7 @@ export default { worker: { cpu_usage: 'CPU Usage', memory_usage: 'Memory Usage', + disk_available: 'Disk Available', load_average: 'Load Average', create_time: 'Create Time', last_heartbeat_time: 'Last Heartbeat Time', diff --git a/dolphinscheduler-ui/src/locales/zh_CN/monitor.ts b/dolphinscheduler-ui/src/locales/zh_CN/monitor.ts index 1d319297a6..eca2fe7a20 100644 --- a/dolphinscheduler-ui/src/locales/zh_CN/monitor.ts +++ b/dolphinscheduler-ui/src/locales/zh_CN/monitor.ts @@ -19,6 +19,7 @@ export default { master: { cpu_usage: '处理器使用量', memory_usage: '内存使用量', + disk_available: '磁盘可用容量', load_average: '平均负载量', create_time: '创建时间', last_heartbeat_time: '最后心跳时间', @@ -32,6 +33,7 @@ export default { worker: { cpu_usage: '处理器使用量', memory_usage: '内存使用量', + disk_available: '磁盘可用容量', load_average: '平均负载量', create_time: '创建时间', last_heartbeat_time: '最后心跳时间', diff --git a/dolphinscheduler-ui/src/views/monitor/servers/master/index.tsx b/dolphinscheduler-ui/src/views/monitor/servers/master/index.tsx index 78563bc514..c01f841b35 100644 --- a/dolphinscheduler-ui/src/views/monitor/servers/master/index.tsx +++ b/dolphinscheduler-ui/src/views/monitor/servers/master/index.tsx @@ -98,7 +98,7 @@ const master = defineComponent({ - +

@@ -125,6 +125,19 @@ const master = defineComponent({
+ + +
+ {item && ( + + )} +
+
+
diff --git a/dolphinscheduler-ui/src/views/monitor/servers/worker/index.tsx b/dolphinscheduler-ui/src/views/monitor/servers/worker/index.tsx index e532d539a2..2eb682310f 100644 --- a/dolphinscheduler-ui/src/views/monitor/servers/worker/index.tsx +++ b/dolphinscheduler-ui/src/views/monitor/servers/worker/index.tsx @@ -102,7 +102,7 @@ const worker = defineComponent({ - +
@@ -129,6 +129,19 @@ const worker = defineComponent({
+ + +
+ {item && ( + + )} +
+
+