提交 81117241 authored 作者: wangqiang's avatar wangqiang

问题修改 运维平台-剩余BUG跟踪与新增(10-19)

上级 19ae21c8
...@@ -17,6 +17,7 @@ import com.priusis.client.service.data.*; ...@@ -17,6 +17,7 @@ import com.priusis.client.service.data.*;
import com.priusis.controller.ProgramController; import com.priusis.controller.ProgramController;
import com.priusis.controller.RemoteControlController; import com.priusis.controller.RemoteControlController;
import com.priusis.dto.HwPortControllerDto; import com.priusis.dto.HwPortControllerDto;
import com.priusis.dto.NetPortControllerDto;
import com.priusis.lib.R; import com.priusis.lib.R;
import com.priusis.monitor.mqtt.*; import com.priusis.monitor.mqtt.*;
import com.priusis.service.common.MacAddrService; import com.priusis.service.common.MacAddrService;
...@@ -43,6 +44,7 @@ import java.net.URL; ...@@ -43,6 +44,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.KeyStore; import java.security.KeyStore;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
...@@ -149,11 +151,15 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -149,11 +151,15 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
@Resource @Resource
private ProgramController programController; private ProgramController programController;
private Locale enlocale = new Locale("en", "US");
private DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(enlocale);
public MqttServiceImpl(PcCoreConfiguration configuration, Consumer<String> extensionsConfigListener) { public MqttServiceImpl(PcCoreConfiguration configuration, Consumer<String> extensionsConfigListener) {
this.configuration = configuration; this.configuration = configuration;
this.extensionsConfigListener = extensionsConfigListener; this.extensionsConfigListener = extensionsConfigListener;
} }
@Override @Override
@PostConstruct @PostConstruct
public void init() { public void init() {
...@@ -397,11 +403,14 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -397,11 +403,14 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
realDataMonitorScanHandler(message, requestId, bizRequestId, mqttRpcDataMessage); realDataMonitorScanHandler(message, requestId, bizRequestId, mqttRpcDataMessage);
remoteRtcHandler(message, requestId, bizRequestId, mqttRpcDataMessage); remoteRtcHandler(message, requestId, bizRequestId, mqttRpcDataMessage);
resetControlHandler(message, requestId, bizRequestId, mqttRpcDataMessage); resetControlHandler(message, requestId, bizRequestId, mqttRpcDataMessage);
resetNetPortControlHandler(message, requestId, bizRequestId, mqttRpcDataMessage);
resetBackWhiteListHandler(message, requestId, bizRequestId, mqttRpcDataMessage);
controlHandler(message, requestId, bizRequestId, mqttRpcDataMessage); controlHandler(message, requestId, bizRequestId, mqttRpcDataMessage);
try { try {
if (!Arrays.asList("power", "remote_control", "remote_control_exit", "remote_control_accept", if (!Arrays.asList("power", "remote_control", "remote_control_exit", "remote_control_accept",
"real_data_monitor", "facility_scan", "remote_rtc", "control_allow", "controll").contains(mqttRpcDataMessage.getMethod())) { "real_data_monitor", "facility_scan", "remote_rtc", "control_allow", "controll",
"control_port_allow", "BlackList_allow", "WhiteList_allow").contains(mqttRpcDataMessage.getMethod())) {
persistentFileService.flushRpcDataToFile(mqttRpcDataMessage); persistentFileService.flushRpcDataToFile(mqttRpcDataMessage);
} }
} catch (IOException e) { } catch (IOException e) {
...@@ -712,6 +721,145 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -712,6 +721,145 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
} }
} }
/**
* 网络端口Reset接口处理 control_port_allow
*
* @param message
* @param requestId
* @param bizRequestId
* @param mqttRpcDataMessage
*/
private void resetNetPortControlHandler(String message, int requestId, String bizRequestId, MqttRpcDataMessage
mqttRpcDataMessage) {
String method = mqttRpcDataMessage.getMethod();
if (!"control_port_allow".equals(method)) {
return;
}
if ("control_port_allow".equals(method)) {
String params = mqttRpcDataMessage.getParams();
if (StrUtil.isNotBlank(params)) {
try {
Long sendTime = mqttRpcDataMessage.getSendTime();
List<NetPortControllerDto> netPortControllerDtos = JSONUtil.toList(params, NetPortControllerDto.class);
// 收到软件链路端口策略下发请求
log.info("收到软件链路端口策略Reset下发请求, sendTime:{}, params:{}", sendTime, params);
Process process = null;
for (NetPortControllerDto netPortControllerDto : netPortControllerDtos) {
NetPortControllerDto.DeviceNetHardwareEnum deviceNetHardwareEnum = netPortControllerDto.getKey();
Long value = netPortControllerDto.getValue();
int doType = netPortControllerDto.getDoType();
String doTypeStr = doType == 1 ? "in" : "out";
// netsh advfirewall firewall del rule name="_apq_135_tcp_0"
// netsh advfirewall firewall del rule name="_apq_135_udp_0"
String deleteShellPre = "netsh advfirewall firewall del rule name=\"_apq_" + value;
String deleteCmd = deleteShellPre + "_tcp_" + doType + "\"";
String executeCmdResult = WinExecuteUtils.executeCmd(deleteCmd);
log.info("处理软件链路端口策略, deleteShell:{}, executeCmdResult:{}", deleteCmd, executeCmdResult);
deleteCmd = deleteShellPre + "_udp_" + doType + "\"";
executeCmdResult = WinExecuteUtils.executeCmd(deleteCmd);
log.info("处理软件链路端口策略, deleteShell:{}, executeCmdResult:{}", deleteCmd, executeCmdResult);
}
if (null != process && process.isAlive()) {
process.destroy();
}
// 清空control_port数据
MqttRpcDataMessage resetMqttRpcDataMessage = MqttRpcDataMessage.builder()
.sendTime(System.currentTimeMillis())
.method("control_port")
.params(null).build();
persistentFileService.flushRpcDataToFile(resetMqttRpcDataMessage);
// response
ObjectNode paramsNode = newNode();
paramsNode.put("code", "1");
paramsNode.put("msg", "success");
paramsNode.put("status", "success");
byte[] msgData = toBytes(newNode().put("requestId", bizRequestId).put("method", method)
.put("resTime", System.currentTimeMillis()).put("response", paramsNode.toString()));
persistMessage(DEVICE_RPC_RES_TOPIC + "/" + requestId, msgIdSeq.incrementAndGet(), msgData, null,
error ->
log.warn("Could not publish control reset res", error));
} catch (Exception e) {
log.error("APQ_HWPORT ERROR: {}", e.getMessage());
log.error("Failed to process rpc command persistent : {}", message, e);
ObjectNode paramsNode = newNode();
paramsNode.put("code", "0");
paramsNode.put("msg", "fail");
paramsNode.put("status", "fail");
byte[] msgData = toBytes(newNode().put("requestId", bizRequestId).put("method", method)
.put("resTime", System.currentTimeMillis()).put("response", paramsNode.toString()));
persistMessage(DEVICE_RPC_RES_TOPIC + "/" + requestId, msgIdSeq.incrementAndGet(), msgData, null,
error ->
log.warn("Could not publish control reset res", error));
}
} else {
log.info("未获取到获取硬件RESET监控配置");
}
}
}
/**
* 黑白名单Reset接口处理 BlackList_allow || WhiteList_allow
*
* @param message
* @param requestId
* @param bizRequestId
* @param mqttRpcDataMessage
*/
private void resetBackWhiteListHandler(String message, int requestId, String bizRequestId, MqttRpcDataMessage
mqttRpcDataMessage) {
String method = mqttRpcDataMessage.getMethod();
if (!"BlackList_allow".equals(method) || !"WhiteList_allow".equals(method)) {
return;
}
String resetMethod = "BlackList";
if ("WhiteList_allow".equals(method)) {
resetMethod = "WhiteList";
}
try {
// 清空BlackList数据
MqttRpcDataMessage resetMqttRpcDataMessage = MqttRpcDataMessage.builder()
.sendTime(System.currentTimeMillis())
.method(resetMethod)
.params(null).build();
persistentFileService.flushRpcDataToFile(resetMqttRpcDataMessage);
// response
ObjectNode paramsNode = newNode();
paramsNode.put("code", "1");
paramsNode.put("msg", "success");
paramsNode.put("status", "success");
byte[] msgData = toBytes(newNode().put("requestId", bizRequestId).put("method", method)
.put("resTime", System.currentTimeMillis()).put("response", paramsNode.toString()));
persistMessage(DEVICE_RPC_RES_TOPIC + "/" + requestId, msgIdSeq.incrementAndGet(), msgData, null,
error ->
log.warn("Could not publish control reset res", error));
} catch (Exception e) {
log.error("APQ_HWPORT ERROR: {}", e.getMessage());
log.error("Failed to process rpc command persistent : {}", message, e);
ObjectNode paramsNode = newNode();
paramsNode.put("code", "0");
paramsNode.put("msg", "fail");
paramsNode.put("status", "fail");
byte[] msgData = toBytes(newNode().put("requestId", bizRequestId).put("method", method)
.put("resTime", System.currentTimeMillis()).put("response", paramsNode.toString()));
persistMessage(DEVICE_RPC_RES_TOPIC + "/" + requestId, msgIdSeq.incrementAndGet(), msgData, null,
error ->
log.warn("Could not publish control reset res", error));
}
}
/** /**
* 远程RPC处理 * 远程RPC处理
* *
...@@ -883,6 +1031,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -883,6 +1031,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
* @param mqttRpcDataMessage * @param mqttRpcDataMessage
*/ */
private void realDataMonitorScheduler(MqttRpcDataMessage mqttRpcDataMessage) { private void realDataMonitorScheduler(MqttRpcDataMessage mqttRpcDataMessage) {
decimalFormat.applyPattern("#.00");
// 持续时长 // 持续时长
Integer durationSeconds = JSONUtil.parseObj(mqttRpcDataMessage.getParams()).getInt("minutes", 1) * 60; Integer durationSeconds = JSONUtil.parseObj(mqttRpcDataMessage.getParams()).getInt("minutes", 1) * 60;
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
...@@ -900,13 +1049,13 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -900,13 +1049,13 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
String memoryOccupyRate = "memoryOccupyRate"; String memoryOccupyRate = "memoryOccupyRate";
String diskFree = "diskFree"; String diskFree = "diskFree";
// CPU负载 // CPU负载
double cpuLoadV = Double.parseDouble(new DecimalFormat("#.00").format(sigar.getCpuPerc().getCombined() * 100)); double cpuLoadV = Double.parseDouble(decimalFormat.format(sigar.getCpuPerc().getCombined() * 100));
int[] cpuAndGpuTemp = CoreTempUtil.getCpuAndGpuTemp(); int[] cpuAndGpuTemp = CoreTempUtil.getCpuAndGpuTemp();
// CPU温度 // CPU温度
double cpuTempV = cpuAndGpuTemp[0]; double cpuTempV = cpuAndGpuTemp[0];
Mem mem = sigar.getMem(); Mem mem = sigar.getMem();
// 内存占用率 // 内存占用率
double memoryOccupyRateV = Double.parseDouble(new DecimalFormat("#.00").format(mem.getUsed() * 1.0 / mem.getTotal() * 100)); double memoryOccupyRateV = Double.parseDouble(decimalFormat.format(mem.getUsed() * 1.0 / mem.getTotal() * 100));
// 磁盘使用容量 // 磁盘使用容量
String collect = null; String collect = null;
FileSystem[] diskStores; FileSystem[] diskStores;
...@@ -920,7 +1069,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -920,7 +1069,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
try { try {
FileSystemUsage usage = sigar.getFileSystemUsage(partition.getDirName()); FileSystemUsage usage = sigar.getFileSystemUsage(partition.getDirName());
return "\"" + StrUtil.removeSuffix(partition.getDevName(), ":\\") + "盘\":\"" + return "\"" + StrUtil.removeSuffix(partition.getDevName(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * (usage.getTotal() - usage.getFree()) / usage.getTotal()) + "%\""; decimalFormat.format(100d * (usage.getTotal() - usage.getFree()) / usage.getTotal()) + "%\"";
} catch (SigarException e) { } catch (SigarException e) {
log.error("SigarException: {}", e.getMessage()); log.error("SigarException: {}", e.getMessage());
} }
...@@ -1292,14 +1441,9 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -1292,14 +1441,9 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
return null; return null;
} }
MqttRpcDataMessage mqttRpcDataMessaget = MqttRpcDataMessage.builder() String allMacAddress = MacAddrUtil.getAllMacAddress();
.sendTime(System.currentTimeMillis())
.method("mac_addr")
.params(mac).build();
flushRpcDataToFile(mqttRpcDataMessaget);
macAddrService.initMacAddr(mac);
log.info("获取到MAC地址:{}", mac); log.info("获取到MAC地址:{},{}", mac, allMacAddress);
// deviceInfo = StrUtil.format(deviceInfo, mac); // deviceInfo = StrUtil.format(deviceInfo, mac);
...@@ -1307,6 +1451,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -1307,6 +1451,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
params.put("productId", productId); params.put("productId", productId);
params.put("tenantId", tenantId); params.put("tenantId", tenantId);
params.put("macAddress", mac); params.put("macAddress", mac);
params.put("allMacAddress", allMacAddress);
params.put("clientVersion", clientVersion); params.put("clientVersion", clientVersion);
Map<String, String> map = System.getenv(); Map<String, String> map = System.getenv();
...@@ -1319,6 +1464,15 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall ...@@ -1319,6 +1464,15 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
RemoteDeviceVoResult remoteDeviceVo = JSONUtil.toBean(remoteDeviceVoJson, RemoteDeviceVoResult.class); RemoteDeviceVoResult remoteDeviceVo = JSONUtil.toBean(remoteDeviceVoJson, RemoteDeviceVoResult.class);
MqttClientSecurityConfiguration mqttClientSecurityConfiguration = new MqttClientSecurityConfiguration(); MqttClientSecurityConfiguration mqttClientSecurityConfiguration = new MqttClientSecurityConfiguration();
mqttClientSecurityConfiguration.setAccessToken(remoteDeviceVo.getData().getSecretKey()); mqttClientSecurityConfiguration.setAccessToken(remoteDeviceVo.getData().getSecretKey());
String serverMac = remoteDeviceVo.getData().getMacAddress();
MqttRpcDataMessage mqttRpcDataMessaget = MqttRpcDataMessage.builder()
.sendTime(System.currentTimeMillis())
.method("mac_addr")
.params(serverMac).build();
flushRpcDataToFile(mqttRpcDataMessaget);
macAddrService.initMacAddr(serverMac);
return mqttClientSecurityConfiguration; return mqttClientSecurityConfiguration;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -27,6 +27,11 @@ public class RemoteDeviceVo implements Serializable { ...@@ -27,6 +27,11 @@ public class RemoteDeviceVo implements Serializable {
*/ */
private String bizCode; private String bizCode;
/**
* mac
*/
private String macAddress;
/** /**
* 秘钥 * 秘钥
*/ */
......
...@@ -22,7 +22,9 @@ import java.net.InetAddress; ...@@ -22,7 +22,9 @@ import java.net.InetAddress;
import java.net.SocketException; import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -40,6 +42,9 @@ public class DeviceInfoController { ...@@ -40,6 +42,9 @@ public class DeviceInfoController {
private Map<String, Object> info; private Map<String, Object> info;
private Locale enlocale = new Locale("en", "US");
private DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(enlocale);
@GetMapping(value = "get") @GetMapping(value = "get")
public R<Map<String, Object>> get() throws UnknownHostException, SocketException { public R<Map<String, Object>> get() throws UnknownHostException, SocketException {
if (info == null) refresh(); if (info == null) refresh();
...@@ -54,6 +59,8 @@ public class DeviceInfoController { ...@@ -54,6 +59,8 @@ public class DeviceInfoController {
JSONObject diskFree = null; JSONObject diskFree = null;
FileSystem[] diskStores; FileSystem[] diskStores;
decimalFormat.applyPattern("#.00");
try { try {
String diskStoresFromOshiJson = Oshi4NoneSigarUtil.getDiskStoresModelJsonFromOshi(); String diskStoresFromOshiJson = Oshi4NoneSigarUtil.getDiskStoresModelJsonFromOshi();
if (null != diskStoresFromOshiJson) { if (null != diskStoresFromOshiJson) {
...@@ -82,7 +89,7 @@ public class DeviceInfoController { ...@@ -82,7 +89,7 @@ public class DeviceInfoController {
try { try {
FileSystemUsage usage = sigar.getFileSystemUsage(partition.getDirName()); FileSystemUsage usage = sigar.getFileSystemUsage(partition.getDirName());
return "\"" + StrUtil.removeSuffix(partition.getDevName(), ":\\") + "盘\":\"" + return "\"" + StrUtil.removeSuffix(partition.getDevName(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * usage.getFree() / usage.getTotal()) + "%\""; decimalFormat.format(100d * usage.getFree() / usage.getTotal()) + "%\"";
} catch (SigarException e) { } catch (SigarException e) {
log.error("SigarException: {}", e.getMessage()); log.error("SigarException: {}", e.getMessage());
} }
......
...@@ -331,6 +331,7 @@ public class ProgramController { ...@@ -331,6 +331,7 @@ public class ProgramController {
+ " -fi " + '"' + "USERNAME ne Font Driver Host\\DWM-1" + '"' + " -fi " + '"' + "USERNAME ne Font Driver Host\\DWM-1" + '"'
+ " -fi " + '"' + "USERNAME ne 暂缺" + '"' + " -fi " + '"' + "USERNAME ne 暂缺" + '"'
+ " /fo csv"); + " /fo csv");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"))) {
reader.readLine(); reader.readLine();
String line; String line;
...@@ -378,6 +379,9 @@ public class ProgramController { ...@@ -378,6 +379,9 @@ public class ProgramController {
public static void main(String[] args) throws InterruptedException, IOException { public static void main(String[] args) throws InterruptedException, IOException {
String t = "{\"changeContent\":\"拔出U盘/移动硬盘\",\"changeRemark\":\"USB 大容量存储设备;;Storage Media;兼容 USB 存储设备;class\u003dUSB;\",\"changeType\":2,\"deviceClass\":\"USB_DRIVE\"}";
System.out.println(t);
/*int exitVal = -1; /*int exitVal = -1;
try { try {
exitVal = Runtime.getRuntime().exec("cmd /c \"D:\\work\\priusis\\priusis-iot\\apq-iot\\apq-client\\tools\\install-package\boot\\dist\\apq-info-install.exe\"").waitFor(); exitVal = Runtime.getRuntime().exec("cmd /c \"D:\\work\\priusis\\priusis-iot\\apq-iot\\apq-client\\tools\\install-package\boot\\dist\\apq-info-install.exe\"").waitFor();
...@@ -399,12 +403,12 @@ public class ProgramController { ...@@ -399,12 +403,12 @@ public class ProgramController {
// ================================================================= // =================================================================
String url = "http://apuqi.oss-cn-zhangjiakou.aliyuncs.com/ossdata/20220420/f65fe478633c43f493a0b60d13717504.exe"; /*String url = "http://apuqi.oss-cn-zhangjiakou.aliyuncs.com/ossdata/20220420/f65fe478633c43f493a0b60d13717504.exe";
String fileName = url.substring(url.lastIndexOf("/") + 1); String fileName = url.substring(url.lastIndexOf("/") + 1);
System.out.println(fileName); System.out.println(fileName);
Runtime.getRuntime().exec("cmd /c \"C:\\apqdownloads\\f65fe478633c43f493a0b60d13717504.exe\""); Runtime.getRuntime().exec("cmd /c \"C:\\apqdownloads\\f65fe478633c43f493a0b60d13717504.exe\"");
System.out.println(11); System.out.println(11);*/
} }
@Scheduled(fixedDelay = 360000) @Scheduled(fixedDelay = 360000)
......
...@@ -31,10 +31,8 @@ import oshi.util.FormatUtil; ...@@ -31,10 +31,8 @@ import oshi.util.FormatUtil;
import java.net.InetAddress; import java.net.InetAddress;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Arrays; import java.text.NumberFormat;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
...@@ -64,10 +62,13 @@ public class ApqInfoJob { ...@@ -64,10 +62,13 @@ public class ApqInfoJob {
private static Map<String, Map<String, String>> hardwareCache = new HashMap<>(); private static Map<String, Map<String, String>> hardwareCache = new HashMap<>();
private static Map<String, String> attrCache = new HashMap<>(); private static Map<String, String> attrCache = new HashMap<>();
private Locale enlocale = new Locale("en", "US");
private DecimalFormat decimalFormat = (DecimalFormat)NumberFormat.getNumberInstance(enlocale);
// 30秒一次上报 // 30秒一次上报
@Scheduled(fixedDelay = 30000L) @Scheduled(fixedDelay = 30000L)
protected void controlProgramTask() { protected void controlProgramTask() {
decimalFormat.applyPattern("#.00");
log.info("设备实时数据采集上报================="); log.info("设备实时数据采集上报=================");
runningIndex++; runningIndex++;
boolean isNoneEven = runningIndex % 2 == 0; boolean isNoneEven = runningIndex % 2 == 0;
...@@ -152,7 +153,7 @@ public class ApqInfoJob { ...@@ -152,7 +153,7 @@ public class ApqInfoJob {
try { try {
FileSystemUsage usage = sigar.getFileSystemUsage(partition.getDirName()); FileSystemUsage usage = sigar.getFileSystemUsage(partition.getDirName());
return "\"" + StrUtil.removeSuffix(partition.getDevName(), ":\\") + "盘\":\"" + return "\"" + StrUtil.removeSuffix(partition.getDevName(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * (usage.getTotal() - usage.getFree()) / usage.getTotal()) + "%\""; decimalFormat.format(100d * (usage.getTotal() - usage.getFree()) / usage.getTotal()) + "%\"";
} catch (SigarException e) { } catch (SigarException e) {
log.error("SigarException: {}", e.getMessage()); log.error("SigarException: {}", e.getMessage());
} }
...@@ -186,17 +187,22 @@ public class ApqInfoJob { ...@@ -186,17 +187,22 @@ public class ApqInfoJob {
org.hyperic.sigar.CpuInfo cpuInfo = sigar.getCpuInfoList()[0]; org.hyperic.sigar.CpuInfo cpuInfo = sigar.getCpuInfoList()[0];
cpuModelV = cpuInfo.getVendor() + " " + cpuInfo.getModel(); cpuModelV = cpuInfo.getVendor() + " " + cpuInfo.getModel();
cpuLoadV = Double.parseDouble(decimalFormat.format(sigar.getCpuPerc().getCombined() * 100));
} catch (Exception e) {
log.error("SigarException", e);
}
try {
Mem mem = sigar.getMem(); Mem mem = sigar.getMem();
memoryCapV = DataSizeUtil.format(mem.getTotal()); memoryCapV = DataSizeUtil.format(mem.getTotal());
cpuLoadV = Double.parseDouble(new DecimalFormat("#.00").format(sigar.getCpuPerc().getCombined() * 100)); log.info("===============mem:{}", mem.getUsed() * 1.0 / mem.getTotal() * 100);
memoryOccupyRateV = Double.parseDouble(new DecimalFormat("#.00").format(mem.getUsed() * 1.0 / mem.getTotal() * 100)); memoryOccupyRateV = Double.parseDouble(decimalFormat.format(mem.getUsed() * 1.0 / mem.getTotal() * 100));
memoryAvailableV = DataSizeUtil.format(mem.getUsed()) + "/" + DataSizeUtil.format(mem.getTotal()) memoryAvailableV = DataSizeUtil.format(mem.getUsed()) + "/" + DataSizeUtil.format(mem.getTotal())
+ "(" + memoryOccupyRateV + "%)"; + "(" + memoryOccupyRateV + "%)";
// OperatingSystem OS = OperatingSystem.getInstance(); // OperatingSystem OS = OperatingSystem.getInstance();
operatingSystemV = Oshi4NoneSigarUtil.getOsWithCache(); operatingSystemV = Oshi4NoneSigarUtil.getOsWithCache();
...@@ -206,7 +212,7 @@ public class ApqInfoJob { ...@@ -206,7 +212,7 @@ public class ApqInfoJob {
// 2. Thermal Zone的_TMP报告的一般是主板的某个温区,而不是CPU的温度 // 2. Thermal Zone的_TMP报告的一般是主板的某个温区,而不是CPU的温度
// 最佳实践 https://www.cnblogs.com/javawebsoa/archive/2013/05/31/3111351.html WinRing0.sys + rdmsr指令 // 最佳实践 https://www.cnblogs.com/javawebsoa/archive/2013/05/31/3111351.html WinRing0.sys + rdmsr指令
// cpuTempV = Double.parseDouble(new DecimalFormat("#.00").format(OshiUtil.getSensors().getCpuTemperature())); // cpuTempV = Double.parseDouble(decimalFormat.format(OshiUtil.getSensors().getCpuTemperature()));
int[] cpuAndGpuTemp = CoreTempUtil.getCpuAndGpuTemp(); int[] cpuAndGpuTemp = CoreTempUtil.getCpuAndGpuTemp();
cpuTempV = cpuAndGpuTemp[0]; cpuTempV = cpuAndGpuTemp[0];
gpuTempV = cpuAndGpuTemp[1]; gpuTempV = cpuAndGpuTemp[1];
......
...@@ -2,10 +2,12 @@ package com.priusis.job; ...@@ -2,10 +2,12 @@ package com.priusis.job;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.priusis.dto.NetPortControllerDto; import com.priusis.dto.NetPortControllerDto;
import com.priusis.utils.WinExecuteUtils; import com.priusis.utils.WinExecuteUtils;
import com.priusis.client.service.MqttRpcDataMessage; import com.priusis.client.service.MqttRpcDataMessage;
import jdk.nashorn.internal.ir.ObjectNode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
...@@ -15,7 +17,9 @@ import org.springframework.stereotype.Component; ...@@ -15,7 +17,9 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
@Slf4j @Slf4j
...@@ -32,7 +36,10 @@ public class ApqNetControlJob { ...@@ -32,7 +36,10 @@ public class ApqNetControlJob {
@Scheduled(fixedDelay = 60000L) @Scheduled(fixedDelay = 60000L)
protected void controlProgramTask() { protected void controlProgramTask() {
log.info("软件链路端口监控上报================="); log.info("软件链路端口监控上报=================");
controlPort();
}
private void controlPort() {
// 获取软件链路端口监控配置 params == data // 获取软件链路端口监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null; ResponseEntity<MqttRpcDataMessage> forEntity = null;
try { try {
...@@ -99,8 +106,38 @@ public class ApqNetControlJob { ...@@ -99,8 +106,38 @@ public class ApqNetControlJob {
executeCmdResult = WinExecuteUtils.executeCmd(doneShell1); executeCmdResult = WinExecuteUtils.executeCmd(doneShell1);
log.info("处理软件链路端口策略, doneShell:{}, executeCmdResult:{}", doneShell1, executeCmdResult); log.info("处理软件链路端口策略, doneShell:{}, executeCmdResult:{}", doneShell1, executeCmdResult);
} }
// MqttRpcDataMessage
Map eventMapRequest = new HashMap();
eventMapRequest.put("requestId", body.getRequestId());
eventMapRequest.put("bizRequestId", body.getBizRequestId());
eventMapRequest.put("method", "control_port");
Map paramsNode = new HashMap();
paramsNode.put("code", "1");
paramsNode.put("msg", "success");
paramsNode.put("status", "success");
eventMapRequest.put("params", paramsNode.toString());
Map map = restTemplate.postForObject("http://localhost:8765/rpc_res/oc-client", eventMapRequest, Map.class);
log.info("处理软件链路端口响应RES-SUCCESS: {}", map);
} catch (IOException e) { } catch (IOException e) {
log.error("软件链路端口监控上报异常", e.getMessage()); log.error("软件链路端口监控上报异常", e.getMessage());
Map eventMapRequest = new HashMap();
eventMapRequest.put("requestId", body.getRequestId());
eventMapRequest.put("bizRequestId", body.getBizRequestId());
eventMapRequest.put("method", "control_port");
Map paramsNode = new HashMap();
paramsNode.put("code", "0");
paramsNode.put("msg", "fail");
paramsNode.put("status", "fail");
eventMapRequest.put("params", paramsNode.toString());
Map map = restTemplate.postForObject("http://localhost:8765/rpc_res/oc-client", eventMapRequest, Map.class);
log.info("处理软件链路端口响应RES-FAIL: {}", map);
} }
} }
if (null != process && process.isAlive()) { if (null != process && process.isAlive()) {
......
package com.priusis.service.common; package com.priusis.service.common;
import com.priusis.client.service.MqttRpcDataMessage; import com.priusis.client.service.MqttRpcDataMessage;
import com.priusis.utils.MacAddrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -44,7 +43,7 @@ public class MacAddrService { ...@@ -44,7 +43,7 @@ public class MacAddrService {
} }
} }
if (null == macAddr) { if (null == macAddr) {
try { /*try {
macAddr = MacAddrUtil.getSigarMac(); macAddr = MacAddrUtil.getSigarMac();
MqttRpcDataMessage mqttRpcDataMessage = MqttRpcDataMessage.builder() MqttRpcDataMessage mqttRpcDataMessage = MqttRpcDataMessage.builder()
.sendTime(System.currentTimeMillis()) .sendTime(System.currentTimeMillis())
...@@ -53,7 +52,8 @@ public class MacAddrService { ...@@ -53,7 +52,8 @@ public class MacAddrService {
restTemplate.postForObject("http://localhost:8765/rpc_cmd", mqttRpcDataMessage, String.class); restTemplate.postForObject("http://localhost:8765/rpc_cmd", mqttRpcDataMessage, String.class);
} catch (Exception e) { } catch (Exception e) {
log.error("采集数据异常", e); log.error("采集数据异常", e);
} }*/
throw new RuntimeException("macAddr is null");
} }
} catch (RestClientException e) { } catch (RestClientException e) {
log.error("macAddr异常"); log.error("macAddr异常");
......
...@@ -5,8 +5,12 @@ import org.hyperic.sigar.NetFlags; ...@@ -5,8 +5,12 @@ import org.hyperic.sigar.NetFlags;
import org.hyperic.sigar.NetInterfaceConfig; import org.hyperic.sigar.NetInterfaceConfig;
import org.hyperic.sigar.Sigar; import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate; import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* @author yangli * @author yangli
...@@ -35,7 +39,42 @@ public final class MacAddrUtil { ...@@ -35,7 +39,42 @@ public final class MacAddrUtil {
return null; return null;
} }
public static String getAllMacAddress() {
Set<String> macSet = new HashSet<>();
byte[] mac = null;
try {
//获取所有的网络接口
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
while (allNetInterfaces.hasMoreElements()) {
//遍历每一个网络接口
NetworkInterface netInterface = allNetInterfaces.nextElement();
//若是网路接口是:1回环接口 2虚拟网口 3网口状态为unUser,则跳过
if (netInterface.isLoopback() || netInterface.isVirtual()/* || !netInterface.isUp()*/) {
continue;
} else {
String macAppend = "";
mac = netInterface.getHardwareAddress();
if (mac != null) {
for (int i = 0; i < mac.length; i++) {
macAppend += String.format("%02X%s", mac[i], (i < mac.length - 1) ? ":" : "");
}
macSet.add(macAppend);
}
}
}
} catch (Exception e) {
log.error("IP地址获取失败", e);
}
if (macSet.size() > 0) {
return macSet.stream().collect(Collectors.joining(","));
}
return "";
}
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("本机MAC:" + getAllMacAddress());
System.out.println(MacAddrUtil.getSigarMac()); System.out.println(MacAddrUtil.getSigarMac());
} }
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#define MyAppURL "https://www.apq.com/" #define MyAppURL "https://www.apq.com/"
#define MyAppDirName "apq-client" #define MyAppDirName "apq-client"
#define MyAppEnName "apq-client" #define MyAppEnName "apq-client"
#define MyAppExeName "apq-client.exe" #define MyAppExeName "apq-client.exe"
; apq-iot-client ; apq-iot-client
#define MyAppInstallPwd "2a96d11973c7caa1a72eb816d7db6d17" #define MyAppInstallPwd "2a96d11973c7caa1a72eb816d7db6d17"
; hk-remove2022 ; hk-remove2022
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论