修改
This commit is contained in:
@@ -16,15 +16,15 @@ import com.jeesite.modules.app.utils.LoggerUtils;
|
|||||||
import com.jeesite.modules.app.utils.NetworkUtils;
|
import com.jeesite.modules.app.utils.NetworkUtils;
|
||||||
import com.jeesite.modules.biz.service.BizServerInfoService;
|
import com.jeesite.modules.biz.service.BizServerInfoService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class hostJob {
|
public class hostJob {
|
||||||
@@ -73,62 +73,25 @@ public class hostJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
private void syncServerInfo(BizMonitorHost host) {
|
* 运行信息更新
|
||||||
try {
|
*/
|
||||||
|
public void syncServerInfo(BizMonitorHost host) {
|
||||||
BizMonitorAccount monitorAccount = new BizMonitorAccount();
|
BizMonitorAccount monitorAccount = new BizMonitorAccount();
|
||||||
monitorAccount.setHostId(host.getHostId());
|
monitorAccount.setHostId(host.getHostId());
|
||||||
monitorAccount.setSshUsername("ogsapp");
|
monitorAccount.setSshUsername("ogsapp");
|
||||||
List<BizMonitorAccount> account = accountService.findList(monitorAccount);
|
List<BizMonitorAccount> accountList = accountService.findList(monitorAccount);
|
||||||
if (account.size() > 0) {
|
if (accountList.size() > 0) {
|
||||||
CpuInfo cpuInfo = SystemUtil.getCpuMemUsage(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword()));
|
try {
|
||||||
ServerInfo info = SystemUtil.getServerBasicInfo(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword()), host.getIpAddress());
|
BizMonitorAccount account = accountList.get(0);
|
||||||
List<DiskInfo> diskInfos = SystemUtil.getDiskInfos(host.getIpAddress(), account.get(0).getSshPort(), account.get(0).getSshUsername(), vo.getDecode(account.get(0).getSshPassword()));
|
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 bizServerInfo = new BizServerInfo();
|
||||||
bizServerInfo.setHostId(host.getHostId());
|
bizServerInfo.setHostId(host.getHostId());
|
||||||
List<BizServerInfo> serverInfo = serverInfoService.findList(bizServerInfo);
|
List<BizServerInfo> serverInfoList = serverInfoService.findList(bizServerInfo);
|
||||||
if (serverInfo.get(0).getIsNewRecord()) {
|
BizServerInfo serverInfo = serverInfoList.isEmpty() ? new BizServerInfo() : serverInfoList.get(0);
|
||||||
getServerInfo(cpuInfo, info, bizServerInfo);
|
|
||||||
} else {
|
|
||||||
getServerInfo(cpuInfo, info, serverInfo.get(0));
|
|
||||||
}
|
|
||||||
syncDeviceInfo(host, diskInfos);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void syncDeviceInfo(BizMonitorHost host, List<DiskInfo> diskInfos) {
|
|
||||||
try {
|
|
||||||
for (DiskInfo diskInfo : diskInfos) {
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void getServerInfo(CpuInfo cpuInfo, ServerInfo info, BizServerInfo serverInfo) {
|
|
||||||
serverInfo.setUptime(info.getUptime());
|
serverInfo.setUptime(info.getUptime());
|
||||||
serverInfo.setOs(info.getOs());
|
serverInfo.setOs(info.getOs());
|
||||||
serverInfo.setKernelVersion(info.getKernelVersion());
|
serverInfo.setKernelVersion(info.getKernelVersion());
|
||||||
@@ -138,6 +101,38 @@ public class hostJob {
|
|||||||
serverInfo.setCpuUsage(cpuInfo.getCpuUsage());
|
serverInfo.setCpuUsage(cpuInfo.getCpuUsage());
|
||||||
serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage());
|
serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage());
|
||||||
serverInfo.setLastOnlineTime(new Date());
|
serverInfo.setLastOnlineTime(new Date());
|
||||||
|
serverInfo.setHostId(host.getHostId());
|
||||||
serverInfoService.save(serverInfo);
|
serverInfoService.save(serverInfo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主机磁盘监测
|
||||||
|
*/
|
||||||
|
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> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ import java.io.Serial;
|
|||||||
@Table(name = "biz_device_info", alias = "a", label = "磁盘信息信息", columns = {
|
@Table(name = "biz_device_info", alias = "a", label = "磁盘信息信息", columns = {
|
||||||
@Column(name = "create_time", attrName = "createTime", label = "记录时间", isUpdateForce = true),
|
@Column(name = "create_time", attrName = "createTime", label = "记录时间", isUpdateForce = true),
|
||||||
@Column(name = "id", attrName = "id", label = "主键标识", isPK = true),
|
@Column(name = "id", attrName = "id", label = "主键标识", isPK = true),
|
||||||
@Column(name = "device", attrName = "device", label = "设备名称", isQuery = false),
|
@Column(name = "device", attrName = "device", label = "设备名称"),
|
||||||
@Column(name = "mount_point", attrName = "mountPoint", label = "挂载点", isQuery = false),
|
@Column(name = "mount_point", attrName = "mountPoint", label = "挂载点"),
|
||||||
@Column(name = "total_size", attrName = "totalSize", label = "总容量", isQuery = false),
|
@Column(name = "total_size", attrName = "totalSize", label = "总容量", isQuery = false),
|
||||||
@Column(name = "used_size", attrName = "usedSize", label = "已使用容量", isQuery = false),
|
@Column(name = "used_size", attrName = "usedSize", label = "已使用容量", isQuery = false),
|
||||||
@Column(name = "usage_rate", attrName = "usageRate", label = "使用率", comment = "使用率(%)", isQuery = false),
|
@Column(name = "usage_rate", attrName = "usageRate", label = "使用率", comment = "使用率(%)", isQuery = false),
|
||||||
|
|||||||
@@ -89,6 +89,7 @@
|
|||||||
sorter: true,
|
sorter: true,
|
||||||
width: 180,
|
width: 180,
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
fixed: 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t('主机名称'),
|
title: t('主机名称'),
|
||||||
|
|||||||
@@ -122,6 +122,7 @@
|
|||||||
sorter: true,
|
sorter: true,
|
||||||
width: 230,
|
width: 230,
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
fixed: 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t('主机名称'),
|
title: t('主机名称'),
|
||||||
|
|||||||
@@ -109,6 +109,7 @@
|
|||||||
sorter: true,
|
sorter: true,
|
||||||
width: 180,
|
width: 180,
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
fixed: 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t('运行时长'),
|
title: t('运行时长'),
|
||||||
|
|||||||
Reference in New Issue
Block a user