Browse Source

Monitoring: Added disk available capacity monitoring (#10030)

2.0.7-release
retime123 3 years ago committed by GitHub
parent
commit
930c7d4f62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
  2. 35
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HeartBeat.java
  3. 19
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
  4. 7
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/os/OSUtilsTest.java
  5. 3
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HeartBeatTest.java
  6. 16
      dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/master.vue
  7. 16
      dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/worker.vue
  8. 1
      dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js
  9. 1
      dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js

2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

@ -514,7 +514,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

35
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HeartBeat.java

@ -42,6 +42,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;
}
@ -177,6 +187,7 @@ public class HeartBeat {
this.loadAverage = OSUtils.loadAverage();
this.availablePhysicalMemorySize = OSUtils.availablePhysicalMemorySize();
this.memoryUsage = OSUtils.memoryUsage();
this.diskAvailable = OSUtils.diskAvailable();
this.processId = OSUtils.getProcessID();
}
@ -207,6 +218,7 @@ public class HeartBeat {
StringBuilder builder = new StringBuilder(100);
builder.append(cpuUsage).append(COMMA);
builder.append(memoryUsage).append(COMMA);
builder.append(diskAvailable).append(COMMA);
builder.append(loadAverage).append(COMMA);
builder.append(availablePhysicalMemorySize).append(Constants.COMMA);
builder.append(maxCpuloadAvg).append(Constants.COMMA);
@ -233,17 +245,18 @@ public class HeartBeat {
HeartBeat heartBeat = new HeartBeat();
heartBeat.cpuUsage = Double.parseDouble(parts[0]);
heartBeat.memoryUsage = Double.parseDouble(parts[1]);
heartBeat.loadAverage = Double.parseDouble(parts[2]);
heartBeat.availablePhysicalMemorySize = Double.parseDouble(parts[3]);
heartBeat.maxCpuloadAvg = Double.parseDouble(parts[4]);
heartBeat.reservedMemory = Double.parseDouble(parts[5]);
heartBeat.startupTime = Long.parseLong(parts[6]);
heartBeat.reportTime = Long.parseLong(parts[7]);
heartBeat.serverStatus = Integer.parseInt(parts[8]);
heartBeat.processId = Integer.parseInt(parts[9]);
heartBeat.workerHostWeight = Integer.parseInt(parts[10]);
heartBeat.workerExecThreadCount = Integer.parseInt(parts[11]);
heartBeat.workerWaitingTaskCount = Integer.parseInt(parts[12]);
heartBeat.diskAvailable = Double.parseDouble(parts[2]);
heartBeat.loadAverage = Double.parseDouble(parts[3]);
heartBeat.availablePhysicalMemorySize = Double.parseDouble(parts[4]);
heartBeat.maxCpuloadAvg = Double.parseDouble(parts[5]);
heartBeat.reservedMemory = Double.parseDouble(parts[6]);
heartBeat.startupTime = Long.parseLong(parts[7]);
heartBeat.reportTime = Long.parseLong(parts[8]);
heartBeat.serverStatus = Integer.parseInt(parts[9]);
heartBeat.processId = Integer.parseInt(parts[10]);
heartBeat.workerHostWeight = Integer.parseInt(parts[11]);
heartBeat.workerExecThreadCount = Integer.parseInt(parts[12]);
heartBeat.workerWaitingTaskCount = Integer.parseInt(parts[13]);
return heartBeat;
}
}

19
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java

