Skip to content

Commit 02f0164

Browse files
committed
[Fix-16903] Fix monitor page cannot display well
1 parent 2ae4402 commit 02f0164

File tree

16 files changed

+201
-139
lines changed

16 files changed

+201
-139
lines changed

dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/registry/AlertHeartbeatTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public AlertServerHeartBeat getHeartBeat() {
7575
.cpuUsage(systemMetrics.getSystemCpuUsagePercentage())
7676
.memoryUsage(systemMetrics.getSystemMemoryUsedPercentage())
7777
.jvmMemoryUsage(systemMetrics.getJvmMemoryUsedPercentage())
78+
.diskUsage(systemMetrics.getDiskUsedPercentage())
7879
.serverStatus(ServerStatus.NORMAL)
7980
.isActive(alertHAServer.isActive())
8081
.host(NetUtils.getHost())

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class MonitorController extends BaseController {
6565
@ResponseStatus(HttpStatus.OK)
6666
@ApiException(LIST_MASTERS_ERROR)
6767
public Result<List<Server>> listServer(@PathVariable("nodeType") RegistryNodeType nodeType) {
68-
List<Server> servers = monitorService.listServer(nodeType);
68+
final List<Server> servers = monitorService.listServer(nodeType);
6969
return Result.success(servers);
7070
}
7171

dolphinscheduler-meter/src/main/java/org/apache/dolphinscheduler/meter/metrics/DefaultMetricsProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public SystemMetrics getSystemMetrics() {
6565
long totalSystemMemory = OSUtils.getTotalSystemMemory();
6666
long systemMemoryAvailable = OSUtils.getSystemAvailableMemoryUsed();
6767

68+
double diskToTalBytes = meterRegistry.get("disk.total").gauge().value();
69+
double diskFreeBytes = meterRegistry.get("disk.free").gauge().value();
70+
6871
systemMetrics = SystemMetrics.builder()
6972
.systemCpuUsagePercentage(systemCpuUsage)
7073
.jvmCpuUsagePercentage(processCpuUsage)
@@ -74,6 +77,9 @@ public SystemMetrics getSystemMetrics() {
7477
.systemMemoryUsed(totalSystemMemory - systemMemoryAvailable)
7578
.systemMemoryMax(totalSystemMemory)
7679
.systemMemoryUsedPercentage((double) (totalSystemMemory - systemMemoryAvailable) / totalSystemMemory)
80+
.diskUsed(diskToTalBytes - diskFreeBytes)
81+
.diskTotal(diskToTalBytes)
82+
.diskUsedPercentage((diskToTalBytes - diskFreeBytes) / diskToTalBytes)
7783
.build();
7884
lastRefreshTime = System.currentTimeMillis();
7985
return systemMetrics;

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistry.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,51 +97,55 @@ public void connectUntilTimeout(@NonNull Duration timeout) throws RegistryExcept
9797
}
9898

9999
@Override
100-
public void subscribe(String path, SubscribeListener listener) {
101-
checkNotNull(path);
100+
public void subscribe(String subscribePath, SubscribeListener listener) {
101+
checkNotNull(subscribePath);
102102
checkNotNull(listener);
103103
jdbcRegistryClient.subscribeJdbcRegistryDataChange(new JdbcRegistryDataChangeListener() {
104104

105105
@Override
106-
public void onJdbcRegistryDataChanged(String key, String value) {
107-
if (!key.startsWith(path)) {
106+
public void onJdbcRegistryDataChanged(String eventPath, String value) {
107+
if (!isPathMatch(subscribePath, eventPath)) {
108108
return;
109109
}
110-
Event event = Event.builder()
111-
.key(key)
112-
.path(path)
110+
final Event event = Event.builder()
111+
.key(subscribePath)
112+
.path(eventPath)
113113
.data(value)
114114
.type(Event.Type.UPDATE)
115115
.build();
116116
listener.notify(event);
117117
}
118118

119119
@Override
120-
public void onJdbcRegistryDataDeleted(String key) {
121-
if (!key.startsWith(path)) {
120+
public void onJdbcRegistryDataDeleted(String eventPath) {
121+
if (!isPathMatch(subscribePath, eventPath)) {
122122
return;
123123
}
124-
Event event = Event.builder()
125-
.key(key)
126-
.path(key)
124+
final Event event = Event.builder()
125+
.key(subscribePath)
126+
.path(eventPath)
127127
.type(Event.Type.REMOVE)
128128
.build();
129129
listener.notify(event);
130130
}
131131

132132
@Override
133-
public void onJdbcRegistryDataAdded(String key, String value) {
134-
if (!key.startsWith(path)) {
133+
public void onJdbcRegistryDataAdded(String eventPath, String value) {
134+
if (!isPathMatch(subscribePath, eventPath)) {
135135
return;
136136
}
137-
Event event = Event.builder()
138-
.key(key)
139-
.path(key)
137+
final Event event = Event.builder()
138+
.key(subscribePath)
139+
.path(eventPath)
140140
.data(value)
141141
.type(Event.Type.ADD)
142142
.build();
143143
listener.notify(event);
144144
}
145+
146+
private boolean isPathMatch(String subscribePath, String eventPath) {
147+
return KeyUtils.isParent(subscribePath, eventPath) || KeyUtils.isSamePath(subscribePath, eventPath);
148+
}
145149
});
146150
}
147151

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dolphinscheduler.plugin.registry.jdbc;
19+
20+
import static com.google.common.base.Preconditions.checkNotNull;
21+
22+
import org.apache.commons.lang3.StringUtils;
23+
24+
import lombok.experimental.UtilityClass;
25+
26+
@UtilityClass
27+
public class KeyUtils {
28+
29+
/**
30+
* Whether the path is the parent path of the child
31+
* <p> Only the parentPath is the parent path of the childPath, return true
32+
* <p> If the parentPath is equal to the childPath, return false
33+
*/
34+
public static boolean isParent(final String parentPath, final String childPath) {
35+
if (StringUtils.isEmpty(parentPath)) {
36+
throw new IllegalArgumentException("Invalid parent path string " + parentPath);
37+
}
38+
if (StringUtils.isEmpty(childPath)) {
39+
throw new IllegalArgumentException("Invalid child path string " + childPath);
40+
}
41+
final String standardParentPath = removeLastSlash(parentPath);
42+
final String standardChildPath = removeLastSlash(childPath);
43+
return standardParentPath.equals(getParentPath(standardChildPath))
44+
&& !standardParentPath.equals(standardChildPath);
45+
}
46+
47+
public static boolean isSamePath(final String path1, final String path2) {
48+
return removeLastSlash(path1).equals(path2);
49+
}
50+
51+
public static String getParentPath(final String path) {
52+
if (StringUtils.isEmpty(path)) {
53+
throw new IllegalArgumentException("Invalid path string " + path);
54+
}
55+
final String standardPath = removeLastSlash(path);
56+
if ("/".equals(standardPath)) {
57+
return path;
58+
}
59+
return StringUtils.substringBeforeLast(path, "/");
60+
}
61+
62+
private static String removeLastSlash(final String path) {
63+
checkNotNull(path, "path is null");
64+
if (!path.startsWith("/")) {
65+
throw new IllegalArgumentException("Invalid path string " + path);
66+
}
67+
int length = path.length() - 1;
68+
while (length >= 0 && path.charAt(length) == '/') {
69+
length--;
70+
}
71+
if (length == -1) {
72+
return "/";
73+
}
74+
return path.substring(0, length + 1);
75+
}
76+
77+
}

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryDataManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryProperties;
2323
import org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryThreadFactory;
24+
import org.apache.dolphinscheduler.plugin.registry.jdbc.KeyUtils;
2425
import org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.DataType;
2526
import org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryDataChanceEventDTO;
2627
import org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryDataDTO;
@@ -147,12 +148,11 @@ public Optional<JdbcRegistryDataDTO> getRegistryDataByKey(String key) {
147148
}
148149

149150
@Override
150-
public List<JdbcRegistryDataDTO> listJdbcRegistryDataChildren(String key) {
151+
public List<JdbcRegistryDataDTO> listJdbcRegistryDataChildren(final String key) {
151152
checkNotNull(key);
152153
return jdbcRegistryDataRepository.selectAll()
153154
.stream()
154-
.filter(jdbcRegistryDataDTO -> jdbcRegistryDataDTO.getDataKey().startsWith(key)
155-
&& !jdbcRegistryDataDTO.getDataKey().equals(key))
155+
.filter(jdbcRegistryDataDTO -> KeyUtils.isParent(key, jdbcRegistryDataDTO.getDataKey()))
156156
.collect(Collectors.toList());
157157
}
158158

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dolphinscheduler.plugin.registry.jdbc;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
class KeyUtilsTest {
27+
28+
@Test
29+
void isParent() {
30+
assertFalse(KeyUtils.isParent("/a", "/b"));
31+
assertFalse(KeyUtils.isParent("/a", "/a"));
32+
assertFalse(KeyUtils.isParent("/b/c", "/b"));
33+
34+
assertTrue(KeyUtils.isParent("/", "/b"));
35+
assertTrue(KeyUtils.isParent("/b/c", "/b/c/d"));
36+
37+
}
38+
39+
@Test
40+
void getParentPath() {
41+
assertEquals("/b", KeyUtils.getParentPath("/b/c"));
42+
assertEquals("/b/c", KeyUtils.getParentPath("/b/c/d"));
43+
assertEquals("/", KeyUtils.getParentPath("/"));
44+
}
45+
}

dolphinscheduler-ui/src/locales/en_US/monitor.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export default {
1919
master: {
2020
cpu_usage: 'CPU Usage',
2121
memory_usage: 'Memory Usage',
22-
disk_available: 'Disk Available',
23-
load_average: 'Load Average',
22+
disk_usage: 'Disk Usage',
2423
create_time: 'Create Time',
2524
last_heartbeat_time: 'Last Heartbeat Time',
2625
directory_detail: 'Directory Detail',
@@ -33,8 +32,7 @@ export default {
3332
worker: {
3433
cpu_usage: 'CPU Usage',
3534
memory_usage: 'Memory Usage',
36-
disk_available: 'Disk Available',
37-
load_average: 'Load Average',
35+
disk_usage: 'Disk Usage',
3836
thread_pool_usage: 'Thread Pool Usage',
3937
create_time: 'Create Time',
4038
last_heartbeat_time: 'Last Heartbeat Time',

dolphinscheduler-ui/src/locales/zh_CN/monitor.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export default {
1919
master: {
2020
cpu_usage: '处理器使用量',
2121
memory_usage: '内存使用量',
22-
disk_available: '磁盘可用容量',
23-
load_average: '平均负载量',
22+
disk_usage: '磁盘使用量',
2423
create_time: '创建时间',
2524
last_heartbeat_time: '最后心跳时间',
2625
directory_detail: '目录详情',
@@ -33,8 +32,7 @@ export default {
3332
worker: {
3433
cpu_usage: '处理器使用量',
3534
memory_usage: '内存使用量',
36-
disk_available: '磁盘可用容量',
37-
load_average: '平均负载量',
35+
disk_usage: '磁盘使用量',
3836
thread_pool_usage: '线程池使用量',
3937
create_time: '创建时间',
4038
last_heartbeat_time: '最后心跳时间',

dolphinscheduler-ui/src/service/modules/monitor/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ interface ServerNode {
3131
id: number
3232
host: string
3333
port: number
34-
zkDirectory: string
35-
resInfo: string
34+
serverDirectory: string
35+
heartBeatInfo: string
3636
createTime: string
3737
lastHeartbeatTime: string
3838
}

0 commit comments

Comments
 (0)