This commit is contained in:
2025-11-30 19:12:59 +08:00
parent 71cc66ea9b
commit 9e27d4bb4b

View File

@@ -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<DiskInfo> 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<BizMonitorAccount> 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<DiskInfo> 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<BizServerInfo> 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<BizDeviceInfo> 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);
}
}