提交 a8883a20 authored 作者: yangli's avatar yangli

Merge remote-tracking branch 'origin/master'

......@@ -5,6 +5,14 @@
<springProperty scop="context" name="CONSOLE_LOG_PATH" source="CONSOLE_LOG_PATH" defaultValue="/apps/logs"/>
<property name="log.path" value="${CONSOLE_LOG_PATH}/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="fileLogAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
......@@ -29,6 +37,7 @@
<logger name="com.alibaba.nacos" level="ERROR"/>
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="fileLogAppender"/>
</root>
......
......@@ -70,6 +70,8 @@ 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 ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
......
<service>
<id>apq-pc-client</id>
<name>${project.name}</name>
<description>${project.description}</description>
<name>apq-pc-client</name>
<description>apq-pc-client</description>
<workingdirectory>%BASE%\conf</workingdirectory>
<logpath>${pkg.winWrapperLogFolder}</logpath>
<logpath>logs</logpath>
<logmode>rotate</logmode>
<env name="LOADER_PATH" value="%BASE%\conf" />
<executable>java</executable>
......
......@@ -93,7 +93,6 @@
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
......
......@@ -15,6 +15,7 @@ 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;
......@@ -39,8 +40,14 @@ public class ApqControlApplication {
@Scheduled(fixedDelay = 60000L)
protected void controlProgramTask() {
log.info("硬件监控上报=================");
// 获取硬件监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/controll", MqttRpcDataMessage.class);
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/controll", MqttRpcDataMessage.class);
} catch (Exception e) {
log.error("硬件监控上报异常", e);
}
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
......@@ -186,7 +193,5 @@ public class ApqControlApplication {
} else {
log.info("未获取到获取硬件监控配置");
}
}
}
......@@ -5,6 +5,13 @@
<springProperty scop="context" name="CONSOLE_LOG_PATH" source="CONSOLE_LOG_PATH" defaultValue="/apps/logs"/>
<property name="log.path" value="${CONSOLE_LOG_PATH}/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="fileLogAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
......@@ -29,6 +36,7 @@
<logger name="com.alibaba.nacos" level="ERROR"/>
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="fileLogAppender"/>
</root>
......
......@@ -87,7 +87,6 @@
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
......
package com.priusis;
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.OshiUtil;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestTemplate;
import oshi.hardware.NetworkIF;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Map;
@Slf4j
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqInfoApplication {
@Autowired
private RestTemplate restTemplate;
private int runningIndex = 0;
public static void main(String[] args) {
SpringApplication.run(ApqInfoApplication.class, args);
}
// 30秒一次上报
@Scheduled(fixedDelay = 30000L)
protected void controlProgramTask() {
log.info("设备实时数据采集上报=================");
runningIndex++;
boolean isNoneEven = runningIndex % 2 == 0;
// 获取采集配置,数据上报频率 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)) {
mapParams = JSONUtil.toBean(params, Map.class);
}
}
} catch (Exception e) {
log.error("采集数据异常", e);
}
String operatingSystem = "operatingSystem";
String mac = "mac";
String baseboard = "baseboard";
String ip = "ip";
String cpuModel = "cpuModel";
String cpuTemp = "cpuTemp";
String memoryCap = "memoryCap";
String diskModel = "diskModel";
String diskCap = "diskCap";
try {
// 上报PC实时信息
InetAddress inetAddress = InetAddress.getLocalHost();
NetworkIF networkIF = new NetworkIF();
networkIF.setNetworkInterface(NetworkInterface.getByInetAddress(inetAddress));
Map<String, Object> data = MapUtil.<String, Object>builder()
.put(isNeedCollection(isNoneEven, operatingSystem, mapParams), operatingSystem, OshiUtil.getOs().toString())
.put(isNeedCollection(isNoneEven, mac, mapParams), mac, networkIF.getMacaddr())
.put(isNeedCollection(isNoneEven, baseboard, mapParams), baseboard, OshiUtil.getSystem().getBaseboard().getManufacturer() + " " + OshiUtil.getSystem().getBaseboard().getVersion())
.put(isNeedCollection(isNoneEven, ip, mapParams), ip, inetAddress.getHostAddress())
.put(isNeedCollection(isNoneEven, cpuModel, mapParams), cpuModel, OshiUtil.getCpuInfo(0).getCpuModel())
.put(isNeedCollection(isNoneEven, cpuTemp, mapParams), cpuTemp, OshiUtil.getSensors().getCpuTemperature())
.put(isNeedCollection(isNoneEven, memoryCap, mapParams), memoryCap, DataSizeUtil.format(OshiUtil.getMemory().getTotal()))
.put(isNeedCollection(isNoneEven, diskModel, mapParams), diskModel, OshiUtil.getHardware().getDiskStores()[0].getModel())
.put(isNeedCollection(isNoneEven, diskCap, mapParams), diskCap, DataSizeUtil.format(OshiUtil.getHardware().getDiskStores()[0].getSize()))
.build();
Map mapR = restTemplate.postForObject("http://localhost:8765/uplink/oc-client", data, Map.class);
log.info("采集数据,上报属性: mapData:{}, ret:{}", data, mapR);
} catch (Exception e) {
log.error("采集数据异常", e);
}
}
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;
}
}
}
......@@ -5,6 +5,13 @@
<springProperty scop="context" name="CONSOLE_LOG_PATH" source="CONSOLE_LOG_PATH" defaultValue="/apps/logs"/>
<property name="log.path" value="${CONSOLE_LOG_PATH}/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="fileLogAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
......@@ -29,6 +36,7 @@
<logger name="com.alibaba.nacos" level="ERROR"/>
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="fileLogAppender"/>
</root>
......
......@@ -83,7 +83,6 @@
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
......
......@@ -13,6 +13,7 @@ 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.io.BufferedReader;
......@@ -50,8 +51,14 @@ public class ApqRegisterApplication {
@Scheduled(fixedDelay = 60000L)
protected void registerProgramTask() {
log.info("软件检测上报=================");
// 获取软件检测监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/register", MqttRpcDataMessage.class);
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/register", MqttRpcDataMessage.class);
} catch (RestClientException e) {
log.error("软件检测上报异常", e);
}
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
......
......@@ -5,6 +5,13 @@
<springProperty scop="context" name="CONSOLE_LOG_PATH" source="CONSOLE_LOG_PATH" defaultValue="/apps/logs"/>
<property name="log.path" value="${CONSOLE_LOG_PATH}/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="fileLogAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
......@@ -29,6 +36,7 @@
<logger name="com.alibaba.nacos" level="ERROR"/>
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="fileLogAppender"/>
</root>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论