diff --git a/kunlun-basedata-service/src/main/java/com/kunlun/basedata/model/UserModel.java b/kunlun-basedata-service/src/main/java/com/kunlun/basedata/model/UserModel.java index 50ac71c8b2dbd6414aa9e3725e4cf20aac11a6c0..e2ae620f3859a6dcdea5aa2af02d12dc5b28c7e3 100644 --- a/kunlun-basedata-service/src/main/java/com/kunlun/basedata/model/UserModel.java +++ b/kunlun-basedata-service/src/main/java/com/kunlun/basedata/model/UserModel.java @@ -54,6 +54,16 @@ public class UserModel { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date modifiedTime; + /** + * 个人简介 + */ + private String resume; + + /** + * 个性标签 + */ + private String individual; + public String getId() { return id; } @@ -117,4 +127,20 @@ public class UserModel { public void setModifiedTime(Date modifiedTime) { this.modifiedTime = modifiedTime; } + + public String getResume() { + return resume; + } + + public void setResume(String resume) { + this.resume = resume; + } + + public String getIndividual() { + return individual; + } + + public void setIndividual(String individual) { + this.individual = individual; + } } diff --git a/kunlun-basedata-service/src/main/resources/mapper/userMapper.xml b/kunlun-basedata-service/src/main/resources/mapper/userMapper.xml index 3dc6319bd36054c9d7728248eb152e4155a62e9b..be0ba7e9e631864f5a04ac0fc0387404816d047c 100644 --- a/kunlun-basedata-service/src/main/resources/mapper/userMapper.xml +++ b/kunlun-basedata-service/src/main/resources/mapper/userMapper.xml @@ -6,7 +6,7 @@ SELECT id, user_name AS userName, password, sex, phone_number AS phoneNumber, email, - create_time AS createTime, modified_time AS modifiedTime + create_time AS createTime, modified_time AS modifiedTime, resume, individual FROM t_system_user WHERE id = #{userId} INSERT INTO t_system_user - (id, user_name, password, sex, phone_number, email, create_time, modified_time) + (id, user_name, password, sex, phone_number, email, create_time, modified_time, resume, individual) VALUES (#{id}, #{userName}, #{password}, #{sex}, #{phoneNumber}, - #{email}, #{createTime}, #{modifiedTime}) + #{email}, #{createTime}, #{modifiedTime}, #{resume}, #{individual}) UPDATE t_system_user SET user_name = #{userName}, password = #{password}, sex=#{sex}, phone_number = #{phoneNumber}, - email = #{email}, modified_time = #{modifiedTime} + email = #{email}, modified_time = #{modifiedTime}, resume = #{resume}, individual = #{individual} WHERE id = #{id} @@ -75,7 +75,7 @@ diff --git a/kunlun-basedata-service/src/main/resources/migration/V1.0.1.2022072400__UPDATE.sql b/kunlun-basedata-service/src/main/resources/migration/V1.0.1.2022072400__UPDATE.sql new file mode 100644 index 0000000000000000000000000000000000000000..11dadc0f7f049884a4e5ba76b613f22c6e4165de --- /dev/null +++ b/kunlun-basedata-service/src/main/resources/migration/V1.0.1.2022072400__UPDATE.sql @@ -0,0 +1,6 @@ +-- 系统用户表 +ALTER TABLE t_system_user ADD COLUMN resume varchar(500) default NULL; +COMMENT ON COLUMN t_system_user.resume IS '个人简介'; + +ALTER TABLE t_system_user ADD COLUMN individual varchar(100) default NULL; +COMMENT ON COLUMN t_system_user.individual IS '个性标签'; diff --git a/kunlun-system-service/src/main/java/com/kunlun/system/controller/SystemInstanceController.java b/kunlun-system-service/src/main/java/com/kunlun/system/controller/SystemInstanceController.java new file mode 100644 index 0000000000000000000000000000000000000000..78f5a3bb72c39e28c6bd6d5e70b2c68757a952bd --- /dev/null +++ b/kunlun-system-service/src/main/java/com/kunlun/system/controller/SystemInstanceController.java @@ -0,0 +1,45 @@ +package com.kunlun.system.controller; + +import com.kunlun.common.utils.ResponseUtil; +import com.kunlun.system.service.ISystemMachineService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@RestController +@RequestMapping(value = "/instance") +public class SystemInstanceController { + + private Logger log = LogManager.getLogger(); + + @Autowired + private ISystemMachineService systemMachineService; + + @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET) + public Object downloadTemplate(HttpServletRequest request, HttpServletResponse response, String type) { + try { + systemMachineService.downloadTemplate(request, response, type); + } catch (Exception e) { + log.error("MachineController getAllMachine Error: ", e); + return ResponseUtil.failedResponse("查询虚拟机容器列表数据失败!", e.getMessage()); + } + return null; + } + + @RequestMapping(value = "/refreshMonitor", method = RequestMethod.GET) + public Object refreshMonitor() { + try { + systemMachineService.collectMonitor(); + } catch (Exception e) { + log.error("MachineController refreshMonitor Error: ", e); + return ResponseUtil.failedResponse("刷新服務器監控數據失败!", e.getMessage()); + } + return null; + } +} diff --git a/kunlun-system-service/src/main/java/com/kunlun/system/controller/SystemMachineController.java b/kunlun-system-service/src/main/java/com/kunlun/system/controller/SystemMachineController.java index ae4ce195fe1d913714672e1b7308020cfc5f2b75..8db1f97252f22292ab53faad12eb09949ed28f23 100644 --- a/kunlun-system-service/src/main/java/com/kunlun/system/controller/SystemMachineController.java +++ b/kunlun-system-service/src/main/java/com/kunlun/system/controller/SystemMachineController.java @@ -2,8 +2,8 @@ package com.kunlun.system.controller; import com.kunlun.common.model.Page; import com.kunlun.common.utils.ResponseUtil; -import com.kunlun.system.model.MachineModel; import com.kunlun.system.model.SystemMachineModel; +import com.kunlun.system.model.vo.MachineInstanceVo; import com.kunlun.system.service.ISystemMachineService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.List; @RestController @RequestMapping(value = "/machine") @@ -27,7 +28,7 @@ public class SystemMachineController { @RequestMapping(value = "/getAllMachine", method = RequestMethod.GET) public Object getAllMachine(SystemMachineModel machineModel, int currentPage, int pageSize) { try { - Page list = systemMachineService.getAllMachine(machineModel, currentPage, pageSize); + Page list = systemMachineService.getAllMachine(machineModel, currentPage, pageSize); return ResponseUtil.successResponse(list); } catch (Exception e) { log.error("MachineController getAllMachine Error: ", e); @@ -56,4 +57,26 @@ public class SystemMachineController { } return null; } + + @RequestMapping(value = "/getMachineLineData", method = RequestMethod.GET) + public Object getMachineLineData(String id) { + try { + MachineInstanceVo vo = systemMachineService.getMachineLineData(id); + return ResponseUtil.successResponse(vo); + } catch (Exception e) { + log.error("MachineController getMachineInstance Error: ", e); + return ResponseUtil.failedResponse("查询虚拟机实例信息失败!", e.getMessage()); + } + } + + @RequestMapping(value = "/getSystemMonitorData", method = RequestMethod.GET) + public Object getSystemMonitorData(String serviceName, String ipAddress, Integer pageSize) { + try { + List vos = systemMachineService.getSystemMonitorData(serviceName, ipAddress, pageSize); + return ResponseUtil.successResponse(vos); + } catch (Exception e) { + log.error("MachineController getSystemMonitorData Error: ", e); + return ResponseUtil.failedResponse("查询虚拟机实例信息失败!", e.getMessage()); + } + } } diff --git a/kunlun-system-service/src/main/java/com/kunlun/system/dao/IDictionaryDao.java b/kunlun-system-service/src/main/java/com/kunlun/system/dao/IDictionaryDao.java index 0339cc6364214f2c960e25e5e7df6003c177e662..9ddfaa4954f2c3156a1a1c860302ae62af21913b 100644 --- a/kunlun-system-service/src/main/java/com/kunlun/system/dao/IDictionaryDao.java +++ b/kunlun-system-service/src/main/java/com/kunlun/system/dao/IDictionaryDao.java @@ -9,25 +9,26 @@ import java.util.Map; @Repository public interface IDictionaryDao { - public List getAllDictionaryItem(Map queryMap) throws Exception; - public int getDictionaryCount(Map queryMap) throws Exception; + List getAllDictionaryItem(Map queryMap) throws Exception; - public List getAllDictionaryValue(Map queryMap) throws Exception; + int getDictionaryCount(Map queryMap) throws Exception; - public List getValuesByDictCode(String dictCode) throws Exception; + List getAllDictionaryValue(Map queryMap) throws Exception; - public int getDictionarySubCount(Map queryMap) throws Exception; + List getValuesByDictCode(String dictCode) throws Exception; - public void insertDictionaryItem(DictionaryItemModel dictionaryItemModel) throws Exception; + int getDictionarySubCount(Map queryMap) throws Exception; - public void insertDictionaryValue(DictionaryValueModel dictionaryModel) throws Exception; + void insertDictionaryItem(DictionaryItemModel dictionaryItemModel) throws Exception; - public void updateDictionaryItem(DictionaryItemModel dictionaryItemModel) throws Exception; + void insertDictionaryValue(DictionaryValueModel dictionaryModel) throws Exception; - public void updateDictionaryValue(DictionaryValueModel dictionaryModel) throws Exception; + void updateDictionaryItem(DictionaryItemModel dictionaryItemModel) throws Exception; - public void deleteDictionaryItem(String ids) throws Exception; + void updateDictionaryValue(DictionaryValueModel dictionaryModel) throws Exception; - public void deleteDictionaryValue(String ids) throws Exception; + void deleteDictionaryItem(String ids) throws Exception; + + void deleteDictionaryValue(String ids) throws Exception; } diff --git a/kunlun-system-service/src/main/java/com/kunlun/system/dao/ISystemMachineDao.java b/kunlun-system-service/src/main/java/com/kunlun/system/dao/ISystemMachineDao.java index c88c07026ebcedc18f61e1836948d333062524a9..6504c0d3ead16863fd0cdb2422af7a17989980e8 100644 --- a/kunlun-system-service/src/main/java/com/kunlun/system/dao/ISystemMachineDao.java +++ b/kunlun-system-service/src/main/java/com/kunlun/system/dao/ISystemMachineDao.java @@ -1,6 +1,8 @@ package com.kunlun.system.dao; import com.kunlun.system.model.SystemMachineModel; +import com.kunlun.system.model.vo.MachineInstanceVo; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -9,9 +11,11 @@ import java.util.Map; @Repository public interface ISystemMachineDao { - List getAllMachine(Map queryMap) throws Exception; + List getMachineInstance(Map queryMap) throws Exception; int selectMachineCount(Map queryMap) throws Exception; void addSystemMachine(List monitorModels) throws Exception; + + MachineInstanceVo getMachineLineData(String id) throws Exception; } diff --git a/kunlun-system-service/src/main/java/com/kunlun/system/model/SystemMachineModel12345.java b/kunlun-system-service/src/main/java/com/kunlun/system/model/vo/MachineInstanceVo.java similarity index 62% rename from kunlun-system-service/src/main/java/com/kunlun/system/model/SystemMachineModel12345.java rename to kunlun-system-service/src/main/java/com/kunlun/system/model/vo/MachineInstanceVo.java index 5e01adf4e095ff6b738c540f5abf4f2a9d6cde67..8bcd148192a9741690c96466b430183ce9d0bcd5 100644 --- a/kunlun-system-service/src/main/java/com/kunlun/system/model/SystemMachineModel12345.java +++ b/kunlun-system-service/src/main/java/com/kunlun/system/model/vo/MachineInstanceVo.java @@ -1,23 +1,8 @@ -package com.kunlun.system.model; - -import com.kunlun.common.model.monitor.CpuInfoModel; -import com.kunlun.common.model.monitor.DiskInfoModel; -import com.kunlun.common.model.monitor.JvmInfoModel; -import com.kunlun.common.model.monitor.MemoryInfoModel; -import com.kunlun.common.model.monitor.NetworkInfoModel; -import com.kunlun.common.model.monitor.SystemInfoModel; -import com.kunlun.common.utils.CalculateUtil; -import com.kunlun.common.utils.CommonUtil; -import org.springframework.util.ObjectUtils; +package com.kunlun.system.model.vo; import java.util.Date; -import java.util.List; - -/** - * 系统监控数据模型 - */ -public class SystemMachineModel12345 { +public class MachineInstanceVo { // 主键ID private String id; @@ -25,19 +10,7 @@ public class SystemMachineModel12345 { private String serviceName; // ip地址 - private String ipAdress; - - // 计算机名 - private String computerName; - - // 系统名 - private String systemName; - - // 系统架构 - private String systemArchitecture; - - // 系统userDir - private String userDirectory; + private String ipAddress; // CPU逻辑处理器数 private int cpuLogicalProcessorCount; @@ -69,6 +42,39 @@ public class SystemMachineModel12345 { // 内存使用率 private String memoryUsedPercent; + // 磁盘文件系统类型 + private String diskType; + + // 磁盘总容量 + private String diskTotalSpace; + + // 磁盘总大小 + private String diskTotalSize; + + // 磁盘可用容量 + private String diskUsableSpace; + + // 磁盘可用大小 + private String diskUsableSize; + + // 磁盘已使用大小 + private String diskUsedSize; + + // 磁盘使用率 + private String diskUsedPercent; + + // 计算机名 + private String computerName; + + // 系统名 + private String systemName; + + // 系统架构 + private String systemArchitecture; + + // 系统userDir + private String userDirectory; + // JVM总内存 private String jvmTotalMemory; @@ -106,97 +112,14 @@ public class SystemMachineModel12345 { private int netSendDataCount; // 每秒钟接收的KB数 - private int netReceiveKBCount; + private int netReceiveKbCount; // 每秒钟发送的KB数 - private int netSendKBCount; - - // 磁盘文件系统类型 - private String diskType; + private int netSendKbCount; - // 磁盘总容量 - private String diskTotalSpace; + private Date createTime; - // 磁盘总大小 - private String diskTotalSize; - - // 磁盘可用容量 - private String diskUsableSpace; - - // 磁盘可用大小 - private String diskUsableSize; - - // 磁盘已使用大小 - private String diskUsedSize; - - // 磁盘使用率 - private String diskUsedPercent; - - public SystemMachineModel12345() { - } - - public SystemMachineModel12345(String serviceName, CpuInfoModel cpuInfoModel, MemoryInfoModel memoryInfoModel, JvmInfoModel jvmInfoModel, - List diskInfoModels, SystemInfoModel systemInfoModel, NetworkInfoModel networkInfoModel) { - this.id = CommonUtil.generateUUID(); - this.serviceName = serviceName; - if (!ObjectUtils.isEmpty(cpuInfoModel)) { - this.cpuLogicalProcessorCount = cpuInfoModel.getLogicalProcessorCount(); - this.cpuPhysicalProcessorCount = cpuInfoModel.getPhysicalProcessorCount(); - this.cpuSystemUsedPercent = String.valueOf(cpuInfoModel.getSystemPercent()); - this.cpuUserUsedPercent = String.valueOf(cpuInfoModel.getUserPercent()); - this.cpuWaitPercent = String.valueOf(cpuInfoModel.getWaitPercent()); - this.cpuUsedPercent = String.valueOf(cpuInfoModel.getUsePercent()); - } - if (!ObjectUtils.isEmpty(memoryInfoModel)) { - this.memoryTotal = memoryInfoModel.getTotal(); - this.memoryFree = memoryInfoModel.getFree(); - this.memoryUsed = memoryInfoModel.getUsed(); - this.memoryUsedPercent = String.valueOf(memoryInfoModel.getUsePercent()); - } - if (!ObjectUtils.isEmpty(jvmInfoModel)) { - this.jdkName = jvmInfoModel.getJdkName(); - this.jdkHome = jvmInfoModel.getJdkHome(); - this.jdkVersion = jvmInfoModel.getJdkVersion(); - this.jvmTotalMemory = jvmInfoModel.getJvmTotalMemory(); - this.jvmMaxMemory = jvmInfoModel.getMaxMemory(); - this.jvmFreeMemory = jvmInfoModel.getFreeMemory(); - this.jvmUsedMemory = jvmInfoModel.getUsedMemory(); - this.jvmUsedPercent = String.valueOf(jvmInfoModel.getUsePercent()); - this.jvmStartTime = new Date(jvmInfoModel.getStartTime()); - this.jvmUpTime = jvmInfoModel.getUptime(); - } - if (!ObjectUtils.isEmpty(diskInfoModels)) { - String type = null, totalSpace = null, usableSpace = null, totalSize = null, usableSize = null, usedSize = null; - for (DiskInfoModel diskModel : diskInfoModels) { - type = diskModel.getType(); - totalSpace = CalculateUtil.calculate("a + b", 2, totalSpace, String.valueOf(diskModel.getTotalSpace())); - usableSpace = CalculateUtil.calculate("a + b", 2, usableSpace, String.valueOf(diskModel.getUsableSpace())); - totalSize = CalculateUtil.calculate("a + b", 2, totalSize, diskModel.getSize().replace("GB", "")); - usableSize = CalculateUtil.calculate("a + b", 2, totalSize, diskModel.getAvail().replace("GB", "")); - usedSize = CalculateUtil.calculate("a + b", 2, usedSize, diskModel.getUsed().replace("GB", "")); - } - this.diskType = type; - this.diskTotalSpace = totalSpace; - this.diskTotalSize = totalSize + "GB"; - this.diskUsableSpace = usableSpace; - this.diskUsableSize = usableSize + "GB"; - this.diskUsedSize = usedSize + "GB"; - this.diskUsedPercent = CalculateUtil.calculate("a / b", 2, usedSize, totalSize); - } - if (!ObjectUtils.isEmpty(systemInfoModel)) { - this.computerName = systemInfoModel.getName(); - this.systemName = systemInfoModel.getOsName(); - this.systemArchitecture = systemInfoModel.getOsArch(); - this.ipAdress = systemInfoModel.getIp(); - this.userDirectory = systemInfoModel.getUserDir(); - } - if (!ObjectUtils.isEmpty(networkInfoModel)) { - this.netReceiveDataCount = Integer.valueOf(networkInfoModel.getRxpck()); - this.netSendDataCount = Integer.valueOf(networkInfoModel.getTxpck()); - this.netReceiveKBCount = Integer.valueOf(networkInfoModel.getRxbyt()); - this.netSendKBCount = Integer.valueOf(networkInfoModel.getTxbyt()); - } - } + private Date modifiedTime; public String getId() { return id; @@ -214,44 +137,12 @@ public class SystemMachineModel12345 { this.serviceName = serviceName; } - public String getIpAdress() { - return ipAdress; - } - - public void setIpAdress(String ipAdress) { - this.ipAdress = ipAdress; - } - - public String getComputerName() { - return computerName; - } - - public void setComputerName(String computerName) { - this.computerName = computerName; + public String getIpAddress() { + return ipAddress; } - public String getSystemName() { - return systemName; - } - - public void setSystemName(String systemName) { - this.systemName = systemName; - } - - public String getSystemArchitecture() { - return systemArchitecture; - } - - public void setSystemArchitecture(String systemArchitecture) { - this.systemArchitecture = systemArchitecture; - } - - public String getUserDirectory() { - return userDirectory; - } - - public void setUserDirectory(String userDirectory) { - this.userDirectory = userDirectory; + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; } public int getCpuLogicalProcessorCount() { @@ -334,6 +225,94 @@ public class SystemMachineModel12345 { this.memoryUsedPercent = memoryUsedPercent; } + public String getDiskType() { + return diskType; + } + + public void setDiskType(String diskType) { + this.diskType = diskType; + } + + public String getDiskTotalSpace() { + return diskTotalSpace; + } + + public void setDiskTotalSpace(String diskTotalSpace) { + this.diskTotalSpace = diskTotalSpace; + } + + public String getDiskTotalSize() { + return diskTotalSize; + } + + public void setDiskTotalSize(String diskTotalSize) { + this.diskTotalSize = diskTotalSize; + } + + public String getDiskUsableSpace() { + return diskUsableSpace; + } + + public void setDiskUsableSpace(String diskUsableSpace) { + this.diskUsableSpace = diskUsableSpace; + } + + public String getDiskUsableSize() { + return diskUsableSize; + } + + public void setDiskUsableSize(String diskUsableSize) { + this.diskUsableSize = diskUsableSize; + } + + public String getDiskUsedSize() { + return diskUsedSize; + } + + public void setDiskUsedSize(String diskUsedSize) { + this.diskUsedSize = diskUsedSize; + } + + public String getDiskUsedPercent() { + return diskUsedPercent; + } + + public void setDiskUsedPercent(String diskUsedPercent) { + this.diskUsedPercent = diskUsedPercent; + } + + public String getComputerName() { + return computerName; + } + + public void setComputerName(String computerName) { + this.computerName = computerName; + } + + public String getSystemName() { + return systemName; + } + + public void setSystemName(String systemName) { + this.systemName = systemName; + } + + public String getSystemArchitecture() { + return systemArchitecture; + } + + public void setSystemArchitecture(String systemArchitecture) { + this.systemArchitecture = systemArchitecture; + } + + public String getUserDirectory() { + return userDirectory; + } + + public void setUserDirectory(String userDirectory) { + this.userDirectory = userDirectory; + } + public String getJvmTotalMemory() { return jvmTotalMemory; } @@ -430,75 +409,35 @@ public class SystemMachineModel12345 { this.netSendDataCount = netSendDataCount; } - public int getNetReceiveKBCount() { - return netReceiveKBCount; - } - - public void setNetReceiveKBCount(int netReceiveKBCount) { - this.netReceiveKBCount = netReceiveKBCount; - } - - public int getNetSendKBCount() { - return netSendKBCount; + public int getNetReceiveKbCount() { + return netReceiveKbCount; } - public void setNetSendKBCount(int netSendKBCount) { - this.netSendKBCount = netSendKBCount; + public void setNetReceiveKbCount(int netReceiveKbCount) { + this.netReceiveKbCount = netReceiveKbCount; } - public String getDiskType() { - return diskType; + public int getNetSendKbCount() { + return netSendKbCount; } - public void setDiskType(String diskType) { - this.diskType = diskType; + public void setNetSendKbCount(int netSendKbCount) { + this.netSendKbCount = netSendKbCount; } - public String getDiskTotalSpace() { - return diskTotalSpace; + public Date getCreateTime() { + return createTime; } - public void setDiskTotalSpace(String diskTotalSpace) { - this.diskTotalSpace = diskTotalSpace; + public void setCreateTime(Date createTime) { + this.createTime = createTime; } - public String getDiskTotalSize() { - return diskTotalSize; + public Date getModifiedTime() { + return modifiedTime; } - public void setDiskTotalSize(String diskTotalSize) { - this.diskTotalSize = diskTotalSize; - } - - public String getDiskUsableSpace() { - return diskUsableSpace; - } - - public void setDiskUsableSpace(String diskUsableSpace) { - this.diskUsableSpace = diskUsableSpace; - } - - public String getDiskUsableSize() { - return diskUsableSize; - } - - public void setDiskUsableSize(String diskUsableSize) { - this.diskUsableSize = diskUsableSize; - } - - public String getDiskUsedSize() { - return diskUsedSize; - } - - public void setDiskUsedSize(String diskUsedSize) { - this.diskUsedSize = diskUsedSize; - } - - public String getDiskUsedPercent() { - return diskUsedPercent; - } - - public void setDiskUsedPercent(String diskUsedPercent) { - this.diskUsedPercent = diskUsedPercent; + public void setModifiedTime(Date modifiedTime) { + this.modifiedTime = modifiedTime; } } diff --git a/kunlun-system-service/src/main/java/com/kunlun/system/service/ISystemMachineService.java b/kunlun-system-service/src/main/java/com/kunlun/system/service/ISystemMachineService.java index 53759073332bf48271eaac5abaf8941222a50783..c2f4ebc05b286a4aa09d2444257adf00f8e4b79d 100644 --- a/kunlun-system-service/src/main/java/com/kunlun/system/service/ISystemMachineService.java +++ b/kunlun-system-service/src/main/java/com/kunlun/system/service/ISystemMachineService.java @@ -2,15 +2,21 @@ package com.kunlun.system.service; import com.kunlun.common.model.Page; import com.kunlun.system.model.SystemMachineModel; +import com.kunlun.system.model.vo.MachineInstanceVo; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.List; public interface ISystemMachineService { - Page getAllMachine(SystemMachineModel machineModel, int currentPage, int pageSize) throws Exception; + Page getAllMachine(SystemMachineModel machineModel, int currentPage, int pageSize) throws Exception; void downloadTemplate(HttpServletRequest request, HttpServletResponse response, String type) throws Exception; void collectMonitor() throws Exception; + + MachineInstanceVo getMachineLineData(String id) throws Exception; + + List getSystemMonitorData(String serviceName, String ipAddress, Integer pageSize) throws Exception; } diff --git a/kunlun-system-service/src/main/java/com/kunlun/system/service/impl/SystemMachineService.java b/kunlun-system-service/src/main/java/com/kunlun/system/service/impl/SystemMachineService.java index 1c4e71084bde0316547354031549217b21f515e0..bd5728ccfb38564cfc5e9745f4dcb52345c6fa20 100644 --- a/kunlun-system-service/src/main/java/com/kunlun/system/service/impl/SystemMachineService.java +++ b/kunlun-system-service/src/main/java/com/kunlun/system/service/impl/SystemMachineService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.kunlun.common.model.Page; import com.kunlun.common.model.ResponseMessage; import com.kunlun.common.model.monitor.SystemDataModel; +import com.kunlun.common.utils.CalculateUtil; import com.kunlun.common.utils.JsonUtil; import com.kunlun.system.config.dataSource.DataSourceType; import com.kunlun.system.config.dataSource.DbContextHolder; @@ -11,6 +12,7 @@ import com.kunlun.system.dao.ISystemMachineDao; import com.kunlun.system.model.DictionaryValueModel; import com.kunlun.system.model.SystemInstanceModel; import com.kunlun.system.model.SystemMachineModel; +import com.kunlun.system.model.vo.MachineInstanceVo; import com.kunlun.system.service.IDictionaryService; import com.kunlun.system.service.ISystemInstanceService; import com.kunlun.system.service.ISystemMachineService; @@ -21,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; import org.springframework.web.client.RestTemplate; import javax.servlet.http.HttpServletRequest; @@ -30,9 +33,12 @@ import java.io.InputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Comparator; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service @Transactional @@ -55,16 +61,16 @@ public class SystemMachineService implements ISystemMachineService { private ISystemInstanceService systemInstanceService; @Override - public Page getAllMachine(SystemMachineModel machineModel, int currentPage, int pageSize) throws Exception { + public Page getAllMachine(SystemMachineModel machineModel, int currentPage, int pageSize) throws Exception { int startIndex = (currentPage - 1) * pageSize; Map queryMap = CommonUtil.packageQueryMap(machineModel, startIndex, pageSize); DbContextHolder.setDbType(DataSourceType.MASTER.getKey()); int count = systemMachineDao.selectMachineCount(queryMap); - List machineModels = systemMachineDao.getAllMachine(queryMap); + List machineModels = systemMachineDao.getMachineInstance(queryMap); - Page page = new Page<>(); + Page page = new Page<>(); page.setCurrentPage(currentPage); page.setPageSize(pageSize); page.setTotal(count); @@ -101,6 +107,7 @@ public class SystemMachineService implements ISystemMachineService { SystemMachineModel systemMachineModel = new SystemMachineModel(systemData); systemMachineModels.add(systemMachineModel); SystemInstanceModel systemInstanceModel = new SystemInstanceModel(systemData); + systemInstanceModel.setMachineId(systemMachineModel.getId()); systemInstanceModels.add(systemInstanceModel); } } catch (Exception e) { @@ -111,6 +118,36 @@ public class SystemMachineService implements ISystemMachineService { } } + @Override + public MachineInstanceVo getMachineLineData(String id) throws Exception { + MachineInstanceVo vo = systemMachineDao.getMachineLineData(id); + vo.setCpuUsedPercent(CalculateUtil.calculate("a * b", 2, vo.getCpuUsedPercent(), "100")); + vo.setMemoryUsedPercent(CalculateUtil.calculate("a * b", 2, vo.getMemoryUsedPercent(), "100")); + vo.setDiskUsedPercent(CalculateUtil.calculate("a * b", 2, vo.getDiskUsedPercent(), "100")); + vo.setJvmUsedPercent(CalculateUtil.calculate("a * b", 2, vo.getJvmUsedPercent(), "100")); + String jvmUpTime = CalculateUtil.calculate("a / b", 0, String.valueOf(vo.getJvmUpTime()), "1000"); + vo.setJvmUpTime(Long.valueOf(jvmUpTime)); + return vo; + } + + @Override + public List getSystemMonitorData(String serviceName, String ipAddress, Integer pageSize) throws Exception { + Map queryMap = new HashMap<>(); + queryMap.put("serviceName", serviceName); + queryMap.put("ipAddress", ipAddress); + queryMap.put("currentPage", 1); + queryMap.put("pageSize", pageSize); + List machineModels = systemMachineDao.getMachineInstance(queryMap); + machineModels = machineModels.stream().filter(obj -> !ObjectUtils.isEmpty(obj.getCreateTime())).map(model -> { + model.setCpuUsedPercent(CalculateUtil.calculate("a * b", 2, model.getCpuUsedPercent(), "100")); + model.setMemoryUsedPercent(CalculateUtil.calculate("a * b", 2, model.getMemoryUsedPercent(), "100")); + model.setDiskUsedPercent(CalculateUtil.calculate("a * b", 2, model.getDiskUsedPercent(), "100")); + model.setJvmUsedPercent(CalculateUtil.calculate("a * b", 2, model.getJvmUsedPercent(), "100")); + return model; + }).sorted(Comparator.comparing(MachineInstanceVo::getCreateTime)).collect(Collectors.toList()); + return machineModels; + } + private void exportTemplate(HttpServletResponse response, String templatePath) throws Exception { OutputStream os = response.getOutputStream(); InputStream is = new FileInputStream(templatePath); diff --git a/kunlun-system-service/src/main/java/com/kunlun/system/task/ScheduleTaskService.java b/kunlun-system-service/src/main/java/com/kunlun/system/task/ScheduleTaskService.java index 6a92c9d63668ed0eb7061a53212343b101ffe71e..db8efa4e222ceb290c7188aaa2d8bd7fb75c3c86 100644 --- a/kunlun-system-service/src/main/java/com/kunlun/system/task/ScheduleTaskService.java +++ b/kunlun-system-service/src/main/java/com/kunlun/system/task/ScheduleTaskService.java @@ -30,8 +30,7 @@ public class ScheduleTaskService { log.info("TaskService startMonitor start"); try { ScheduleMonitorTask monitorTask = new ScheduleMonitorTask(systemMachineService); -// executorPool.scheduleAtFixedRate(monitorTask, 1, 60 * 5, TimeUnit.SECONDS); - executorPool.scheduleAtFixedRate(monitorTask, 0, 20, TimeUnit.SECONDS); + executorPool.scheduleAtFixedRate(monitorTask, 10, 60 * 5, TimeUnit.SECONDS); } catch (Exception e) { log.error("ScheduleTaskService Error: ", e); } diff --git a/kunlun-system-service/src/main/resources/mapper/machineMapper.xml b/kunlun-system-service/src/main/resources/mapper/machineMapper.xml index 1b4c027d0af7325d4ea65cc9b071d6d0e9969763..ddfcd37fd0c6b9e53516cfc70ac7942662ca2fea 100644 --- a/kunlun-system-service/src/main/resources/mapper/machineMapper.xml +++ b/kunlun-system-service/src/main/resources/mapper/machineMapper.xml @@ -2,47 +2,72 @@ - + + ORDER BY machine.create_time desc offset #{currentPage} limit #{pageSize} - + + + select + machine.id as id, + machine.service_name as serviceName, + machine.ip_address as ipAddress, + machine.cpu_logical_processor_count as cpuLogicalProcessorCount, + machine.cpu_physical_processor_count as cpuPhysicalProcessorCount, + machine.cpu_system_used_percent as cpuSystemUsedPercent, + machine.cpu_user_used_percent as cpuUserUsedPercent, + machine.cpu_wait_percent as cpuWaitPercent, + machine.cpu_used_percent as cpuUsedPercent, + machine.memory_total as memoryTotal, + machine.memory_free as memoryFree, + machine.memory_used as memoryUsed, + machine.memory_used_percent as memoryUsedPercent, + machine.disk_type as diskType, + machine.disk_total_space as diskTotalSpace, + machine.disk_total_size as diskTotalSize, + machine.disk_usable_space as diskUsableSpace, + machine.disk_usable_size as diskUsableSize, + machine.disk_used_size as diskUsedSize, + machine.disk_used_percent as diskUsedPercent, + instance.computer_name as computerName, + instance.system_name as systemName, + instance.system_architecture as systemArchitecture, + instance.user_directory as userDirectory, + instance.jvm_total_memory as jvmTotalMemory, + instance.jvm_max_memory as jvmMaxMemory, + instance.jvm_free_memory as jvmFreeMemory, + instance.jvm_used_memory as jvmUsedMemory, + instance.jvm_used_percent as jvmUsedPercent, + instance.jvm_start_time as jvmStartTime, + instance.jvm_up_time as jvmUpTime, + instance.jdk_name as jdkName, + instance.jdk_version as jdkVersion, + instance.jdk_home as jdkHome, + instance.net_receive_data_count as netReceiveDataCount, + instance.net_send_data_count as netSendDataCount, + instance.net_receive_kb_count as netReceiveKbCount, + instance.net_send_kb_count as netSendKbCount, + instance.create_time as createTime, + instance.modified_time as modifiedTime + from t_system_machine machine + left join t_system_instance instance on machine.id = instance.machine_id + + - service_name = #{serviceName} + machine.service_name = #{serviceName} - AND ip_address = #{ipAddress} + AND machine.ip_address = #{ipAddress} @@ -65,4 +90,9 @@ + +