新增前端vue
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.jeesite.modules.app.Job.biz;
|
package com.jeesite.modules.app.Job.biz;
|
||||||
|
|
||||||
|
import com.github.dockerjava.api.model.Container;
|
||||||
import com.jcraft.jsch.Session;
|
import com.jcraft.jsch.Session;
|
||||||
import com.jeesite.common.config.Global;
|
import com.jeesite.common.config.Global;
|
||||||
import com.jeesite.modules.app.dao.info.CpuInfo;
|
import com.jeesite.modules.app.dao.info.CpuInfo;
|
||||||
@@ -67,6 +68,9 @@ public class hostJob {
|
|||||||
if (isReachable) {
|
if (isReachable) {
|
||||||
syncServerInfo(monitorHost);
|
syncServerInfo(monitorHost);
|
||||||
monitorHost.setLastOnlineTime(new Date());
|
monitorHost.setLastOnlineTime(new Date());
|
||||||
|
} else {
|
||||||
|
BizWarningAlert warningAlert = new BizWarningAlert("ZJ_" + KeyUtil.ObjKey(12, 2), "网络预警", 2, monitorHost.getHostname() + "网络预警", "当前主机网络连接超时,请及时处理,主机IP:" + monitorHost.getIpAddress(), "业务系统", "0");
|
||||||
|
bizWarningAlertService.save(warningAlert);
|
||||||
}
|
}
|
||||||
monitorHostService.save(monitorHost);
|
monitorHostService.save(monitorHost);
|
||||||
}, hostMonitorExecutor); // 指定使用配置的线程池
|
}, hostMonitorExecutor); // 指定使用配置的线程池
|
||||||
@@ -84,57 +88,67 @@ public class hostJob {
|
|||||||
* 运行信息更新
|
* 运行信息更新
|
||||||
*/
|
*/
|
||||||
public void syncServerInfo(BizMonitorHost host) {
|
public void syncServerInfo(BizMonitorHost host) {
|
||||||
BizMonitorAccount monitorAccount = new BizMonitorAccount();
|
if (host.getIsAuth().equals("1")) {
|
||||||
monitorAccount.setHostId(host.getHostId());
|
DockerUtils dockerUtils = new DockerUtils(host.getIpAddress(), host.getCheckTargetPort());
|
||||||
monitorAccount.setUstatus("1");
|
List<Container> containerList = dockerUtils.listContainers(true);
|
||||||
monitorAccount.setSshUsername("ogsapp");
|
host.setRunTargetNums(containerList.size());
|
||||||
List<BizMonitorAccount> accountList = accountService.findList(monitorAccount);
|
monitorHostService.save(host);
|
||||||
if (accountList.size() > 0) {
|
BizMonitorAccount monitorAccount = new BizMonitorAccount();
|
||||||
try {
|
monitorAccount.setHostId(host.getHostId());
|
||||||
BizMonitorAccount account = accountList.get(0);
|
monitorAccount.setUstatus("1");
|
||||||
Session session = SystemUtil.getSshSession(account);
|
monitorAccount.setSshUsername("ogsapp");
|
||||||
if (session.isConnected()) {
|
List<BizMonitorAccount> accountList = accountService.findList(monitorAccount);
|
||||||
CpuInfo cpuInfo = SystemUtil.getCpuMemUsage(session);
|
if (accountList.size() > 0) {
|
||||||
ServerInfo info = SystemUtil.getServerBasicInfo(session);
|
try {
|
||||||
List<DiskInfo> diskInfos = SystemUtil.getDiskInfos(session);
|
BizMonitorAccount account = accountList.get(0);
|
||||||
syncDeviceInfo(host, diskInfos);
|
Session session = SystemUtil.getSshSession(account);
|
||||||
BizServerInfo bizServerInfo = new BizServerInfo();
|
if (session.isConnected()) {
|
||||||
bizServerInfo.setHostId(host.getHostId());
|
CpuInfo cpuInfo = SystemUtil.getCpuMemUsage(session);
|
||||||
// 新增主机监控
|
ServerInfo info = SystemUtil.getServerBasicInfo(session);
|
||||||
BizResourceMonitor resourceMonitor = new BizResourceMonitor();
|
List<DiskInfo> diskInfos = SystemUtil.getDiskInfos(session);
|
||||||
resourceMonitor.setHostName(host.getHostname());
|
syncDeviceInfo(host, diskInfos);
|
||||||
resourceMonitor.setCpuUsage(cpuInfo.getCpuUsage());
|
BizServerInfo bizServerInfo = new BizServerInfo();
|
||||||
resourceMonitor.setMemoryUsage(cpuInfo.getMemoryUsage());
|
bizServerInfo.setHostId(host.getHostId());
|
||||||
resourceMonitor.setMemoryTotal(info.getMemoryTotal());
|
// 新增主机监控
|
||||||
resourceMonitor.setHostId(host.getHostId());
|
BizResourceMonitor resourceMonitor = new BizResourceMonitor();
|
||||||
resourceMonitorService.save(resourceMonitor);
|
resourceMonitor.setHostName(host.getHostname());
|
||||||
// 更新主机监控
|
resourceMonitor.setCpuUsage(cpuInfo.getCpuUsage());
|
||||||
List<BizServerInfo> serverInfoList = serverInfoService.findList(bizServerInfo);
|
resourceMonitor.setMemoryUsage(cpuInfo.getMemoryUsage());
|
||||||
BizServerInfo serverInfo = serverInfoList.isEmpty() ? new BizServerInfo() : serverInfoList.get(0);
|
resourceMonitor.setMemoryTotal(info.getMemoryTotal());
|
||||||
serverInfo.setUptime(info.getUptime());
|
resourceMonitor.setHostId(host.getHostId());
|
||||||
serverInfo.setOs(info.getOs());
|
resourceMonitorService.save(resourceMonitor);
|
||||||
serverInfo.setKernelVersion(info.getKernelVersion());
|
// 更新主机监控
|
||||||
serverInfo.setHostname(info.getHostname());
|
List<BizServerInfo> serverInfoList = serverInfoService.findList(bizServerInfo);
|
||||||
serverInfo.setIpAddress(info.getIpAddress());
|
BizServerInfo serverInfo = serverInfoList.isEmpty() ? new BizServerInfo() : serverInfoList.get(0);
|
||||||
serverInfo.setCpuModel(info.getCpuModel());
|
serverInfo.setUptime(info.getUptime());
|
||||||
serverInfo.setMemoryTotal(info.getMemoryTotal());
|
serverInfo.setOs(info.getOs());
|
||||||
serverInfo.setCpuUsage(cpuInfo.getCpuUsage());
|
serverInfo.setKernelVersion(info.getKernelVersion());
|
||||||
serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage());
|
serverInfo.setHostname(info.getHostname());
|
||||||
serverInfo.setLastOnlineTime(new Date());
|
serverInfo.setIpAddress(info.getIpAddress());
|
||||||
serverInfo.setHostId(host.getHostId());
|
serverInfo.setCpuModel(info.getCpuModel());
|
||||||
serverInfoService.save(serverInfo);
|
serverInfo.setMemoryTotal(info.getMemoryTotal());
|
||||||
if (serverInfo.getCpuUsage() >= CPU_RATE) {
|
serverInfo.setCpuUsage(cpuInfo.getCpuUsage());
|
||||||
BizWarningAlert warningAlert = new BizWarningAlert("ZJ_" + KeyUtil.ObjKey(12, 2), "CPU预警", 2, host.getHostname() + "CPU预警", "当前主机CPU已超过" + CPU_RATE + "%,请及时处理,主机IP:" + host.getIpAddress(), "业务系统", "0");
|
serverInfo.setMemoryUsage(cpuInfo.getMemoryUsage());
|
||||||
bizWarningAlertService.save(warningAlert);
|
serverInfo.setLastOnlineTime(new Date());
|
||||||
|
serverInfo.setHostId(host.getHostId());
|
||||||
|
serverInfoService.save(serverInfo);
|
||||||
|
if (serverInfo.getCpuUsage() >= CPU_RATE) {
|
||||||
|
BizWarningAlert warningAlert = new BizWarningAlert("ZJ_" + KeyUtil.ObjKey(12, 2), "CPU预警", 2, host.getHostname() + "CPU预警", "当前主机CPU已超过" + CPU_RATE + "%,请及时处理,主机IP:" + host.getIpAddress(), "业务系统", "0");
|
||||||
|
bizWarningAlertService.save(warningAlert);
|
||||||
|
}
|
||||||
|
if (serverInfo.getMemoryUsage() >= MEM_RATE) {
|
||||||
|
BizWarningAlert warningAlert = new BizWarningAlert("ZJ_" + KeyUtil.ObjKey(12, 2), "内存预警", 2, host.getHostname() + "内存预警", "当前主机内存已超过" + MEM_RATE + "%,请及时处理,主机IP:" + host.getIpAddress(), "业务系统", "0");
|
||||||
|
bizWarningAlertService.save(warningAlert);
|
||||||
|
}
|
||||||
|
SystemUtil.closeSession(session);
|
||||||
}
|
}
|
||||||
if (serverInfo.getMemoryUsage() >= MEM_RATE) {
|
} catch (Exception e) {
|
||||||
BizWarningAlert warningAlert = new BizWarningAlert("ZJ_" + KeyUtil.ObjKey(12, 2), "内存预警", 2, host.getHostname() + "内存预警", "当前主机内存已超过" + MEM_RATE + "%,请及时处理,主机IP:" + host.getIpAddress(), "业务系统", "0");
|
logger.error(e.getMessage(), host);
|
||||||
bizWarningAlertService.save(warningAlert);
|
|
||||||
}
|
|
||||||
SystemUtil.closeSession(session);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
}
|
||||||
logger.error(e.getMessage(), host);
|
if (host.getCheckTargetNums() != containerList.size()) {
|
||||||
|
BizWarningAlert warningAlert = new BizWarningAlert("ZJ_" + KeyUtil.ObjKey(12, 2), "容器预警", 2, host.getHostname() + "容器预警", "当前主机容器运行数量" + containerList.size() + "与配置数量不一致,请及时处理,主机IP:" + host.getIpAddress(), "业务系统", "0");
|
||||||
|
bizWarningAlertService.save(warningAlert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user