现场测试调整

This commit is contained in:
tiger_zhou 2023-12-04 08:54:02 +08:00
parent 690499ecfa
commit c9b8724195
6 changed files with 97 additions and 11 deletions

View File

@ -64,11 +64,11 @@
<version>2.0.2</version>
</dependency>
<!--设备状态采集 cpu,内存,硬盘等-->
<!--<dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.4.8</version>
</dependency>-->
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>

View File

@ -3,13 +3,17 @@ package club.joylink.xiannccda.ats.message;
import club.joylink.xiannccda.ats.message.line3.changer.DeviceNameChangerManage;
import com.google.common.collect.Maps;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import oshi.SystemInfo;
import oshi.software.os.OSProcess;
/**
* OCC客户端管理
@ -31,6 +35,9 @@ public class OccMessageManage implements ApplicationRunner {
private Boolean collectorData;
@Value("${receive-msg-timeout:6}")
private Integer receiveMsgTimeout;
@Value("${monitor-handware-change:false}")
private boolean monitorHandwareChange;
Map<Integer, XianOccMessagingClient> clientMap = new HashMap<>();
public void sendMsg(Integer lineId, MessageData md, boolean isRealTime) {
@ -48,12 +55,13 @@ public class OccMessageManage implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("初始化 occ tcp连接....");
log.info("初始化 occ tcp连接.... 是否监控cpu内存信息:{}", this.monitorHandwareChange);
DeviceNameChangerManage.init();
// 读取数据配置创建客户端
this.registerClient(new XianOccMessagingClient(this.lineId, this.realPort, this.unRealPort, this.serverHost, this.collectorData, receiveMsgTimeout));
for (XianOccMessagingClient client : this.clientMap.values()) {
client.connect();
client.connect(this.monitorHandwareChange);
}
}
}

View File

@ -80,7 +80,7 @@ public class OccTcpClientConnection {
void reconnect() {
if (this.channel != null) {
this.channel.close();
this.reconnectState.resetState();
// this.reconnectState.resetState();
} else {
this.connect();
}
@ -110,7 +110,7 @@ public class OccTcpClientConnection {
this.channel = null;
this.client.resetRequestBaseDataFlag();
}
// this.reconnectState.resetState();
this.reconnectState.resetState();
});
}

View File

@ -2,7 +2,6 @@ package club.joylink.xiannccda.ats.message;
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest;
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum;
import java.sql.Time;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.Objects;
@ -12,6 +11,10 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.GlobalMemory;
@Slf4j
public class XianOccMessagingClient {
@ -92,8 +95,10 @@ public class XianOccMessagingClient {
/**
* 连接OCC服务
*/
public void connect() {
public void connect(boolean monitorHandwareChange) {
this.timeOutHandler.monitorHandwareChange = monitorHandwareChange;
this.timeOutHandler.start();
}
@Getter
@ -115,13 +120,78 @@ public class XianOccMessagingClient {
static final ScheduledExecutorService Executor = Executors.newSingleThreadScheduledExecutor();
private final LinkedList<OccTcpClientConnection> clientConnections = new LinkedList<>();
private final SystemInfo systemInfo;
// private long[] ticks = null;
private boolean monitorHandwareChange;
// private OSProcess osProcess;
// private Integer processId;
private long[] ticks;
public ConnectionTimeOutHandler() {
this.systemInfo = new SystemInfo();
/* List<OSProcess> osProcesses = systemInfo.getOperatingSystem().getProcesses();
for (OSProcess osProcess : osProcesses) {
String processName = osProcess.getName();
if (StringUtils.contains(processName, "java")) {
log.info(osProcess.getArguments().toString());
for (String arg : osProcess.getArguments()) {
if (StringUtils.containsAny(arg, "XianNccDaApplication", "xian-ncc-da")) {
*//*System.out.println(osProcess.getProcessID());
System.out.println(osProcess.getName());
System.out.println(osProcess.getProcessCpuLoadBetweenTicks(osProcess) * 100);*//*
this.osProcess = osProcess;
this.processId = osProcess.getProcessID();
}
}
}
}*/
}
public void addConnection(OccTcpClientConnection conn) {
this.clientConnections.add(conn);
}
private String hardWareUserInfo() {
CentralProcessor cpu = systemInfo.getHardware().getProcessor();
GlobalMemory memory = systemInfo.getHardware().getMemory();
if (Objects.isNull(ticks)) {
ticks = cpu.getSystemCpuLoadTicks();
} else {
double d2 = cpu.getSystemCpuLoadBetweenTicks(ticks);
ticks = cpu.getSystemCpuLoadTicks();
long totalMemory = memory.getTotal();
long availableMemory = memory.getAvailable();
long usedMemory = totalMemory - availableMemory;
return String.format("当前CPU使用:%d%% 内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", Math.round(d2 * 100), (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024),
(availableMemory / 1024 / 1024));
}
return null;
/* GlobalMemory memory = systemInfo.getHardware().getMemory();
long totalMemory = memory.getTotal();
long availableMemory = memory.getAvailable();
long usedMemory = totalMemory - availableMemory;
if (Objects.isNull(this.osProcess)) {
return String.format("内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024),
(availableMemory / 1024 / 1024));
} else {
OSProcess osp = this.systemInfo.getOperatingSystem().getProcess(this.processId);
double d2 = this.osProcess.getProcessCpuLoadBetweenTicks(osp);
return String.format("当前CPU使用:%d%% 内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", Math.round(d2 * 100), (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024),
(availableMemory / 1024 / 1024));
}*/
}
public void start() {
Executor.scheduleWithFixedDelay(() -> {
if (this.monitorHandwareChange) {
String moitorContent = this.hardWareUserInfo();
if (StringUtils.isNotEmpty(moitorContent)) {
log.info(moitorContent);
}
}
for (OccTcpClientConnection cc : this.clientConnections) {
if (cc.connected) {
long ctm = System.currentTimeMillis();
@ -135,6 +205,7 @@ public class XianOccMessagingClient {
}
}, Period, Period, TimeUnit.SECONDS);
}
}
}

View File

@ -144,6 +144,7 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
AlertDeviceType.DEVICE_TYPE_PLATFORM,
false);
alertManager.emit(alertInfo);
this.removeTrainRecord(record);
}
// this.removeTrainRecordOnly(record);
}
@ -174,6 +175,7 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
"列车开关过屏蔽门只是等待,线路[{}] 列车表号[{}] 列车车次号[{}] 车站id[{}] 站台门id[{}] 上下行[{}] 解析屏蔽门code[{}],接收时间[{}] ",
record.getLineId(), record.getTrainId(), record.getGlobalId(), record.getStationId(), record.getSideId(), isUpWay, platformBuild.getId(), platformBuild.getReceiveTime());
}
this.removeTrainRecord(record);
continue;
}
InUsedScheduleData scheduleData = DeviceDataRepository.findDataSouce(String.valueOf(record.getLineId()), DataTypeEnum.TRAIN_PLAN);
@ -183,6 +185,7 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
log.info("未找到对应的行车计划,线路[{}] 列车表号[{}] 列车车次号[{}] 车站id[{}] 站台门id[{}] 上下行[{}] 解析屏蔽门code[{}]"
, record.getLineId(), record.getTrainId(), record.getGlobalId(), record.getStationId(), record.getSideId(), isUpWay, platformBuild.getId());
}
this.removeTrainRecord(record);
continue;
}
Plan.Builder planBuild = planBuildOpt.get();

View File

@ -12,9 +12,12 @@ spring:
auto-commit: true #配置从池返回的连接的默认自动提交行为
idle-timeout: 60000 # 允许连接在连接池中空闲的最长时间单位ms
pool-name: HikariPool
max-lifetime: 0 # 池中连接关闭后的最长生命周期单位ms
# max-lifetime: 1800000 # 池中连接关闭后的最长生命周期单位ms
max-lifetime: 300000 # 池中连接关闭后的最长生命周期单位ms
connection-timeout: 60000 # 等待连接的超时时间单位ms
connection-test-query: select 1
leak-detection-threshold: 20000
# validation-timeout: 10000
key:
public: classpath:app.pub
@ -47,5 +50,6 @@ jwt:
occ-not-handle-rtu: '{3: "81,82"}'
#长时间没有接收occ数据超时重新获取基础数据时间小时
receive-msg-timeout: 1
#检测硬件变化(cpu,内存)
monitor-handware-change: true