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()); boolean isReachable = NetworkUtils.isNetworkReachable(monitorHost.getIpAddress());
monitorHost.setUstatus(isReachable ? "1" : "0"); monitorHost.setUstatus(isReachable ? "1" : "0");
if (isReachable) { if (isReachable) {
monitorHost.setLastOnlineTime(new Date());
syncServerInfo(monitorHost); syncServerInfo(monitorHost);
monitorHost.setLastOnlineTime(new Date());
} }
monitorHostService.update(monitorHost); monitorHostService.save(monitorHost);
}, hostMonitorExecutor); // 指定使用配置的线程池 }, hostMonitorExecutor); // 指定使用配置的线程池
futures.add(future); futures.add(future);
} }
@@ -79,19 +79,21 @@ public class hostJob {
BizMonitorAccount monitorAccount = new BizMonitorAccount(); BizMonitorAccount monitorAccount = new BizMonitorAccount();
monitorAccount.setHostId(host.getHostId()); monitorAccount.setHostId(host.getHostId());
monitorAccount.setSshUsername("ogsapp"); monitorAccount.setSshUsername("ogsapp");
BizMonitorAccount account = accountService.get(monitorAccount); List<BizMonitorAccount> account = accountService.findList(monitorAccount);
CpuInfo cpuInfo = SystemUtil.getCpuMemUsage(host.getIpAddress(), account.getSshPort(), account.getSshUsername(), vo.getDecode(account.getSshPassword())); if (account.size() > 0) {
ServerInfo info = SystemUtil.getServerBasicInfo(host.getIpAddress(), account.getSshPort(), account.getSshUsername(), vo.getDecode(account.getSshPassword()), host.getIpAddress()); CpuInfo cpuInfo = SystemUtil.getCpuMemUsage(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword()));
List<DiskInfo> diskInfos = SystemUtil.getDiskInfos(host.getIpAddress(), account.getSshPort(), account.getSshUsername(), vo.getDecode(account.getSshPassword())); ServerInfo info = SystemUtil.getServerBasicInfo(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword()), host.getIpAddress());
BizServerInfo bizServerInfo = new BizServerInfo(); List<DiskInfo> diskInfos = SystemUtil.getDiskInfos(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword()));
bizServerInfo.setHostId(host.getHostId()); BizServerInfo bizServerInfo = new BizServerInfo();
BizServerInfo serverInfo = serverInfoService.get(bizServerInfo); bizServerInfo.setHostId(host.getHostId());
if (serverInfo.getIsNewRecord()) { List<BizServerInfo> serverInfo = serverInfoService.findList(bizServerInfo);
getServerInfo(cpuInfo, info, bizServerInfo); if (serverInfo.get(0).getIsNewRecord()) {
} else { getServerInfo(cpuInfo, info, bizServerInfo);
getServerInfo(cpuInfo, info, serverInfo); } else {
getServerInfo(cpuInfo, info, serverInfo.get(0));
}
syncDeviceInfo(host, diskInfos);
} }
syncDeviceInfo(host, diskInfos);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
} }
@@ -105,19 +107,19 @@ public class hostJob {
bizDeviceInfo.setHostId(host.getHostId()); bizDeviceInfo.setHostId(host.getHostId());
bizDeviceInfo.setDevice(diskInfo.getDevice()); bizDeviceInfo.setDevice(diskInfo.getDevice());
bizDeviceInfo.setMountPoint(diskInfo.getMountPoint()); bizDeviceInfo.setMountPoint(diskInfo.getMountPoint());
BizDeviceInfo deviceInfo = deviceInfoService.get(bizDeviceInfo); List<BizDeviceInfo> deviceInfo = deviceInfoService.findList(bizDeviceInfo);
if (deviceInfo.getIsNewRecord()) { if (deviceInfo.get(0).getIsNewRecord()) {
bizDeviceInfo.setTotalSize(diskInfo.getTotalSize()); bizDeviceInfo.setTotalSize(diskInfo.getTotalSize());
bizDeviceInfo.setUsedSize(diskInfo.getUsedSize()); bizDeviceInfo.setUsedSize(diskInfo.getUsedSize());
bizDeviceInfo.setUsageRate(diskInfo.getUsageRate()); bizDeviceInfo.setUsageRate(diskInfo.getUsageRate());
bizDeviceInfo.setLastOnlineTime(new Date()); bizDeviceInfo.setLastOnlineTime(new Date());
deviceInfoService.save(bizDeviceInfo); deviceInfoService.save(bizDeviceInfo);
} else { } else {
deviceInfo.setTotalSize(diskInfo.getTotalSize()); deviceInfo.get(0).setTotalSize(diskInfo.getTotalSize());
deviceInfo.setUsedSize(diskInfo.getUsedSize()); deviceInfo.get(0).setUsedSize(diskInfo.getUsedSize());
deviceInfo.setUsageRate(diskInfo.getUsageRate()); deviceInfo.get(0).setUsageRate(diskInfo.getUsageRate());
deviceInfo.setLastOnlineTime(new Date()); deviceInfo.get(0).setLastOnlineTime(new Date());
deviceInfoService.save(deviceInfo); deviceInfoService.save(deviceInfo.get(0));
} }
} }
} catch (Exception e) { } catch (Exception e) {
@@ -135,6 +137,7 @@ public class hostJob {
serverInfo.setCpuModel(info.getCpuModel()); serverInfo.setCpuModel(info.getCpuModel());
serverInfo.setCpuUsage(cpuInfo.getCpuUsage()); serverInfo.setCpuUsage(cpuInfo.getCpuUsage());
serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage()); serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage());
serverInfo.setLastOnlineTime(new Date());
serverInfoService.save(serverInfo); serverInfoService.save(serverInfo);
} }
} }