提交 6c622901 authored 作者: wangqiang's avatar wangqiang

install service

上级 73d2dcb6
......@@ -48,8 +48,10 @@ public class DeviceInfoController {
JSONObject diskModel = null;
JSONObject diskCap = null;
JSONObject diskFree = null;
HWDiskStore[] diskStores = null;
try {
diskModel = JSONUtil.parseObj(Arrays.stream(OshiUtil.getHardware().getDiskStores())
diskStores = OshiUtil.getHardware().getDiskStores();
diskModel = JSONUtil.parseObj(Arrays.stream(diskStores)
.map(store -> Arrays.stream(store.getPartitions())
.map(HWPartition::getMountPoint)
.filter(StrUtil::isNotBlank)
......@@ -58,14 +60,14 @@ public class DeviceInfoController {
.collect(Collectors.joining(",")))
.filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",", "{", "}")));
diskCap = JSONUtil.parseObj(Arrays.stream(OshiUtil.getHardware().getDiskStores())
diskCap = JSONUtil.parseObj(Arrays.stream(diskStores)
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
DataSizeUtil.format(partition.getSize()) + "\"")
.collect(Collectors.joining(",", "{", "}")));
diskFree = JSONUtil.parseObj(Arrays.stream(OshiUtil.getHardware().getDiskStores())
diskFree = JSONUtil.parseObj(Arrays.stream(diskStores)
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
......@@ -74,6 +76,16 @@ public class DeviceInfoController {
.collect(Collectors.joining(",", "{", "}")));
} catch (Exception e) {
log.error("硬盘数据获取失败", e);
if (null != diskStores) {
for (HWDiskStore diskStore : diskStores) {
HWPartition[] partitions = diskStore.getPartitions();
if (null != partitions) {
for (HWPartition partition : partitions) {
log.error("硬盘数据获取失败: {}", partition.getMountPoint());
}
}
}
}
}
info = MapUtil.<String, Object>builder()
.put("operatingSystem", OshiUtil.getOs().toString())
......
package com.priusis.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApqInfoDataVo implements Serializable {
private String code;
private String name;
private int frequency;
}
package com.priusis.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class MqttRpcDataMessage implements Serializable {
private static final long serialVersionUID = -3133461476074777891L;
private int requestId;
private String method;
private String params;
@Override
public String toString() {
return "{requestId=" + requestId +
", method=" + method +
", params=" + params +
'}';
}
}
......@@ -70,7 +70,7 @@ IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO runing apq-pc-client ...
@ECHO running apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
......
......@@ -70,7 +70,7 @@ IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO runing apq-pc-client ...
@ECHO running apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
......
......@@ -8,7 +8,6 @@ import com.priusis.utils.IHwPortController;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
......@@ -16,7 +15,6 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
......@@ -42,6 +40,10 @@ public class ApqControlApplication {
@Scheduled(fixedDelay = 60000L)
protected void controlProgramTask() {
log.info("硬件监控上报=================");
// todo
//testUsb();
// 获取硬件监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
......@@ -199,4 +201,20 @@ public class ApqControlApplication {
//log.info("APQ_HWPORT_Uninitialize ret:{}", result2);
}
}
public void testUsb() {
// 初始化硬件接口管理模块
int result = IHwPortController.instanceDll.APQ_HWPORT_Initialize();
log.info("APQ_HWPORT_Initialize ret:{}", result);
// APQ_HWPORT_STORAGE_PERM_ALLOW APQ_HWPORT_STORAGE_PERM_DENY
int result32 = IHwPortController.instanceDll.APQ_HWPORT_set_storage_device_permit(IHwPortController.HwportStorageDevidEnum.APQ_HWPORT_STORAGE_DEVID_UDISK.getCode(), IHwPortController.HwportStoragePermEnum.APQ_HWPORT_STORAGE_PERM_ALLOW.getCode(), null);
log.info("APQ_HWPORT_set_storage_device_permit ret:{}", result32);
//应用硬件接口管理模块的配置内容
int result5 = IHwPortController.instanceDll.APQ_HWPORT_Apply();
log.info("APQ_HWPORT_Apply ret:{}", result5);
int result2 = IHwPortController.instanceDll.APQ_HWPORT_Uninitialize();
log.info("APQ_HWPORT_Uninitialize ret:{}", result2);
}
}
......@@ -5,4 +5,5 @@ spring:
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[10000,19999]}
# port: ${random.int[10000,19999]}
port: 8762
\ No newline at end of file
package com.priusis.controller;
import cn.hutool.core.io.unit.DataSizeUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.system.oshi.CpuInfo;
import cn.hutool.system.oshi.OshiUtil;
import com.priusis.lib.R;
import com.priusis.util.MacAddrUtil;
import com.priusis.vo.ApqInfoDataVo;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HWPartition;
import java.io.File;
import java.io.IOException;
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.util.stream.Collectors;
/**
* @author yangli
* @since 2021/09/10
*/
@Slf4j
@Validated
@RestController
@RequestMapping(value = "info")
public class InfoController {
@Autowired
private RestTemplate restTemplate;
@GetMapping(value = "read_post")
public R<Map<String, Object>> getDownloadPath() throws IOException {
boolean isNoneEven = false;
// 获取采集配置,数据上报频率 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
Map<String, Integer> mapParams = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/info", MqttRpcDataMessage.class);
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
List<ApqInfoDataVo> apqInfoDataVos = JSONUtil.toList(params, ApqInfoDataVo.class);
mapParams = new HashMap<>();
for (ApqInfoDataVo apqInfoDataVo : apqInfoDataVos) {
mapParams.put(apqInfoDataVo.getCode(), apqInfoDataVo.getFrequency());
}
}
}
} catch (Exception e) {
log.error("采集数据异常", e);
}
String operatingSystem = "operatingSystem";
String mac = "mac";
String baseboard = "baseboard";
String ip = "ip";
String cpuModel = "cpuModel";
String cpuLoad = "cpuLoad";
String cpuTemp = "cpuTemp";
String memoryCap = "memoryCap";
String memoryAvailable = "memoryAvailable";
String diskModel = "diskModel";
String diskCap = "diskCap";
String diskFree = "diskFree";
Map<String, Object> data = null;
try {
// 上报PC实时信息
String collect = null;
String collect1 = null;
String collect2 = null;
try {
collect = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
DataSizeUtil.format(partition.getSize()) + "\"")
.collect(Collectors.joining(",", "{", "}"));
collect1 = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(store -> Arrays.stream(store.getPartitions())
.map(HWPartition::getMountPoint)
.filter(StrUtil::isNotBlank)
.map(s -> "\"" + StrUtil.removeSuffix(s, ":\\") + "盘\":\"" +
StrUtil.removeSuffix(store.getModel(), " (标准磁盘驱动器)") + "\"")
.collect(Collectors.joining(",")))
.filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",", "{", "}"));
collect2 = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * new File(partition.getMountPoint()).getFreeSpace() / partition.getSize()) + "%\"")
.collect(Collectors.joining(",", "{", "}"));
} catch (Exception e) {
log.error("硬盘数据获取失败", e);
}
data = MapUtil.<String, Object>builder()
.put(isNeedCollection(isNoneEven, operatingSystem, mapParams), operatingSystem, OshiUtil.getOs().toString())
.put(isNeedCollection(isNoneEven, mac, mapParams), mac, MacAddrUtil.get())
.put(isNeedCollection(isNoneEven, baseboard, mapParams), baseboard, OshiUtil.getSystem().getBaseboard().getManufacturer() + " " + OshiUtil.getSystem().getBaseboard().getVersion())
.put(isNeedCollection(isNoneEven, ip, mapParams), ip, InetAddress.getLocalHost().getHostAddress())
.put(isNeedCollection(isNoneEven, cpuModel, mapParams), cpuModel, OshiUtil.getCpuInfo(0).getCpuModel())
.put(isNeedCollection(isNoneEven, cpuTemp, mapParams), cpuTemp, Double.parseDouble(new DecimalFormat("#.00").format(OshiUtil.getSensors().getCpuTemperature())))
.put(isNeedCollection(isNoneEven, cpuLoad, mapParams), cpuLoad, getCpuUsed())
.put(isNeedCollection(isNoneEven, memoryCap, mapParams), memoryCap, DataSizeUtil.format(OshiUtil.getMemory().getTotal()))
.put(isNeedCollection(isNoneEven, memoryAvailable, mapParams), memoryAvailable, DataSizeUtil.format(OshiUtil.getMemory().getAvailable()))
.put(isNeedCollection(isNoneEven, diskModel, mapParams), diskModel, collect1)
.put(isNeedCollection(isNoneEven, diskCap, mapParams), diskCap, collect)
.put(isNeedCollection(isNoneEven, diskFree, mapParams), diskFree, collect2)
.build();
log.info("采集数据,上报属性: mapData:{}", data);
Map mapR = restTemplate.postForObject("http://localhost:8765/uplink/oc-client", data, Map.class);
log.info("采集数据,上报属性: ret:{}", mapR);
} catch (Exception e) {
log.error("采集数据异常", e);
data = MapUtil.<String, Object>builder().put("ERROR", e.getMessage()).build();
}
return R.success(data);
}
private boolean isNeedCollection(boolean isNoneEven, String key, Map<String, Integer> mapParams) {
if (null != mapParams && mapParams.containsKey(key)) {
return (!isNoneEven || mapParams.get(key) != 30);
} else {
return isNoneEven;
}
}
public static double getCpuUsed() {
CpuInfo cpuInfo = OshiUtil.getCpuInfo(100);
double used = Double.parseDouble(new DecimalFormat("#.00").format(100 - cpuInfo.getFree()));
return Math.min(Math.max(used, 0), 100);
}
}
package com.priusis.lib;
import lombok.Getter;
@Getter
public class R<T> {
private final int code;
private final String msg;
private final T data;
private R(int code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public static <T> R<T> success(T data) {
return new R<>(0, "SUCCESS", data);
}
public static <T> R<T> success() {
return success(null);
}
public static <T> R<T> error(int code, String msg, T data) {
return new R<>(code, msg, data);
}
public static <T> R<T> error(int code, String msg) {
return error(code, msg, null);
}
public static <T> R<T> error(String msg) {
return error(500, msg);
}
public static <T> R<T> error() {
return error("系统异常");
}
}
......@@ -5,4 +5,5 @@ spring:
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[10000,19999]}
# port: ${random.int[10000,19999]}
port: 8764
......@@ -46,11 +46,10 @@ public class ApqRegisterApplication {
@Scheduled(fixedDelay = 30000L)
protected void registerProgramTask() {
log.info("软件检测上报=================");
/*
log.info("===================");
try {
WinExecuteUtils.killProc("Postman.exe");
} catch (Exception e) {
/* try {
WinExecuteUtils.killProc("TIM.exe");
} catch (IOException e) {
log.error("杀进程异常", e);
}*/
......
......@@ -5,4 +5,5 @@ spring:
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[30000,39999]}
# port: ${random.int[30000,39999]}
port: 8763
\ No newline at end of file
......@@ -17,7 +17,7 @@
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes
DisableDirPage=no
AlwaysRestart=yes
; AlwaysRestart=yes
AppId={{1394783A-5D3C-48CD-0000-E2DFBB844E42}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
......
......@@ -4,7 +4,7 @@ setlocal ENABLEEXTENSIONS
@ECHO Installing apq-client ...
"%~dp0apq-client-service.exe" install
@ECHO runing apq-client ...
@ECHO running apq-client ...
"%~dp0apq-client-service.exe" start
@ECHO DONE.
......
No preview for this file type
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论