Skip to content

Commit bdd3ee4

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

File tree

17 files changed

+222
-141
lines changed

17 files changed

+222
-141
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.registry.api;
19+
20+
public class RegistryConstants {
21+
22+
public static final String PATH_SEPARATOR = "/";
23+
public static final char PATH_SEPARATOR_CHAR = '/';
24+
25+
}

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

Lines changed: 22 additions & 19 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

@@ -206,11 +210,10 @@ public void delete(String key) {
206210
@Override
207211
public Collection<String> children(String key) {
208212
try {
209-
List<JdbcRegistryDataDTO> children = jdbcRegistryClient.listJdbcRegistryDataChildren(key);
213+
final List<JdbcRegistryDataDTO> children = jdbcRegistryClient.listJdbcRegistryDataChildren(key);
210214
return children
211215
.stream()
212216
.map(JdbcRegistryDataDTO::getDataKey)
213-
.filter(fullPath -> fullPath.length() > key.length())
214217
.map(fullPath -> StringUtils.substringBefore(fullPath.substring(key.length() + 1), "/"))
215218
.distinct()
216219
.collect(Collectors.toList());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.dolphinscheduler.registry.api.RegistryConstants;
23+
24+
import org.apache.commons.lang3.StringUtils;
25+
26+
import lombok.experimental.UtilityClass;
27+
28+
@UtilityClass
29+
public class KeyUtils {
30+
31+
/**
32+
* Whether the path is the parent path of the child
33+
* <p> Only the parentPath is the parent path of the childPath, return true
34+
* <p> If the parentPath is equal to the childPath, return false
35+
*/
36+
public static boolean isParent(final String parentPath, final String childPath) {
37+
if (StringUtils.isEmpty(parentPath)) {
38+
throw new IllegalArgumentException("Invalid parent path " + parentPath);
39+
}
40+
if (StringUtils.isEmpty(childPath)) {
41+
throw new IllegalArgumentException("Invalid child path " + childPath);
42+
}
43+
final String[] parentSplit = parentPath.split(RegistryConstants.PATH_SEPARATOR);
44+
final String[] childSplit = childPath.split(RegistryConstants.PATH_SEPARATOR);
45+
if (parentSplit.length >= childSplit.length) {
46+
return false;
47+
}
48+
for (int i = 0; i < parentSplit.length; i++) {
49+
if (!parentSplit[i].equals(childSplit[i])) {
50+
return false;
51+
}
52+
}
53+
return true;
54+
55+
}
56+
57+
public static boolean isSamePath(final String path1, final String path2) {
58+
return removeLastSlash(path1).equals(path2);
59+
}
60+
61+
private static String removeLastSlash(final String path) {
62+
checkNotNull(path, "path is null");
63+
if (!path.startsWith(RegistryConstants.PATH_SEPARATOR)) {
64+
throw new IllegalArgumentException("Invalid path " + path);
65+
}
66+
int length = path.length() - 1;
67+
while (length >= 0 && path.charAt(length) == RegistryConstants.PATH_SEPARATOR_CHAR) {
68+
length--;
69+
}
70+
if (length == -1) {
71+
return RegistryConstants.PATH_SEPARATOR;
72+
}
73+
return path.substring(0, length + 1);
74+
}
75+
76+
}

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,41 @@
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.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
class KeyUtilsTest {
26+
27+
@Test
28+
void isParent() {
29+
assertFalse(KeyUtils.isParent("/a", "/b"));
30+
assertFalse(KeyUtils.isParent("/a", "/a"));
31+
assertFalse(KeyUtils.isParent("/b/c", "/b"));
32+
assertFalse(KeyUtils.isParent("/b/c", "/b/"));
33+
34+
assertTrue(KeyUtils.isParent("/", "/b"));
35+
assertTrue(KeyUtils.isParent("/b/c", "/b/c/d"));
36+
assertTrue(KeyUtils.isParent("/b", "/b/c/d"));
37+
assertTrue(KeyUtils.isParent("/b/", "/b/c/d"));
38+
39+
}
40+
41+
}

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: '最后心跳时间',

0 commit comments

Comments
 (0)