Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix-16903] Fix monitor page cannot display well #16968

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public AlertServerHeartBeat getHeartBeat() {
.cpuUsage(systemMetrics.getSystemCpuUsagePercentage())
.memoryUsage(systemMetrics.getSystemMemoryUsedPercentage())
.jvmMemoryUsage(systemMetrics.getJvmMemoryUsedPercentage())
.diskUsage(systemMetrics.getDiskUsedPercentage())
.serverStatus(ServerStatus.NORMAL)
.isActive(alertHAServer.isActive())
.host(NetUtils.getHost())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class MonitorController extends BaseController {
@ResponseStatus(HttpStatus.OK)
@ApiException(LIST_MASTERS_ERROR)
public Result<List<Server>> listServer(@PathVariable("nodeType") RegistryNodeType nodeType) {
List<Server> servers = monitorService.listServer(nodeType);
final List<Server> servers = monitorService.listServer(nodeType);
return Result.success(servers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public SystemMetrics getSystemMetrics() {
long totalSystemMemory = OSUtils.getTotalSystemMemory();
long systemMemoryAvailable = OSUtils.getSystemAvailableMemoryUsed();

double diskToTalBytes = meterRegistry.get("disk.total").gauge().value();
double diskFreeBytes = meterRegistry.get("disk.free").gauge().value();

systemMetrics = SystemMetrics.builder()
.systemCpuUsagePercentage(systemCpuUsage)
.jvmCpuUsagePercentage(processCpuUsage)
Expand All @@ -74,6 +77,9 @@ public SystemMetrics getSystemMetrics() {
.systemMemoryUsed(totalSystemMemory - systemMemoryAvailable)
.systemMemoryMax(totalSystemMemory)
.systemMemoryUsedPercentage((double) (totalSystemMemory - systemMemoryAvailable) / totalSystemMemory)
.diskUsed(diskToTalBytes - diskFreeBytes)
.diskTotal(diskToTalBytes)
.diskUsedPercentage((diskToTalBytes - diskFreeBytes) / diskToTalBytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing but want to make sure we store as float in stock and render as '\d %' right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will render as string by

<Gauge
    data={(
      JSON.parse(item.heartBeatInfo).diskUsage * 100
    ).toFixed(2)}
  />

It works well

image

.build();
lastRefreshTime = System.currentTimeMillis();
return systemMetrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dolphinscheduler.registry.api;

public class RegistryConstants {

public static final String PATH_SEPARATOR = "/";
public static final char PATH_SEPARATOR_CHAR = '/';

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,51 +97,55 @@ public void connectUntilTimeout(@NonNull Duration timeout) throws RegistryExcept
}

@Override
public void subscribe(String path, SubscribeListener listener) {
checkNotNull(path);
public void subscribe(String subscribePath, SubscribeListener listener) {
checkNotNull(subscribePath);
checkNotNull(listener);
jdbcRegistryClient.subscribeJdbcRegistryDataChange(new JdbcRegistryDataChangeListener() {

@Override
public void onJdbcRegistryDataChanged(String key, String value) {
if (!key.startsWith(path)) {
public void onJdbcRegistryDataChanged(String eventPath, String value) {
if (!isPathMatch(subscribePath, eventPath)) {
return;
}
Event event = Event.builder()
.key(key)
.path(path)
final Event event = Event.builder()
.key(subscribePath)
.path(eventPath)
.data(value)
.type(Event.Type.UPDATE)
.build();
listener.notify(event);
}

@Override
public void onJdbcRegistryDataDeleted(String key) {
if (!key.startsWith(path)) {
public void onJdbcRegistryDataDeleted(String eventPath) {
if (!isPathMatch(subscribePath, eventPath)) {
return;
}
Event event = Event.builder()
.key(key)
.path(key)
final Event event = Event.builder()
.key(subscribePath)
.path(eventPath)
.type(Event.Type.REMOVE)
.build();
listener.notify(event);
}

@Override
public void onJdbcRegistryDataAdded(String key, String value) {
if (!key.startsWith(path)) {
public void onJdbcRegistryDataAdded(String eventPath, String value) {
if (!isPathMatch(subscribePath, eventPath)) {
return;
}
Event event = Event.builder()
.key(key)
.path(key)
final Event event = Event.builder()
.key(subscribePath)
.path(eventPath)
.data(value)
.type(Event.Type.ADD)
.build();
listener.notify(event);
}

private boolean isPathMatch(String subscribePath, String eventPath) {
return KeyUtils.isParent(subscribePath, eventPath) || KeyUtils.isSamePath(subscribePath, eventPath);
}
});
}

Expand Down Expand Up @@ -206,11 +210,10 @@ public void delete(String key) {
@Override
public Collection<String> children(String key) {
try {
List<JdbcRegistryDataDTO> children = jdbcRegistryClient.listJdbcRegistryDataChildren(key);
final List<JdbcRegistryDataDTO> children = jdbcRegistryClient.listJdbcRegistryDataChildren(key);
return children
.stream()
.map(JdbcRegistryDataDTO::getDataKey)
.filter(fullPath -> fullPath.length() > key.length())
.map(fullPath -> StringUtils.substringBefore(fullPath.substring(key.length() + 1), "/"))
.distinct()
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dolphinscheduler.plugin.registry.jdbc;

import static com.google.common.base.Preconditions.checkNotNull;

import org.apache.dolphinscheduler.registry.api.RegistryConstants;

import org.apache.commons.lang3.StringUtils;

import lombok.experimental.UtilityClass;

@UtilityClass
public class KeyUtils {

/**
* Whether the path is the parent path of the child
* <p> Only the parentPath is the parent path of the childPath, return true
* <p> If the parentPath is equal to the childPath, return false
*/
public static boolean isParent(final String parentPath, final String childPath) {
if (StringUtils.isEmpty(parentPath)) {
throw new IllegalArgumentException("Invalid parent path " + parentPath);
}
if (StringUtils.isEmpty(childPath)) {
throw new IllegalArgumentException("Invalid child path " + childPath);
}
final String[] parentSplit = parentPath.split(RegistryConstants.PATH_SEPARATOR);
final String[] childSplit = childPath.split(RegistryConstants.PATH_SEPARATOR);
if (parentSplit.length >= childSplit.length) {
return false;
}
for (int i = 0; i < parentSplit.length; i++) {
if (!parentSplit[i].equals(childSplit[i])) {
return false;
}
}
return true;

}

public static boolean isSamePath(final String path1, final String path2) {
return removeLastSlash(path1).equals(path2);
}

private static String removeLastSlash(final String path) {
checkNotNull(path, "path is null");
if (!path.startsWith(RegistryConstants.PATH_SEPARATOR)) {
throw new IllegalArgumentException("Invalid path " + path);
}
int length = path.length() - 1;
while (length >= 0 && path.charAt(length) == RegistryConstants.PATH_SEPARATOR_CHAR) {
length--;
}
if (length == -1) {
return RegistryConstants.PATH_SEPARATOR;
}
return path.substring(0, length + 1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryProperties;
import org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryThreadFactory;
import org.apache.dolphinscheduler.plugin.registry.jdbc.KeyUtils;
import org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.DataType;
import org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryDataChanceEventDTO;
import org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryDataDTO;
Expand Down Expand Up @@ -147,12 +148,11 @@ public Optional<JdbcRegistryDataDTO> getRegistryDataByKey(String key) {
}

@Override
public List<JdbcRegistryDataDTO> listJdbcRegistryDataChildren(String key) {
public List<JdbcRegistryDataDTO> listJdbcRegistryDataChildren(final String key) {
checkNotNull(key);
return jdbcRegistryDataRepository.selectAll()
.stream()
.filter(jdbcRegistryDataDTO -> jdbcRegistryDataDTO.getDataKey().startsWith(key)
&& !jdbcRegistryDataDTO.getDataKey().equals(key))
.filter(jdbcRegistryDataDTO -> KeyUtils.isParent(key, jdbcRegistryDataDTO.getDataKey()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dolphinscheduler.plugin.registry.jdbc;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

class KeyUtilsTest {

@Test
void isParent() {
assertFalse(KeyUtils.isParent("/a", "/b"));
assertFalse(KeyUtils.isParent("/a", "/a"));
assertFalse(KeyUtils.isParent("/b/c", "/b"));
assertFalse(KeyUtils.isParent("/b/c", "/b/"));

assertTrue(KeyUtils.isParent("/", "/b"));
assertTrue(KeyUtils.isParent("/b/c", "/b/c/d"));
assertTrue(KeyUtils.isParent("/b", "/b/c/d"));
assertTrue(KeyUtils.isParent("/b/", "/b/c/d"));

}

}
6 changes: 2 additions & 4 deletions dolphinscheduler-ui/src/locales/en_US/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default {
master: {
cpu_usage: 'CPU Usage',
memory_usage: 'Memory Usage',
disk_available: 'Disk Available',
load_average: 'Load Average',
disk_usage: 'Disk Usage',
create_time: 'Create Time',
last_heartbeat_time: 'Last Heartbeat Time',
directory_detail: 'Directory Detail',
Expand All @@ -33,8 +32,7 @@ export default {
worker: {
cpu_usage: 'CPU Usage',
memory_usage: 'Memory Usage',
disk_available: 'Disk Available',
load_average: 'Load Average',
disk_usage: 'Disk Usage',
thread_pool_usage: 'Thread Pool Usage',
create_time: 'Create Time',
last_heartbeat_time: 'Last Heartbeat Time',
Expand Down
6 changes: 2 additions & 4 deletions dolphinscheduler-ui/src/locales/zh_CN/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default {
master: {
cpu_usage: '处理器使用量',
memory_usage: '内存使用量',
disk_available: '磁盘可用容量',
load_average: '平均负载量',
disk_usage: '磁盘使用量',
create_time: '创建时间',
last_heartbeat_time: '最后心跳时间',
directory_detail: '目录详情',
Expand All @@ -33,8 +32,7 @@ export default {
worker: {
cpu_usage: '处理器使用量',
memory_usage: '内存使用量',
disk_available: '磁盘可用容量',
load_average: '平均负载量',
disk_usage: '磁盘使用量',
thread_pool_usage: '线程池使用量',
create_time: '创建时间',
last_heartbeat_time: '最后心跳时间',
Expand Down
4 changes: 2 additions & 2 deletions dolphinscheduler-ui/src/service/modules/monitor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ interface ServerNode {
id: number
host: string
port: number
zkDirectory: string
resInfo: string
serverDirectory: string
heartBeatInfo: string
createTime: string
lastHeartbeatTime: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
@include base;
}

.load-average {
@include base;
color: var(--n-color-target);
}

.link-btn {
color: var(--n-color-target);
cursor: pointer;
Expand Down
Loading
Loading