@ -31,6 +31,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;
@ -82,6 +83,24 @@ public class OSUtils {
return Double.parseDouble(df.format(memoryUsage));
}
/**
* get disk usage
* Keep 2 decimal
*
* @return disk free space (GB)
*/
public static double diskAvailable() {
File file = new File(".");
long totalSpace = file.getTotalSpace(); //total disk space in bytes.
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
* <p>

7
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/os/OSUtilsTest.java

@ -39,6 +39,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();

3
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HeartBeatTest.java

@ -55,12 +55,13 @@ 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,5.86,3.09,6.47,5.0,1.0,1634033006749,1634033006857,1,29732,1,199,200";
HeartBeat heartBeat = HeartBeat.decodeHeartBeat(heartBeatInfo);
double delta = 0.001;
assertEquals(0.35, heartBeat.getCpuUsage(), delta);
assertEquals(0.58, heartBeat.getMemoryUsage(), delta);
assertEquals(5.86, heartBeat.getDiskAvailable(), delta);
assertEquals(3.09, heartBeat.getLoadAverage(), delta);
assertEquals(6.47, heartBeat.getAvailablePhysicalMemorySize(), delta);
assertEquals(5.0, heartBeat.getMaxCpuloadAvg(), delta);

16
dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/master.vue

@ -30,21 +30,31 @@
</div>
</div>
<div class="row-cont">
<div class="col-md-4">
<div class="col-md-3">
<m-gauge
:value="(item.resInfo.cpuUsage * 100).toFixed(2)"
:name="'cpuUsage'"
:id="'gauge-cpu-' + item.id">
</m-gauge>
</div>
<div class="col-md-4">
<div class="col-md-3">
<m-gauge
:value="(item.resInfo.memoryUsage * 100).toFixed(2)"
:name="'memoryUsage'"
:id="'gauge-memory-' + item.id">
</m-gauge>
</div>
<div class="col-md-4">
<div class="col-md-3">
<div class="text-num-model">
<div class="value-p">
<strong :style="{color:color[$index]}">{{item.resInfo.diskAvailable.toFixed(2)}}</strong>
</div>
<div class="text-1">
diskAvailable(GB)
</div>
</div>
</div>
<div class="col-md-3">
<div class="text-num-model">
<div class="value-p">
<strong :style="{color:color[$index]}">{{item.resInfo.loadAverage > 0? item.resInfo.loadAverage.toFixed(2):0}}</strong>

16
dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/worker.vue

@ -30,21 +30,31 @@
</div>
</div>
<div class="row-cont">
<div class="col-md-4">
<div class="col-md-3">
<m-gauge
:value="(item.resInfo.cpuUsage * 100).toFixed(2)"
:name="'cpuUsage'"
:id="'gauge-cpu-' + item.id">
</m-gauge>
</div>
<div class="col-md-4">
<div class="col-md-3">
<m-gauge
:value="(item.resInfo.memoryUsage * 100).toFixed(2)"
:name="'memoryUsage'"
:id="'gauge-memory-' + item.id">
</m-gauge>
</div>
<div class="col-md-4">
<div class="col-md-3">
<div class="text-num-model">
<div class="value-p">
<strong :style="{color:color[$index]}">{{item.resInfo.diskAvailable.toFixed(2)}}</strong>
</div>
<div class="text-1">
diskAvailable(GB)
</div>
</div>
</div>
<div class="col-md-3">
<div class="text-num-model">
<div class="value-p">
<strong :style="{color:color[$index]}">{{item.resInfo.loadAverage > 0? item.resInfo.loadAverage.toFixed(2):0}}</strong>

1
dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js

@ -197,6 +197,7 @@ export default {
'Zk registration directory': 'Zk registration directory',
cpuUsage: 'cpuUsage',
memoryUsage: 'memoryUsage',
diskAvailable: 'diskAvailable',
'Last heartbeat time': 'Last heartbeat time',
'Edit Tenant': 'Edit Tenant',
'OS Tenant Code': 'OS Tenant Code',

1
dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js

@ -196,6 +196,7 @@ export default {
'Zk registration directory': 'zk注册目录',
cpuUsage: 'cpuUsage',
memoryUsage: 'memoryUsage',
diskAvailable: 'diskAvailable',
'Last heartbeat time': '最后心跳时间',
'Edit Tenant': '编辑租户',
'OS Tenant Code': '操作系统租户',

Loading…
Cancel
Save