From 9e27d4bb4b8df199f4c9204c8b1a8c951c3a240d Mon Sep 17 00:00:00 2001 From: gaoxq <376340421@qq.com> Date: Sun, 30 Nov 2025 19:12:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jeesite/modules/app/Job/hostJob.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/web-api/src/main/java/com/jeesite/modules/app/Job/hostJob.java b/web-api/src/main/java/com/jeesite/modules/app/Job/hostJob.java index 6d26f1f1..c7df5a2c 100644 --- a/web-api/src/main/java/com/jeesite/modules/app/Job/hostJob.java +++ b/web-api/src/main/java/com/jeesite/modules/app/Job/hostJob.java @@ -58,10 +58,10 @@ public class hostJob { boolean isReachable = NetworkUtils.isNetworkReachable(monitorHost.getIpAddress()); monitorHost.setUstatus(isReachable ? "1" : "0"); if (isReachable) { - monitorHost.setLastOnlineTime(new Date()); syncServerInfo(monitorHost); + monitorHost.setLastOnlineTime(new Date()); } - monitorHostService.update(monitorHost); + monitorHostService.save(monitorHost); }, hostMonitorExecutor); // 指定使用配置的线程池 futures.add(future); } @@ -79,19 +79,21 @@ public class hostJob { BizMonitorAccount monitorAccount = new BizMonitorAccount(); monitorAccount.setHostId(host.getHostId()); monitorAccount.setSshUsername("ogsapp"); - BizMonitorAccount account = accountService.get(monitorAccount); - CpuInfo cpuInfo = SystemUtil.getCpuMemUsage(host.getIpAddress(), account.getSshPort(), account.getSshUsername(), vo.getDecode(account.getSshPassword())); - ServerInfo info = SystemUtil.getServerBasicInfo(host.getIpAddress(), account.getSshPort(), account.getSshUsername(), vo.getDecode(account.getSshPassword()), host.getIpAddress()); - List diskInfos = SystemUtil.getDiskInfos(host.getIpAddress(), account.getSshPort(), account.getSshUsername(), vo.getDecode(account.getSshPassword())); - BizServerInfo bizServerInfo = new BizServerInfo(); - bizServerInfo.setHostId(host.getHostId()); - BizServerInfo serverInfo = serverInfoService.get(bizServerInfo); - if (serverInfo.getIsNewRecord()) { - getServerInfo(cpuInfo, info, bizServerInfo); - } else { - getServerInfo(cpuInfo, info, serverInfo); + List account = accountService.findList(monitorAccount); + if (account.size() > 0) { + CpuInfo cpuInfo = SystemUtil.getCpuMemUsage(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword())); + ServerInfo info = SystemUtil.getServerBasicInfo(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword()), host.getIpAddress()); + List diskInfos = SystemUtil.getDiskInfos(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword())); + BizServerInfo bizServerInfo = new BizServerInfo(); + bizServerInfo.setHostId(host.getHostId()); + List serverInfo = serverInfoService.findList(bizServerInfo); + if (serverInfo.get(0).getIsNewRecord()) { + getServerInfo(cpuInfo, info, bizServerInfo); + } else { + getServerInfo(cpuInfo, info, serverInfo.get(0)); + } + syncDeviceInfo(host, diskInfos); } - syncDeviceInfo(host, diskInfos); } catch (Exception e) { logger.error(e.getMessage()); } @@ -105,19 +107,19 @@ public class hostJob { bizDeviceInfo.setHostId(host.getHostId()); bizDeviceInfo.setDevice(diskInfo.getDevice()); bizDeviceInfo.setMountPoint(diskInfo.getMountPoint()); - BizDeviceInfo deviceInfo = deviceInfoService.get(bizDeviceInfo); - if (deviceInfo.getIsNewRecord()) { + List deviceInfo = deviceInfoService.findList(bizDeviceInfo); + if (deviceInfo.get(0).getIsNewRecord()) { bizDeviceInfo.setTotalSize(diskInfo.getTotalSize()); bizDeviceInfo.setUsedSize(diskInfo.getUsedSize()); bizDeviceInfo.setUsageRate(diskInfo.getUsageRate()); bizDeviceInfo.setLastOnlineTime(new Date()); deviceInfoService.save(bizDeviceInfo); } else { - deviceInfo.setTotalSize(diskInfo.getTotalSize()); - deviceInfo.setUsedSize(diskInfo.getUsedSize()); - deviceInfo.setUsageRate(diskInfo.getUsageRate()); - deviceInfo.setLastOnlineTime(new Date()); - deviceInfoService.save(deviceInfo); + deviceInfo.get(0).setTotalSize(diskInfo.getTotalSize()); + deviceInfo.get(0).setUsedSize(diskInfo.getUsedSize()); + deviceInfo.get(0).setUsageRate(diskInfo.getUsageRate()); + deviceInfo.get(0).setLastOnlineTime(new Date()); + deviceInfoService.save(deviceInfo.get(0)); } } } catch (Exception e) { @@ -135,6 +137,7 @@ public class hostJob { serverInfo.setCpuModel(info.getCpuModel()); serverInfo.setCpuUsage(cpuInfo.getCpuUsage()); serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage()); + serverInfo.setLastOnlineTime(new Date()); serverInfoService.save(serverInfo); } }