|
|
|
|
@@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|