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

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

上级 19ae21c8
......@@ -27,6 +27,11 @@ public class RemoteDeviceVo implements Serializable {
*/
private String bizCode;
/**
* mac
*/
private String macAddress;
/**
* 秘钥
*/
......
......@@ -22,7 +22,9 @@ import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -40,6 +42,9 @@ public class DeviceInfoController {
private Map<String, Object> info;
private Locale enlocale = new Locale("en", "US");
private DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(enlocale);
@GetMapping(value = "get")
public R<Map<String, Object>> get() throws UnknownHostException, SocketException {
if (info == null) refresh();
......@@ -54,6 +59,8 @@ public class DeviceInfoController {
JSONObject diskFree = null;
FileSystem[] diskStores;
decimalFormat.applyPattern("#.00");
try {
String diskStoresFromOshiJson = Oshi4NoneSigarUtil.getDiskStoresModelJsonFromOshi();
if (null != diskStoresFromOshiJson) {
......@@ -82,7 +89,7 @@ public class DeviceInfoController {
try {
FileSystemUsage usage = sigar.getFileSystemUsage(partition.getDirName());
return "\"" + StrUtil.removeSuffix(partition.getDevName(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * usage.getFree() / usage.getTotal()) + "%\"";
decimalFormat.format(100d * usage.getFree() / usage.getTotal()) + "%\"";
} catch (SigarException e) {
log.error("SigarException: {}", e.getMessage());
}
......
......@@ -331,6 +331,7 @@ public class ProgramController {
+ " -fi " + '"' + "USERNAME ne Font Driver Host\\DWM-1" + '"'
+ " -fi " + '"' + "USERNAME ne 暂缺" + '"'
+ " /fo csv");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"))) {
reader.readLine();
String line;
......@@ -378,6 +379,9 @@ public class ProgramController {
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;
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();
......@@ -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);
System.out.println(fileName);
Runtime.getRuntime().exec("cmd /c \"C:\\apqdownloads\\f65fe478633c43f493a0b60d13717504.exe\"");
System.out.println(11);
System.out.println(11);*/
}
@Scheduled(fixedDelay = 360000)
......
......@@ -31,10 +31,8 @@ import oshi.util.FormatUtil;
import java.net.InetAddress;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.NumberFormat;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
......@@ -64,10 +62,13 @@ public class ApqInfoJob {
private static Map<String, Map<String, String>> hardwareCache = 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秒一次上报
@Scheduled(fixedDelay = 30000L)
protected void controlProgramTask() {
decimalFormat.applyPattern("#.00");
log.info("设备实时数据采集上报=================");
runningIndex++;
boolean isNoneEven = runningIndex % 2 == 0;
......@@ -152,7 +153,7 @@ public class ApqInfoJob {
try {
FileSystemUsage usage = sigar.getFileSystemUsage(partition.getDirName());
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) {
log.error("SigarException: {}", e.getMessage());
}
......@@ -186,17 +187,22 @@ public class ApqInfoJob {
org.hyperic.sigar.CpuInfo cpuInfo = sigar.getCpuInfoList()[0];
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();
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())
+ "(" + memoryOccupyRateV + "%)";
// OperatingSystem OS = OperatingSystem.getInstance();
operatingSystemV = Oshi4NoneSigarUtil.getOsWithCache();
......@@ -206,7 +212,7 @@ public class ApqInfoJob {
// 2. Thermal Zone的_TMP报告的一般是主板的某个温区,而不是CPU的温度
// 最佳实践 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();
cpuTempV = cpuAndGpuTemp[0];
gpuTempV = cpuAndGpuTemp[1];
......
......@@ -2,10 +2,12 @@ package com.priusis.job;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.priusis.dto.NetPortControllerDto;
import com.priusis.utils.WinExecuteUtils;
import com.priusis.client.service.MqttRpcDataMessage;
import jdk.nashorn.internal.ir.ObjectNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
......@@ -15,7 +17,9 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
......@@ -32,7 +36,10 @@ public class ApqNetControlJob {
@Scheduled(fixedDelay = 60000L)
protected void controlProgramTask() {
log.info("软件链路端口监控上报=================");
controlPort();
}
private void controlPort() {
// 获取软件链路端口监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
......@@ -99,8 +106,38 @@ public class ApqNetControlJob {
executeCmdResult = WinExecuteUtils.executeCmd(doneShell1);
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) {
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()) {
......
package com.priusis.service.common;
import com.priusis.client.service.MqttRpcDataMessage;
import com.priusis.utils.MacAddrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
......@@ -44,7 +43,7 @@ public class MacAddrService {
}
}
if (null == macAddr) {
try {
/*try {
macAddr = MacAddrUtil.getSigarMac();
MqttRpcDataMessage mqttRpcDataMessage = MqttRpcDataMessage.builder()
.sendTime(System.currentTimeMillis())
......@@ -53,7 +52,8 @@ public class MacAddrService {
restTemplate.postForObject("http://localhost:8765/rpc_cmd", mqttRpcDataMessage, String.class);
} catch (Exception e) {
log.error("采集数据异常", e);
}
}*/
throw new RuntimeException("macAddr is null");
}
} catch (RestClientException e) {
log.error("macAddr异常");
......
......@@ -5,8 +5,12 @@ import org.hyperic.sigar.NetFlags;
import org.hyperic.sigar.NetInterfaceConfig;
import org.hyperic.sigar.Sigar;
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
......@@ -35,7 +39,42 @@ public final class MacAddrUtil {
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) {
System.out.println("本机MAC:" + getAllMacAddress());
System.out.println(MacAddrUtil.getSigarMac());
}
}
......@@ -7,7 +7,7 @@
#define MyAppURL "https://www.apq.com/"
#define MyAppDirName "apq-client"
#define MyAppEnName "apq-client"
#define MyAppExeName "apq-client.exe"
#define MyAppExeName "apq-client.exe"
; apq-iot-client
#define MyAppInstallPwd "2a96d11973c7caa1a72eb816d7db6d17"
; hk-remove2022
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论