This commit is contained in:
2025-11-30 21:47:38 +08:00
parent 9e27d4bb4b
commit 25ed2391e9
5 changed files with 57 additions and 59 deletions

View File

@@ -16,15 +16,15 @@ import com.jeesite.modules.app.utils.LoggerUtils;
import com.jeesite.modules.app.utils.NetworkUtils;
import com.jeesite.modules.biz.service.BizServerInfoService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Controller
public class hostJob {
@@ -73,71 +73,66 @@ public class hostJob {
}
}
private void syncServerInfo(BizMonitorHost host) {
try {
BizMonitorAccount monitorAccount = new BizMonitorAccount();
monitorAccount.setHostId(host.getHostId());
monitorAccount.setSshUsername("ogsapp");
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()));
/**
* 运行信息更新
*/
public void syncServerInfo(BizMonitorHost host) {
BizMonitorAccount monitorAccount = new BizMonitorAccount();
monitorAccount.setHostId(host.getHostId());
monitorAccount.setSshUsername("ogsapp");
List<BizMonitorAccount> accountList = accountService.findList(monitorAccount);
if (accountList.size() > 0) {
try {
BizMonitorAccount account = accountList.get(0);
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()));
syncDeviceInfo(host, diskInfos);
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);
List<BizServerInfo> serverInfoList = serverInfoService.findList(bizServerInfo);
BizServerInfo serverInfo = serverInfoList.isEmpty() ? new BizServerInfo() : serverInfoList.get(0);
serverInfo.setUptime(info.getUptime());
serverInfo.setOs(info.getOs());
serverInfo.setKernelVersion(info.getKernelVersion());
serverInfo.setHostname(info.getHostname());
serverInfo.setIpAddress(info.getIpAddress());
serverInfo.setCpuModel(info.getCpuModel());
serverInfo.setCpuUsage(cpuInfo.getCpuUsage());
serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage());
serverInfo.setLastOnlineTime(new Date());
serverInfo.setHostId(host.getHostId());
serverInfoService.save(serverInfo);
} catch (Exception e) {
logger.error(e.getMessage());
}
} catch (Exception e) {
logger.error(e.getMessage());
}
}
private void syncDeviceInfo(BizMonitorHost host, List<DiskInfo> diskInfos) {
try {
for (DiskInfo diskInfo : diskInfos) {
/**
* 主机磁盘监测
*/
public void syncDeviceInfo(BizMonitorHost host, List<DiskInfo> diskInfos) {
for (DiskInfo diskInfo : diskInfos) {
try {
BizDeviceInfo bizDeviceInfo = new BizDeviceInfo();
bizDeviceInfo.setHostId(host.getHostId());
bizDeviceInfo.setDevice(diskInfo.getDevice());
bizDeviceInfo.setMountPoint(diskInfo.getMountPoint());
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.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));
}
List<BizDeviceInfo> deviceInfoList = deviceInfoService.findList(bizDeviceInfo);
BizDeviceInfo deviceInfo = deviceInfoList.isEmpty() ? new BizDeviceInfo() : deviceInfoList.get(0);
deviceInfo.setHostId(host.getHostId());
deviceInfo.setDevice(diskInfo.getDevice());
deviceInfo.setMountPoint(diskInfo.getMountPoint());
deviceInfo.setTotalSize(diskInfo.getTotalSize());
deviceInfo.setUsedSize(diskInfo.getUsedSize());
deviceInfo.setUsageRate(diskInfo.getUsageRate());
deviceInfo.setLastOnlineTime(new Date());
deviceInfoService.save(deviceInfo);
} catch (Exception e) {
logger.error(e.getMessage());
}
} catch (Exception e) {
logger.error(e.getMessage());
}
}
private void getServerInfo(CpuInfo cpuInfo, ServerInfo info, BizServerInfo serverInfo) {
serverInfo.setUptime(info.getUptime());
serverInfo.setOs(info.getOs());
serverInfo.setKernelVersion(info.getKernelVersion());
serverInfo.setHostname(info.getHostname());
serverInfo.setIpAddress(info.getIpAddress());
serverInfo.setCpuModel(info.getCpuModel());
serverInfo.setCpuUsage(cpuInfo.getCpuUsage());
serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage());
serverInfo.setLastOnlineTime(new Date());
serverInfoService.save(serverInfo);
}
}

View File

@@ -32,8 +32,8 @@ import java.io.Serial;
@Table(name = "biz_device_info", alias = "a", label = "磁盘信息信息", columns = {
@Column(name = "create_time", attrName = "createTime", label = "记录时间", isUpdateForce = true),
@Column(name = "id", attrName = "id", label = "主键标识", isPK = true),
@Column(name = "device", attrName = "device", label = "设备名称", isQuery = false),
@Column(name = "mount_point", attrName = "mountPoint", label = "挂载点", isQuery = false),
@Column(name = "device", attrName = "device", label = "设备名称"),
@Column(name = "mount_point", attrName = "mountPoint", label = "挂载点"),
@Column(name = "total_size", attrName = "totalSize", label = "总容量", isQuery = false),
@Column(name = "used_size", attrName = "usedSize", label = "已使用容量", isQuery = false),
@Column(name = "usage_rate", attrName = "usageRate", label = "使用率", comment = "使用率(%)", isQuery = false),

View File

@@ -89,6 +89,7 @@
sorter: true,
width: 180,
align: 'left',
fixed: 'left',
},
{
title: t('主机名称'),

View File

@@ -122,6 +122,7 @@
sorter: true,
width: 230,
align: 'left',
fixed: 'left',
},
{
title: t('主机名称'),

View File

@@ -109,6 +109,7 @@
sorter: true,
width: 180,
align: 'left',
fixed: 'left',
},
{
title: t('运行时长'),