优化服务器列表查询速度、筛选条件bug修复。

ipv4、ipv6初始流量处理。
增加日志排查收益未自动生成问题。
This commit is contained in:
gaoyutao
2025-12-10 18:32:07 +08:00
parent 13e51c11e1
commit 2eaf62ea82
12 changed files with 299 additions and 298 deletions
@@ -64,7 +64,9 @@ public class RmMtrPolicyConfig extends BaseEntity
/** 查询条件 */
private String queryName;
@Excel(name = "修改时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
}
@@ -353,7 +353,7 @@ public class MessageHandler {
boolean needUpdate = false;
RmMtrClientRegistration updateData = new RmMtrClientRegistration();
updateData.setId(rmMtrClientRegistration.getId());
if(rmMtrClientRegistration.getLogicalNode() == null ||
if((rmMtrClientRegistration.getLogicalNode() == null && heartbeat.getLogicalNode()!=null) ||
!StringUtils.equals(rmMtrClientRegistration.getLogicalNode(), heartbeat.getLogicalNode())){
updateData.setLogicalNode(heartbeat.getLogicalNode());
needUpdate = true;
@@ -371,7 +371,7 @@ public class MessageHandler {
}
needUpdate = true;
}
if(rmMtrClientRegistration.getCpucores() == null ||
if((rmMtrClientRegistration.getCpucores() == null && heartbeat.getCpucores() != null) ||
rmMtrClientRegistration.getCpucores() != heartbeat.getCpucores()){
updateData.setCpucores(heartbeat.getCpucores());
needUpdate = true;
@@ -37,8 +37,8 @@ public class CalculateController extends BaseController {
queryParam.setDayOrMonth(dayOrMonth);
InitialSwitchInfoDetails initialSwitchInfoDetails = new InitialSwitchInfoDetails();
initialSwitchInfoDetails.setDayOrMonth(dayOrMonth);
// epsInitialTrafficDataService.calculateBusiness95BandwidthDaily(queryParam, dailyStartTime, dailyEndTime, "1000");
// epsInitialTrafficDataService.calculateBusiness95BandwidthDaily(queryParam, dailyStartTime, dailyEndTime, "1024");
epsInitialTrafficDataService.calculateBusiness95BandwidthDaily(queryParam, dailyStartTime, dailyEndTime, "1000");
epsInitialTrafficDataService.calculateBusiness95BandwidthDaily(queryParam, dailyStartTime, dailyEndTime, "1024");
// initialSwitchInfoDetailsService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails, dailyStartTime, dailyEndTime, "1000");
// initialSwitchInfoDetailsService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails, dailyStartTime, dailyEndTime, "1024");
}
@@ -282,7 +282,12 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
// 遍历处理每个设备
snList.forEach(interfaceName -> {
queryParam.setClientId(interfaceName.getClientId());
calculateChangedDeviceBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode);
try {
calculateChangedDeviceBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode);
log.info("计算{}的95带宽值完成", interfaceName.getClientId());
}catch (Exception e){
log.error("计算{}的95带宽值失败,详情:{}", interfaceName.getClientId(), e.getMessage());
}
});
}
/**
@@ -13,8 +13,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 服务器收益方式配置Service业务层处理
@@ -238,97 +241,67 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
/**
* 批量处理接口名称
*/
@Transactional(rollbackFor = Exception.class, isolation = Isolation.REPEATABLE_READ)
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
public void processInterfaceNames(List<EpsInitialTrafficData> trafficDataList) {
// 分类处理:新增列表 vs 更新列表
List<AllInterfaceName> namesToInsert = new ArrayList<>();
List<AllInterfaceName> namesToUpdate = new ArrayList<>();
if (CollectionUtils.isEmpty(trafficDataList)) {
return;
}
// 用于去重的临时集合,防止同一批数据中的重复
Set<String> processedKeys = new HashSet<>();
trafficDataList.forEach(data -> {
String name = data.getName();
String ip = data.getMac();
String clientId = data.getClientId();
if (StringUtils.isBlank(name) || StringUtils.isBlank(ip) || StringUtils.isBlank(clientId)) {
return;
}
// 生成唯一键,防止同一批数据中的重复处理
String uniqueKey = name + "|" + clientId + "|" + ip;
if (processedKeys.contains(uniqueKey)) {
return;
}
processedKeys.add(uniqueKey);
// 构造新记录
AllInterfaceName newRecord = new AllInterfaceName();
newRecord.setInterfaceName(name);
newRecord.setClientId(data.getClientId());
newRecord.setResourceType("1");
newRecord.setDeviceSn(data.getServiceSn());
newRecord.setNodeName(data.getNodeName());
newRecord.setBusinessCode(data.getBusinessId());
newRecord.setBusinessName(data.getBusinessName());
newRecord.setServerIp(data.getMac());
List<AllInterfaceName> existingNames = allInterfaceNameMapper.selectByNames(newRecord);
if (!existingNames.isEmpty()) {
for (AllInterfaceName existingName : existingNames) {
if (isRecordChanged(existingName, newRecord)) {
newRecord.setId(existingName.getId());
newRecord.setUpdateTime(DateUtils.getNowDate());
// 检查是否已经存在于更新列表中
boolean alreadyInUpdateList = namesToUpdate.stream()
.anyMatch(item -> item.getId() != null && item.getId().equals(existingName.getId()));
if (!alreadyInUpdateList) {
namesToUpdate.add(newRecord);
}
}
}
} else {
newRecord.setCreateTime(DateUtils.getNowDate());
newRecord.setUpdateTime(DateUtils.getNowDate());
// 检查namesToInsert中是否已有相同记录
boolean alreadyInInsertList = namesToInsert.stream()
.anyMatch(item -> item.getInterfaceName().equals(name)
&& item.getClientId().equals(clientId)
&& item.getServerIp().equals(ip));
if (!alreadyInInsertList) {
namesToInsert.add(newRecord);
}
}
});
// 批量操作数据库
if (!namesToInsert.isEmpty()) {
try {
allInterfaceNameMapper.batchInsert(namesToInsert);
log.info("新增接口名称数量:{}", namesToInsert.size());
} catch (Exception e) {
log.error("新增接口名称失败:{}", e.getMessage());
// 直接转换并过滤
List<AllInterfaceName> records = new ArrayList<>();
for (EpsInitialTrafficData data : trafficDataList) {
if (isValidData(data)) {
records.add(convertToInterfaceName(data));
}
}
if (!namesToUpdate.isEmpty()) {
namesToUpdate.sort(Comparator.comparing(AllInterfaceName::getId));
allInterfaceNameMapper.batchUpdate(namesToUpdate);
log.info("更新接口名称数量:{}", namesToUpdate.size());
if (!records.isEmpty()) {
try {
allInterfaceNameMapper.batchInsert(records);
log.info("批量处理接口名称完成,记录数: {}", records.size());
}catch (Exception e){
// 处理死锁异常
if (isDeadlockException(e)) {
// 找到第一个非null的clientId
String deadlockClientId = records.stream()
.map(AllInterfaceName::getClientId)
.filter(StringUtils::isNotBlank)
.findFirst()
.orElse("unknown");
log.error("检测到死锁,涉及的clientId: {}", deadlockClientId);
} else {
// 非死锁异常,重新抛出
log.error("批量处理接口名称失败:{}", e.getMessage());
}
}
}
}
private boolean isDeadlockException(Exception e) {
String message = e.getMessage();
return message != null && (
message.contains("deadlock") ||
message.contains("Deadlock") ||
message.contains("1213") // MySQL死锁错误码
);
}
private boolean isValidData(EpsInitialTrafficData data) {
return StringUtils.isNotBlank(data.getName())
&& StringUtils.isNotBlank(data.getMac())
&& StringUtils.isNotBlank(data.getClientId());
}
// 辅助方法:检查记录是否有变化
private boolean isRecordChanged(AllInterfaceName oldRecord, AllInterfaceName newRecord) {
return !Objects.equals(oldRecord.getDeviceSn(), newRecord.getDeviceSn()) ||
!Objects.equals(oldRecord.getNodeName(), newRecord.getNodeName()) ||
!Objects.equals(oldRecord.getBusinessCode(), newRecord.getBusinessCode()) ||
!Objects.equals(oldRecord.getBusinessName(), newRecord.getBusinessName()) ||
!Objects.equals(oldRecord.getServerIp(), newRecord.getServerIp());
private AllInterfaceName convertToInterfaceName(EpsInitialTrafficData data) {
AllInterfaceName record = new AllInterfaceName();
record.setInterfaceName(data.getName());
record.setClientId(data.getClientId());
record.setResourceType("1");
record.setDeviceSn(data.getServiceSn());
record.setNodeName(data.getNodeName());
record.setBusinessCode(data.getBusinessId());
record.setBusinessName(data.getBusinessName());
record.setServerIp(data.getMac());
return record;
}
/**
* 批量删除服务器收益方式配置
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -349,99 +350,83 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
/**
* 批量处理接口名称
*/
@Transactional(rollbackFor = Exception.class, isolation = Isolation.REPEATABLE_READ)
private void processSwitchInterfaceNames(List<InitialSwitchInfoDetails> initialSwitchInfoDetails) {
// 分类处理:新增列表 vs 更新列表
List<AllInterfaceName> namesToInsert = new ArrayList<>();
List<AllInterfaceName> namesToUpdate = new ArrayList<>();
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
public void processSwitchInterfaceNames(List<InitialSwitchInfoDetails> initialSwitchInfoDetails) {
if (CollectionUtils.isEmpty(initialSwitchInfoDetails)) {
return;
}
initialSwitchInfoDetails.forEach(data -> {
String name = data.getName();
String ip = data.getSwitchIp();
String clientId = data.getClientId();
if (StringUtils.isBlank(name) || StringUtils.isBlank(ip) || StringUtils.isBlank(clientId)) {
return;
}
AllInterfaceName record = new AllInterfaceName();
record.setInterfaceName(name);
record.setClientId(data.getClientId());
record.setResourceType("2");
record.setDeviceSn(data.getServerSn());
record.setNodeName(data.getServerName());
record.setServerPort(data.getServerPort());
record.setInterfaceDeviceType(data.getInterfaceDeviceType());
record.setSwitchName(data.getSwitchName());
record.setSwitchSn(data.getSwitchSn());
record.setSwitchIp(data.getSwitchIp());
List<AllInterfaceName> existingNames = allInterfaceNameMapper.selectByNames(record);
// 根据服务器sn查询业务
if(data.getServerSn() != null){
EpsServerRevenueConfig epsServerRevenueConfig = new EpsServerRevenueConfig();
epsServerRevenueConfig.setHardwareSn(data.getServerSn());
List<EpsServerRevenueConfig> businessList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(epsServerRevenueConfig);
if(!businessList.isEmpty()){
EpsServerRevenueConfig revenueConfig = businessList.get(0);
record.setBusinessName(revenueConfig.getBusinessName());
record.setBusinessCode(revenueConfig.getBusinessCode());
}
}else {
record.setBusinessCode(null);
record.setBusinessName(null);
}
// 判断是否需要更新
if (!existingNames.isEmpty()) {
for (AllInterfaceName existingName : existingNames) {
if(isRecordChanged(existingName,record)){
record.setId(existingName.getId()); // 保留原ID
// 检查是否已经存在于更新列表中
boolean alreadyInUpdateList = namesToUpdate.stream()
.anyMatch(item -> item.getId() != null && item.getId().equals(existingName.getId()));
if (!alreadyInUpdateList) {
namesToUpdate.add(record);
}
}
}
} else {
// 检查namesToInsert中是否已有相同记录
boolean alreadyInInsertList = namesToInsert.stream()
.anyMatch(item -> item.getInterfaceName().equals(name)
&& item.getClientId().equals(clientId)
&& item.getSwitchIp().equals(ip));
if (!alreadyInInsertList) {
namesToInsert.add(record);
}
}
});
// 批量操作数据库
if (!namesToInsert.isEmpty()) {
try {
allInterfaceNameMapper.batchInsert(namesToInsert);
log.info("交换机新增接口名称数量:{}", namesToInsert.size());
} catch (Exception e) {
log.error("交换机接口名称批量插入失败:{}", e.getMessage());
// 直接转换并过滤
List<AllInterfaceName> records = new ArrayList<>();
for (InitialSwitchInfoDetails data : initialSwitchInfoDetails) {
if (isValidData(data)) {
AllInterfaceName record = convertToInterfaceName(data);
// 查询业务信息
fillBusinessInfo(record, data.getServerSn());
records.add(record);
}
}
if (!namesToUpdate.isEmpty()) {
namesToUpdate.sort(Comparator.comparing(AllInterfaceName::getId));
allInterfaceNameMapper.batchUpdate(namesToUpdate);
log.info("交换机更新接口名称数量:{}", namesToUpdate.size());
if (!records.isEmpty()) {
try {
allInterfaceNameMapper.batchInsert(records);
log.info("批量处理交换机接口名称完成,记录数: {}", records.size());
}catch (Exception e){
// 处理死锁异常
if (isDeadlockException(e)) {
// 找到第一个非null的clientId
String deadlockClientId = records.stream()
.map(AllInterfaceName::getClientId)
.filter(StringUtils::isNotBlank)
.findFirst()
.orElse("unknown");
log.error("检测到死锁,涉及的clientId: {}", deadlockClientId);
} else {
// 非死锁异常,重新抛出
log.error("批量处理交换机接口名称失败:{}", e.getMessage());
}
}
}
}
private boolean isDeadlockException(Exception e) {
String message = e.getMessage();
return message != null && (
message.contains("deadlock") ||
message.contains("Deadlock") ||
message.contains("1213") // MySQL死锁错误码
);
}
// 辅助方法:检查记录是否有变化
private boolean isRecordChanged(AllInterfaceName oldRecord, AllInterfaceName newRecord) {
return !Objects.equals(oldRecord.getDeviceSn(), newRecord.getDeviceSn()) ||
!Objects.equals(oldRecord.getNodeName(), newRecord.getNodeName()) ||
!Objects.equals(oldRecord.getServerPort(), newRecord.getServerPort()) ||
!Objects.equals(oldRecord.getInterfaceDeviceType(), newRecord.getInterfaceDeviceType()) ||
!Objects.equals(oldRecord.getSwitchName(), newRecord.getSwitchName()) ||
!Objects.equals(oldRecord.getBusinessCode(), newRecord.getBusinessCode()) ||
!Objects.equals(oldRecord.getBusinessName(), newRecord.getBusinessName()) ||
!Objects.equals(oldRecord.getSwitchSn(), newRecord.getSwitchSn()) ||
!Objects.equals(oldRecord.getSwitchIp(), newRecord.getSwitchIp());
private boolean isValidData(InitialSwitchInfoDetails data) {
return StringUtils.isNotBlank(data.getName())
&& StringUtils.isNotBlank(data.getSwitchIp())
&& StringUtils.isNotBlank(data.getClientId());
}
private AllInterfaceName convertToInterfaceName(InitialSwitchInfoDetails data) {
AllInterfaceName record = new AllInterfaceName();
record.setInterfaceName(data.getName());
record.setClientId(data.getClientId());
record.setResourceType("2");
record.setDeviceSn(data.getServerSn());
record.setNodeName(data.getServerName());
record.setServerPort(data.getServerPort());
record.setInterfaceDeviceType(data.getInterfaceDeviceType());
record.setSwitchName(data.getSwitchName());
record.setSwitchSn(data.getSwitchSn());
record.setSwitchIp(data.getSwitchIp());
return record;
}
private void fillBusinessInfo(AllInterfaceName record, String serverSn) {
if (StringUtils.isNotBlank(serverSn)) {
EpsServerRevenueConfig query = new EpsServerRevenueConfig();
query.setHardwareSn(serverSn);
List<EpsServerRevenueConfig> businessList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(query);
if (!CollectionUtils.isEmpty(businessList)) {
EpsServerRevenueConfig revenueConfig = businessList.get(0);
record.setBusinessCode(revenueConfig.getBusinessCode());
record.setBusinessName(revenueConfig.getBusinessName());
}
}
}
public void calculateSwitch95BandwidthDaily(InitialSwitchInfoDetails queryParam, String dailyStartTime,
@@ -453,7 +438,12 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
// 遍历处理每个交换机
switchSnList.forEach(interfaceName -> {
queryParam.setClientId(interfaceName.getClientId());
processSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode);
try {
processSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode);
log.info("计算{}交换机的95带宽值完成", interfaceName.getClientId());
}catch (Exception e){
log.error("计算{}交换机的95带宽值失败,详情:{}", interfaceName.getClientId(), e.getMessage());
}
});
}
@@ -101,7 +101,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
startPage(pageDomain);
List<RmResourceRegistration> list = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
batchSetNetWorkMsg(list);
// 只处理当前页的数据
processCurrentPageData(list);
@@ -111,6 +111,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
// 情况2: 有查询参数或需要排序,全量查询+内存处理
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
batchSetNetWorkMsg(allData);
// 1. 过滤
List<RmResourceRegistration> filteredList = allData;
@@ -152,7 +153,6 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
for (RmResourceRegistration item : pageList) {
if (item.getClientId() != null) {
setNetWorkMsg(item);
setBandwidthYestoday(item);
}
}
@@ -311,7 +311,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
if (result == null || result.getData() == null || result.getData().isEmpty()) {
log.warn("批量查询网络信息返回为空,clientIds: {}", clientIdsStr);
// 回退到单条查询
fallbackSetNetworkInfo(pageList);
// fallbackSetNetworkInfo(pageList);
return;
}
@@ -341,7 +341,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
} catch (Exception e) {
log.error("批量查询网络信息异常", e);
// 回退到单条查询
fallbackSetNetworkInfo(pageList);
// fallbackSetNetworkInfo(pageList);
}
}
/**
@@ -910,19 +910,19 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
updateData.setOnlineStatus("1");
needUpdate = true;
}
if(exits.getLogicalNodeId() == null ||
if((exits.getLogicalNodeId() == null && rmResourceRegistration.getLogicalNodeId()!=null) ||
!StringUtils.equals(rmResourceRegistration.getLogicalNodeId(),exits.getLogicalNodeId())){
// 如果服务器已注册 增加节点标识
updateData.setLogicalNodeId(rmResourceRegistration.getLogicalNodeId());
needUpdate = true;
}
if(exits.getAgentVersion() == null ||
if((exits.getAgentVersion() == null && rmResourceRegistration.getAgentVersion()!=null) ||
!StringUtils.equals(rmResourceRegistration.getAgentVersion(),exits.getAgentVersion())){
// 如果服务器已注册 增加版本信息
updateData.setAgentVersion(rmResourceRegistration.getAgentVersion());
needUpdate = true;
}
if(exits.getHardwareSn() == null ||
if((exits.getHardwareSn() == null && rmResourceRegistration.getHardwareSn()!=null) ||
!StringUtils.equals(rmResourceRegistration.getHardwareSn(),exits.getHardwareSn())){
// 如果服务器已注册 增加SN信息
updateData.setHardwareSn(rmResourceRegistration.getHardwareSn());
@@ -1,94 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/tongran-system" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
<property name="log.path" value="logs/tongran-system" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 简化版debug.log配置,只包含日志框架的输出 -->
<!-- DEBUG级别日志输出 - 使用ThresholdFilter -->
<appender name="file_debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/debug.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/debug.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
<maxHistory>7</maxHistory> <!-- debug日志只保留7天 -->
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<!-- 记录DEBUG及以上级别,但不记录ERROR(ERROR有单独文件) -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>DENY</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<!-- ThresholdFilter会记录指定级别及以上级别的日志 -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.tongran" level="info" />
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn" />
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.tongran" level="info" />
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn" />
<!-- 如果你想启用特定类的debug日志 -->
<logger name="com.tongran.system" level="debug" additivity="false">
<appender-ref ref="file_debug" />
<appender-ref ref="console" />
</logger>
<!-- 排除不需要debug的子包(如果需要) -->
<logger name="com.tongran.system.mapper" level="info" />
<root level="info">
<appender-ref ref="console" />
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="console" />
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
<!-- 这里不包含file_debug,避免所有框架的debug日志都记录 -->
</root>
</configuration>
@@ -194,6 +194,65 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
NOW()
)
</foreach>
ON DUPLICATE KEY UPDATE
device_sn = CASE
WHEN device_sn != VALUES(device_sn) OR (device_sn IS NULL AND VALUES(device_sn) IS NOT NULL)
THEN VALUES(device_sn)
ELSE device_sn
END,
node_name = CASE
WHEN node_name != VALUES(node_name) OR (node_name IS NULL AND VALUES(node_name) IS NOT NULL)
THEN VALUES(node_name)
ELSE node_name
END,
business_code = CASE
WHEN business_code != VALUES(business_code) OR (business_code IS NULL AND VALUES(business_code) IS NOT NULL)
THEN VALUES(business_code)
ELSE business_code
END,
business_name = CASE
WHEN business_name != VALUES(business_name) OR (business_name IS NULL AND VALUES(business_name) IS NOT NULL)
THEN VALUES(business_name)
ELSE business_name
END,
switch_name = CASE
WHEN switch_name != VALUES(switch_name) OR (switch_name IS NULL AND VALUES(switch_name) IS NOT NULL)
THEN VALUES(switch_name)
ELSE switch_name
END,
interface_device_type = CASE
WHEN interface_device_type != VALUES(interface_device_type) OR (interface_device_type IS NULL AND VALUES(interface_device_type) IS NOT NULL)
THEN VALUES(interface_device_type)
ELSE interface_device_type
END,
server_port = CASE
WHEN server_port != VALUES(server_port) OR (server_port IS NULL AND VALUES(server_port) IS NOT NULL)
THEN VALUES(server_port)
ELSE server_port
END,
switch_sn = CASE
WHEN switch_sn != VALUES(switch_sn) OR (switch_sn IS NULL AND VALUES(switch_sn) IS NOT NULL)
THEN VALUES(switch_sn)
ELSE switch_sn
END,
switch_ip = CASE
WHEN switch_ip != VALUES(switch_ip) OR (switch_ip IS NULL AND VALUES(switch_ip) IS NOT NULL)
THEN VALUES(switch_ip)
ELSE switch_ip
END,
update_time = CASE
WHEN device_sn != VALUES(device_sn) OR (device_sn IS NULL AND VALUES(device_sn) IS NOT NULL)
OR node_name != VALUES(node_name) OR (node_name IS NULL AND VALUES(node_name) IS NOT NULL)
OR business_code != VALUES(business_code) OR (business_code IS NULL AND VALUES(business_code) IS NOT NULL)
OR business_name != VALUES(business_name) OR (business_name IS NULL AND VALUES(business_name) IS NOT NULL)
OR switch_name != VALUES(switch_name) OR (switch_name IS NULL AND VALUES(switch_name) IS NOT NULL)
OR interface_device_type != VALUES(interface_device_type) OR (interface_device_type IS NULL AND VALUES(interface_device_type) IS NOT NULL)
OR server_port != VALUES(server_port) OR (server_port IS NULL AND VALUES(server_port) IS NOT NULL)
OR switch_sn != VALUES(switch_sn) OR (switch_sn IS NULL AND VALUES(switch_sn) IS NOT NULL)
OR switch_ip != VALUES(switch_ip) OR (switch_ip IS NULL AND VALUES(switch_ip) IS NOT NULL)
THEN NOW()
ELSE update_time
END
</insert>
<select id="getAllDeviceSn" parameterType="AllInterfaceName" resultType="AllInterfaceName">
@@ -234,7 +234,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
a.reported_bandwidth as reportedBandwidth,
b.machine_code as machineCode,
(select bandwidth_result from eps_node_bandwidth
where client_id=a.client_id and calculation_mode='1000' and bandwidth_type=1
where client_id=a.client_id and calculation_mode='1000' and bandwidth_type='1'
AND create_time = DATE(DATE_SUB(NOW(), INTERVAL 1 DAY)) limit 1) as bandwidthResult
from rm_resource_registration a
left join rm_registration_machine b on a.client_id = b.client_id
@@ -282,6 +282,13 @@ public class MessageHandler {
iface.setTotalIpv4InSpeed(dataProcessUtil.bytesToBits(iface.getIpv4InSpeed()));
iface.setTotalIpv6OutSpeed(dataProcessUtil.bytesToBits(iface.getIpv6OutSpeed()));
iface.setTotalIpv6InSpeed(dataProcessUtil.bytesToBits(iface.getIpv6InSpeed()));
// 首次采集,速率设为null
iface.setInSpeed(null);
iface.setOutSpeed(null);
iface.setIpv4InSpeed(null);
iface.setIpv4OutSpeed(null);
iface.setIpv6InSpeed(null);
iface.setIpv6OutSpeed(null);
InitialBandwidthTrafficTemp tempInfo = tempMap.get(iface.getMac());
if (tempInfo != null) {
@@ -292,8 +299,6 @@ public class MessageHandler {
BigDecimal inDiff = nowInSpeed.subtract(tempInSpeed);
if (inDiff.compareTo(BigDecimal.ZERO) >= 0) {
iface.setInSpeed(inDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
} else {
iface.setInSpeed(null);
}
}
// 计算总流出速率
@@ -303,8 +308,6 @@ public class MessageHandler {
BigDecimal outDiff = nowOutSpeed.subtract(tempOutSpeed);
if (outDiff.compareTo(BigDecimal.ZERO) >= 0) {
iface.setOutSpeed(outDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
} else {
iface.setOutSpeed(null);
}
}
// 计算IPv4流入速率
@@ -314,8 +317,6 @@ public class MessageHandler {
BigDecimal ipv4InDiff = nowIpv4In.subtract(tempIpv4In);
if (ipv4InDiff.compareTo(BigDecimal.ZERO) >= 0) {
iface.setIpv4InSpeed(ipv4InDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
} else {
iface.setIpv4InSpeed(null);
}
}
// 计算IPv4流出速率
@@ -325,8 +326,6 @@ public class MessageHandler {
BigDecimal ipv4OutDiff = nowIpv4Out.subtract(tempIpv4Out);
if (ipv4OutDiff.compareTo(BigDecimal.ZERO) >= 0) {
iface.setIpv4OutSpeed(ipv4OutDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
} else {
iface.setIpv4OutSpeed(null);
}
}
// 计算IPv6流入速率
@@ -336,8 +335,6 @@ public class MessageHandler {
BigDecimal ipv6InDiff = nowIpv6In.subtract(tempIpv6In);
if (ipv6InDiff.compareTo(BigDecimal.ZERO) >= 0) {
iface.setIpv6InSpeed(ipv6InDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
} else {
iface.setIpv6InSpeed(null);
}
}
// 计算IPv6流出速率
@@ -347,8 +344,6 @@ public class MessageHandler {
BigDecimal ipv6OutDiff = nowIpv6Out.subtract(tempIpv6Out);
if (ipv6OutDiff.compareTo(BigDecimal.ZERO) >= 0) {
iface.setIpv6OutSpeed(ipv6OutDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
} else {
iface.setIpv6OutSpeed(null);
}
}
}
+23 -36
View File
@@ -12,25 +12,35 @@
</encoder>
</appender>
<!-- DEBUG级别日志输出 - 使用ThresholdFilter -->
<appender name="file_debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/debug.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory> <!-- debug日志只保留7天 -->
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<!-- ThresholdFilter会记录指定级别及以上级别的日志 -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- RocketMQ业务日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
@@ -38,53 +48,30 @@
<!-- RocketMQ错误日志输出 -->
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 简化版debug.log配置,只包含日志框架的输出 -->
<appender name="file_debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/debug.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<!-- 记录DEBUG及以上级别,但不记录ERROR(ERROR有单独文件) -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>DENY</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- RocketMQ模块日志级别控制 -->
<logger name="com.tongran.rocketmq" level="info" additivity="false">
<appender-ref ref="console" /> <!-- 显式添加控制台 -->
<!-- 如果你想启用特定类的debug日志 -->
<logger name="com.tongran.rocketmq" level="debug" additivity="false">
<appender-ref ref="file_debug" />
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
<appender-ref ref="console" />
</logger>
<!-- 排除不需要debug的子包(如果需要) -->
<logger name="com.tongran.rocketmq.snmp" level="info" />
<logger name="com.tongran.rocketmq.mapper" level="info" />
<!-- Apache RocketMQ客户端日志控制 -->
<logger name="org.apache.rocketmq" level="warn" />