diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/SystemConfigInfo.java b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/SystemConfigInfo.java index f5a52b97..20a046cd 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/SystemConfigInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/SystemConfigInfo.java @@ -3,8 +3,9 @@ package com.genersoft.iot.vmp.vmanager.bean; import com.genersoft.iot.vmp.common.VersionPo; import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.UserSetting; -import com.genersoft.iot.vmp.conf.VersionInfo; +import lombok.Data; +@Data public class SystemConfigInfo { private int serverPort; @@ -12,36 +13,5 @@ public class SystemConfigInfo { private UserSetting addOn; private VersionPo version; - public int getServerPort() { - return serverPort; - } - - public void setServerPort(int serverPort) { - this.serverPort = serverPort; - } - - public SipConfig getSip() { - return sip; - } - - public void setSip(SipConfig sip) { - this.sip = sip; - } - - public UserSetting getAddOn() { - return addOn; - } - - public void setAddOn(UserSetting addOn) { - this.addOn = addOn; - } - - public VersionPo getVersion() { - return version; - } - - public void setVersion(VersionPo version) { - this.version = version; - } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java index 3c22dbb8..ad7af608 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java @@ -11,8 +11,8 @@ import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService; import com.genersoft.iot.vmp.gb28181.service.IDeviceService; -import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.media.bean.MediaServer; +import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.service.bean.MediaServerLoad; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.streamProxy.service.IStreamProxyService; @@ -25,13 +25,24 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; +import oshi.SystemInfo; +import oshi.hardware.CentralProcessor; +import oshi.hardware.GlobalMemory; +import oshi.hardware.HardwareAbstractionLayer; +import oshi.hardware.NetworkIF; +import oshi.software.os.OperatingSystem; +import java.io.File; +import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; @SuppressWarnings("rawtypes") @Tag(name = "服务控制") @@ -75,7 +86,6 @@ public class ServerController { private IRedisCatchStorage redisCatchStorage; - @GetMapping(value = "/media_server/list") @ResponseBody @Operation(summary = "流媒体服务列表", security = @SecurityRequirement(name = JwtUtils.HEADER)) @@ -140,7 +150,7 @@ public class ServerController { @ResponseBody public void deleteMediaServer(@RequestParam String id) { MediaServer mediaServer = mediaServerService.getOne(id); - if(mediaServer == null) { + if (mediaServer == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "流媒体不存在"); } mediaServerService.delete(mediaServer); @@ -170,9 +180,11 @@ public class ServerController { // throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage()); // } // }); - }; + } - @Operation(summary = "获取系统信息信息", security = @SecurityRequirement(name = JwtUtils.HEADER)) + ; + + @Operation(summary = "获取系统配置信息", security = @SecurityRequirement(name = JwtUtils.HEADER)) @GetMapping(value = "/system/configInfo") @ResponseBody public SystemConfigInfo getConfigInfo() { @@ -234,7 +246,7 @@ public class ServerController { List allOnline = mediaServerService.getAllOnline(); if (allOnline.isEmpty()) { return result; - }else { + } else { for (MediaServer mediaServerItem : allOnline) { result.add(mediaServerService.getLoad(mediaServerItem)); } @@ -258,4 +270,80 @@ public class ServerController { return result; } + + @GetMapping(value = "/info") + @ResponseBody + @Operation(summary = "获取系统信息") + public Map> getInfo() { + Map> result = new LinkedHashMap<>(); + Map hardwareMap = new LinkedHashMap<>(); + result.put("硬件信息", hardwareMap); + + SystemInfo systemInfo = new SystemInfo(); + HardwareAbstractionLayer hardware = systemInfo.getHardware(); + // 获取CPU信息 + CentralProcessor.ProcessorIdentifier processorIdentifier = hardware.getProcessor().getProcessorIdentifier(); + hardwareMap.put("CPU", processorIdentifier.getName()); + // 获取内存 + GlobalMemory memory = hardware.getMemory(); + hardwareMap.put("内存", formatByte(memory.getTotal() - memory.getAvailable()) + "/" + formatByte(memory.getTotal())); + hardwareMap.put("制造商", systemInfo.getHardware().getComputerSystem().getManufacturer()); + hardwareMap.put("产品名称", systemInfo.getHardware().getComputerSystem().getModel()); + // 网卡 + List networkIFs = hardware.getNetworkIFs(); + StringBuilder ips = new StringBuilder(); + for (int i = 0; i < networkIFs.size(); i++) { + NetworkIF networkIF = networkIFs.get(i); + String ipsStr = StringUtils.join(networkIF.getIPv4addr()); + if (ObjectUtils.isEmpty(ipsStr)) { + continue; + } + ips.append(ipsStr); + if (i < networkIFs.size() - 1) { + ips.append(","); + } + } + hardwareMap.put("网卡", ips.toString()); + + Map operatingSystemMap = new LinkedHashMap<>(); + result.put("操作系统", operatingSystemMap); + OperatingSystem operatingSystem = systemInfo.getOperatingSystem(); + operatingSystemMap.put("名称", operatingSystem.getFamily() + " " + operatingSystem.getVersionInfo().getVersion()); + operatingSystemMap.put("类型", operatingSystem.getManufacturer()); + + Map platformMap = new LinkedHashMap<>(); + result.put("平台信息", platformMap); + VersionPo version = versionInfo.getVersion(); + platformMap.put("版本", version.getVersion()); + platformMap.put("构建日期", version.getBUILD_DATE()); + platformMap.put("GIT分支", version.getGIT_BRANCH()); + platformMap.put("GIT地址", version.getGIT_URL()); + platformMap.put("GIT日期", version.getGIT_DATE()); + platformMap.put("GIT版本", version.getGIT_Revision_SHORT()); + platformMap.put("DOCKER环境", new File("/.dockerenv").exists()?"是":"否"); + + return result; + } + + /** + * 单位转换 + */ + private static String formatByte(long byteNumber) { + //换算单位 + double FORMAT = 1024.0; + double kbNumber = byteNumber / FORMAT; + if (kbNumber < FORMAT) { + return new DecimalFormat("#.##KB").format(kbNumber); + } + double mbNumber = kbNumber / FORMAT; + if (mbNumber < FORMAT) { + return new DecimalFormat("#.##MB").format(mbNumber); + } + double gbNumber = mbNumber / FORMAT; + if (gbNumber < FORMAT) { + return new DecimalFormat("#.##GB").format(gbNumber); + } + double tbNumber = gbNumber / FORMAT; + return new DecimalFormat("#.##TB").format(tbNumber); + } } diff --git a/web_src/src/components/operations.vue b/web_src/src/components/operations.vue index c94c29d8..31c111f2 100755 --- a/web_src/src/components/operations.vue +++ b/web_src/src/components/operations.vue @@ -1,26 +1,26 @@