增加流量重试入库功能
This commit is contained in:
@@ -121,6 +121,12 @@
|
|||||||
<artifactId>tea-util</artifactId>
|
<artifactId>tea-util</artifactId>
|
||||||
<version>0.2.21</version>
|
<version>0.2.21</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 分布式redisson锁 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.redisson</groupId>
|
||||||
|
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||||
|
<version>3.27.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class ConsumerConfig {
|
|||||||
|
|
||||||
consumer.setVipChannelEnabled(false);
|
consumer.setVipChannelEnabled(false);
|
||||||
consumer.setConsumeMessageBatchMaxSize(consumerMode.getConsumeMessageBatchMaxSize());
|
consumer.setConsumeMessageBatchMaxSize(consumerMode.getConsumeMessageBatchMaxSize());
|
||||||
|
consumer.setSuspendCurrentQueueTimeMillis(5);
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
* 订阅topic,可以对指定消息进行过滤,例如:"TopicTest","tagl||tag2||tag3",*或null表示topic所有消息
|
* 订阅topic,可以对指定消息进行过滤,例如:"TopicTest","tagl||tag2||tag3",*或null表示topic所有消息
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.tongran.rocketmq.consumer;
|
package com.tongran.rocketmq.consumer;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.tongran.common.core.enums.MsgEnum;
|
||||||
import com.tongran.rocketmq.domain.DeviceMessage;
|
import com.tongran.rocketmq.domain.DeviceMessage;
|
||||||
import com.tongran.rocketmq.enums.MessageCodeEnum;
|
import com.tongran.rocketmq.enums.MessageCodeEnum;
|
||||||
import com.tongran.rocketmq.handler.DeviceMessageHandler;
|
import com.tongran.rocketmq.handler.DeviceMessageHandler;
|
||||||
@@ -56,10 +57,20 @@ public class RocketMsgListener implements MessageListenerConcurrently {
|
|||||||
int reConsume = messageExt.getReconsumeTimes();
|
int reConsume = messageExt.getReconsumeTimes();
|
||||||
// 消息已经重试了3次,如果不需要再次消费,则返回成功
|
// 消息已经重试了3次,如果不需要再次消费,则返回成功
|
||||||
if (reConsume == 3) {
|
if (reConsume == 3) {
|
||||||
|
// 拿到信息
|
||||||
|
DeviceMessage message = JSON.parseObject(body, DeviceMessage.class);
|
||||||
|
if(!message.getDataType().equals(MsgEnum.网络上报重试.getValue())){
|
||||||
// TODO 补偿信息
|
// TODO 补偿信息
|
||||||
log.error("消息消费三次失败,消息内容:{}", body);
|
log.error("消息消费三次失败,消息内容:{}", body);
|
||||||
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;//根据业务返回是否正常
|
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;//根据业务返回是否正常
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// 流量数据重试
|
||||||
|
if (reConsume == 6) {
|
||||||
|
// 补偿信息
|
||||||
|
log.error("流量数据重试消息消费6次失败,消息内容:{}", body);
|
||||||
|
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;//根据业务返回是否正常
|
||||||
|
}
|
||||||
if(MessageCodeEnum.TONGRAN_AGENT_UP.getCode().equals(topic)){
|
if(MessageCodeEnum.TONGRAN_AGENT_UP.getCode().equals(topic)){
|
||||||
// 拿到信息
|
// 拿到信息
|
||||||
DeviceMessage message = JSON.parseObject(body, DeviceMessage.class);
|
DeviceMessage message = JSON.parseObject(body, DeviceMessage.class);
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package com.tongran.rocketmq.domain;
|
package com.tongran.rocketmq.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class DeviceMessage {
|
public class DeviceMessage {
|
||||||
private String clientId;
|
private String clientId;
|
||||||
private String dataType;
|
private String dataType;
|
||||||
private String data;
|
private String data;
|
||||||
|
/** 最后一次标志 */
|
||||||
|
private boolean lastTrafficFlag;
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,8 @@ public class PolicyTypeVo {
|
|||||||
private String diskIopsTest;
|
private String diskIopsTest;
|
||||||
/** 卸载磁盘分区 */
|
/** 卸载磁盘分区 */
|
||||||
private String umountDisk;
|
private String umountDisk;
|
||||||
|
/** 需要删除的时间戳 */
|
||||||
|
private String trafficUsedTimestamp;
|
||||||
/** 时间戳 */
|
/** 时间戳 */
|
||||||
private Long timestamp = Instant.now().getEpochSecond();
|
private Long timestamp = Instant.now().getEpochSecond();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import com.tongran.rocketmq.domain.*;
|
|||||||
import com.tongran.rocketmq.domain.vo.*;
|
import com.tongran.rocketmq.domain.vo.*;
|
||||||
import com.tongran.rocketmq.enums.AlarmTypeEnum;
|
import com.tongran.rocketmq.enums.AlarmTypeEnum;
|
||||||
import com.tongran.rocketmq.enums.PushMethodEnum;
|
import com.tongran.rocketmq.enums.PushMethodEnum;
|
||||||
|
import com.tongran.rocketmq.model.ProducerMode;
|
||||||
|
import com.tongran.rocketmq.producer.MessageProducer;
|
||||||
import com.tongran.rocketmq.service.*;
|
import com.tongran.rocketmq.service.*;
|
||||||
import com.tongran.rocketmq.utils.DataProcessUtil;
|
import com.tongran.rocketmq.utils.DataProcessUtil;
|
||||||
import com.tongran.rocketmq.utils.JsonDataParser;
|
import com.tongran.rocketmq.utils.JsonDataParser;
|
||||||
@@ -18,6 +20,8 @@ import com.tongran.rocketmq.utils.WeChatWorkBot;
|
|||||||
import com.tongran.system.api.RemoteRevenueConfigService;
|
import com.tongran.system.api.RemoteRevenueConfigService;
|
||||||
import com.tongran.system.api.domain.*;
|
import com.tongran.system.api.domain.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
@@ -32,6 +36,7 @@ import javax.annotation.PostConstruct;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -108,6 +113,10 @@ public class MessageHandler {
|
|||||||
private IRmPppoeConfigSubService rmPppoeConfigSubService;
|
private IRmPppoeConfigSubService rmPppoeConfigSubService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAllDiskNameService allDiskNameService;
|
private IAllDiskNameService allDiskNameService;
|
||||||
|
@Autowired
|
||||||
|
private ProducerMode producerMode;
|
||||||
|
@Autowired
|
||||||
|
private RedissonClient redissonClient;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,6 +135,7 @@ public class MessageHandler {
|
|||||||
registerHandler(MsgEnum.容器上报.getValue(), this::handleDockerMessage);
|
registerHandler(MsgEnum.容器上报.getValue(), this::handleDockerMessage);
|
||||||
registerHandler(MsgEnum.内存上报.getValue(), this::handleMemoryMessage);
|
registerHandler(MsgEnum.内存上报.getValue(), this::handleMemoryMessage);
|
||||||
registerHandler(MsgEnum.网络上报.getValue(), this::handleNetMessage);
|
registerHandler(MsgEnum.网络上报.getValue(), this::handleNetMessage);
|
||||||
|
registerHandler(MsgEnum.网络上报重试.getValue(), this::handleNetRecoverMessage);
|
||||||
registerHandler(MsgEnum.挂载上报.getValue(), this::handleMountPointMessage);
|
registerHandler(MsgEnum.挂载上报.getValue(), this::handleMountPointMessage);
|
||||||
registerHandler(MsgEnum.系统其他上报.getValue(), this::handleOtherSystemMessage);
|
registerHandler(MsgEnum.系统其他上报.getValue(), this::handleOtherSystemMessage);
|
||||||
registerHandler(MsgEnum.心跳上报.getValue(), this::handleHeartbeatMessage);
|
registerHandler(MsgEnum.心跳上报.getValue(), this::handleHeartbeatMessage);
|
||||||
@@ -505,6 +515,262 @@ public class MessageHandler {
|
|||||||
throw new RuntimeException("NET流量data数据为空");
|
throw new RuntimeException("NET流量data数据为空");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储时间戳到Redis
|
||||||
|
* @param clientId 客户端ID
|
||||||
|
* @param timestamp 时间戳
|
||||||
|
*/
|
||||||
|
private void storeTimestampToRedis(String clientId, long timestamp) {
|
||||||
|
try {
|
||||||
|
String redisKey = "net_traffic_timestamps:" + clientId;
|
||||||
|
String existingTimestamps = redisTemplate.opsForValue().get(redisKey);
|
||||||
|
|
||||||
|
if (existingTimestamps != null && !existingTimestamps.isEmpty()) {
|
||||||
|
// 已存在时间戳,追加新的时间戳
|
||||||
|
String newTimestamps = existingTimestamps + "," + timestamp;
|
||||||
|
redisTemplate.opsForValue().set(redisKey, newTimestamps);
|
||||||
|
} else {
|
||||||
|
// 首次存储
|
||||||
|
redisTemplate.opsForValue().set(redisKey, String.valueOf(timestamp));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Redis操作异常处理,记录日志但不中断主流程
|
||||||
|
log.error("存储时间戳到Redis失败,clientId: {}, timestamp: {}", clientId, timestamp, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void handleNetRecoverMessage(DeviceMessage message) {
|
||||||
|
String clientId = message.getClientId();
|
||||||
|
String lockKey = "traffic:recover:" + clientId;
|
||||||
|
RLock lock = redissonClient.getLock(lockKey);
|
||||||
|
boolean locked = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 尝试获取锁
|
||||||
|
locked = lock.tryLock(0, 20, TimeUnit.SECONDS);
|
||||||
|
if (locked) {
|
||||||
|
log.info("设备{}获取锁成功,开始处理消息", clientId);
|
||||||
|
processNetRecoverMessageInternal(message);
|
||||||
|
log.info("设备{}消息处理完成", clientId);
|
||||||
|
} else {
|
||||||
|
log.warn("设备{}获取锁失败,消息处理繁忙", clientId);
|
||||||
|
throw new RuntimeException("设备处理繁忙,请重试");
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
log.error("处理消息时线程被中断", e);
|
||||||
|
} finally {
|
||||||
|
// 只有成功获取锁的线程才需要释放
|
||||||
|
if (locked && lock.isHeldByCurrentThread()) {
|
||||||
|
try {
|
||||||
|
lock.unlock();
|
||||||
|
log.debug("设备{}锁已释放", clientId);
|
||||||
|
} catch (IllegalMonitorStateException e) {
|
||||||
|
log.warn("设备{}锁释放异常,可能已自动超时", clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 网络流量数据入库
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
private void processNetRecoverMessageInternal(DeviceMessage message) {
|
||||||
|
List<InitialBandwidthTraffic> interfaces = JsonDataParser.parseJsonData(message.getData(), InitialBandwidthTraffic.class);
|
||||||
|
if(!interfaces.isEmpty()){
|
||||||
|
String clientId = message.getClientId();
|
||||||
|
// 时间戳转换
|
||||||
|
long timestamp = interfaces.get(0).getTimestamp();
|
||||||
|
// 时间戳存储到redis
|
||||||
|
storeTimestampToRedis(clientId, timestamp);
|
||||||
|
if(message.isLastTrafficFlag()){
|
||||||
|
// 把redis中存储的时间戳提取出来,删除redis中的时间戳
|
||||||
|
processExitsTraffic(clientId);
|
||||||
|
}
|
||||||
|
long millis = timestamp * 1000;
|
||||||
|
Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒
|
||||||
|
String timeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",createTime);
|
||||||
|
// 判断数据库中是否已存在数据
|
||||||
|
InitialBandwidthTraffic countQuery = new InitialBandwidthTraffic();
|
||||||
|
countQuery.setClientId(clientId);
|
||||||
|
countQuery.setCreateTime(createTime);
|
||||||
|
countQuery.setStartTime(timeStr);
|
||||||
|
int exitsCount = initialBandwidthTrafficService.countByClientIdAndTime(countQuery);
|
||||||
|
if(exitsCount > 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 创建比timestamp少5分钟的时间
|
||||||
|
long fiveMinutesEarlier = millis - (5 * 60 * 1000); // 减去5分钟的毫秒数
|
||||||
|
Date fiveMinutesEarlierDate = new Date(fiveMinutesEarlier / 1000 * 1000); // 同样去除毫秒
|
||||||
|
// 查询临时表信息,计算实际流量值
|
||||||
|
InitialBandwidthTrafficTemp temp = new InitialBandwidthTrafficTemp();
|
||||||
|
temp.setCreateTime(fiveMinutesEarlierDate);
|
||||||
|
temp.setClientId(clientId);
|
||||||
|
List<InitialBandwidthTrafficTemp> tempList = initialBandwidthTrafficTempService.selectInitialBandwidthTrafficRecoverTempList(temp);
|
||||||
|
if(!tempList.isEmpty()){
|
||||||
|
// 1. 构建快速查找的Map,使用MAC地址+网卡名称作为唯一键
|
||||||
|
Map<String, InitialBandwidthTrafficTemp> tempMap = tempList.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
tempItem -> generateKey(tempItem.getMac(), tempItem.getName()),
|
||||||
|
Function.identity(),
|
||||||
|
(existing, replacement) -> existing
|
||||||
|
));
|
||||||
|
|
||||||
|
// 2. 预计算除数(避免重复创建对象)
|
||||||
|
BigDecimal divisor = new BigDecimal(300);
|
||||||
|
|
||||||
|
interfaces.forEach(iface -> {
|
||||||
|
iface.setClientId(clientId);
|
||||||
|
iface.setCreateTime(createTime);
|
||||||
|
|
||||||
|
// 设置总流量(转换为比特)
|
||||||
|
iface.setTotalOutSpeed(dataProcessUtil.bytesToBits(iface.getOutSpeed()));
|
||||||
|
iface.setTotalInSpeed(dataProcessUtil.bytesToBits(iface.getInSpeed()));
|
||||||
|
iface.setTotalIpv4OutSpeed(dataProcessUtil.bytesToBits(iface.getIpv4OutSpeed()));
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 使用MAC地址+网卡名称作为查找键
|
||||||
|
String key = generateKey(iface.getMac(), iface.getName());
|
||||||
|
InitialBandwidthTrafficTemp tempInfo = tempMap.get(key);
|
||||||
|
if (tempInfo != null) {
|
||||||
|
// 计算总流入速率
|
||||||
|
if (iface.getTotalInSpeed() != null && tempInfo.getTotalInSpeed() != null) {
|
||||||
|
BigDecimal nowInSpeed = new BigDecimal(iface.getTotalInSpeed());
|
||||||
|
BigDecimal tempInSpeed = new BigDecimal(tempInfo.getTotalInSpeed());
|
||||||
|
BigDecimal inDiff = nowInSpeed.subtract(tempInSpeed);
|
||||||
|
if (inDiff.compareTo(BigDecimal.ZERO) >= 0) {
|
||||||
|
iface.setInSpeed(inDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 计算总流出速率
|
||||||
|
if (iface.getTotalOutSpeed() != null && tempInfo.getTotalOutSpeed() != null) {
|
||||||
|
BigDecimal nowOutSpeed = new BigDecimal(iface.getTotalOutSpeed());
|
||||||
|
BigDecimal tempOutSpeed = new BigDecimal(tempInfo.getTotalOutSpeed());
|
||||||
|
BigDecimal outDiff = nowOutSpeed.subtract(tempOutSpeed);
|
||||||
|
if (outDiff.compareTo(BigDecimal.ZERO) >= 0) {
|
||||||
|
iface.setOutSpeed(outDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 计算IPv4流入速率
|
||||||
|
if (iface.getTotalIpv4InSpeed() != null && tempInfo.getTotalIpv4InSpeed() != null) {
|
||||||
|
BigDecimal nowIpv4In = new BigDecimal(iface.getTotalIpv4InSpeed());
|
||||||
|
BigDecimal tempIpv4In = new BigDecimal(tempInfo.getTotalIpv4InSpeed());
|
||||||
|
BigDecimal ipv4InDiff = nowIpv4In.subtract(tempIpv4In);
|
||||||
|
if (ipv4InDiff.compareTo(BigDecimal.ZERO) >= 0) {
|
||||||
|
iface.setIpv4InSpeed(ipv4InDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 计算IPv4流出速率
|
||||||
|
if (iface.getTotalIpv4OutSpeed() != null && tempInfo.getTotalIpv4OutSpeed() != null) {
|
||||||
|
BigDecimal nowIpv4Out = new BigDecimal(iface.getTotalIpv4OutSpeed());
|
||||||
|
BigDecimal tempIpv4Out = new BigDecimal(tempInfo.getTotalIpv4OutSpeed());
|
||||||
|
BigDecimal ipv4OutDiff = nowIpv4Out.subtract(tempIpv4Out);
|
||||||
|
if (ipv4OutDiff.compareTo(BigDecimal.ZERO) >= 0) {
|
||||||
|
iface.setIpv4OutSpeed(ipv4OutDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 计算IPv6流入速率
|
||||||
|
if (iface.getTotalIpv6InSpeed() != null && tempInfo.getTotalIpv6InSpeed() != null) {
|
||||||
|
BigDecimal nowIpv6In = new BigDecimal(iface.getTotalIpv6InSpeed());
|
||||||
|
BigDecimal tempIpv6In = new BigDecimal(tempInfo.getTotalIpv6InSpeed());
|
||||||
|
BigDecimal ipv6InDiff = nowIpv6In.subtract(tempIpv6In);
|
||||||
|
if (ipv6InDiff.compareTo(BigDecimal.ZERO) >= 0) {
|
||||||
|
iface.setIpv6InSpeed(ipv6InDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 计算IPv6流出速率
|
||||||
|
if (iface.getTotalIpv6OutSpeed() != null && tempInfo.getTotalIpv6OutSpeed() != null) {
|
||||||
|
BigDecimal nowIpv6Out = new BigDecimal(iface.getTotalIpv6OutSpeed());
|
||||||
|
BigDecimal tempIpv6Out = new BigDecimal(tempInfo.getTotalIpv6OutSpeed());
|
||||||
|
BigDecimal ipv6OutDiff = nowIpv6Out.subtract(tempIpv6Out);
|
||||||
|
if (ipv6OutDiff.compareTo(BigDecimal.ZERO) >= 0) {
|
||||||
|
iface.setIpv6OutSpeed(ipv6OutDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 清空临时表对应server信息
|
||||||
|
InitialBandwidthTrafficTemp delQuery = new InitialBandwidthTrafficTemp();
|
||||||
|
delQuery.setClientId(clientId);
|
||||||
|
delQuery.setCreateTime(fiveMinutesEarlierDate);
|
||||||
|
initialBandwidthTrafficTempService.deleteTempMsgByClientIdAndTime(delQuery);
|
||||||
|
}else{
|
||||||
|
interfaces.forEach(iface -> {
|
||||||
|
iface.setClientId(clientId);
|
||||||
|
iface.setCreateTime(createTime);
|
||||||
|
// 设置总流量(转换为比特)
|
||||||
|
iface.setTotalOutSpeed(dataProcessUtil.bytesToBits(iface.getOutSpeed()));
|
||||||
|
iface.setTotalInSpeed(dataProcessUtil.bytesToBits(iface.getInSpeed()));
|
||||||
|
iface.setTotalIpv4OutSpeed(dataProcessUtil.bytesToBits(iface.getIpv4OutSpeed()));
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
InitialBandwidthTraffic data = new InitialBandwidthTraffic();
|
||||||
|
// 批量入库集合
|
||||||
|
data.setList(interfaces);
|
||||||
|
// 临时表 用来计算流量速率
|
||||||
|
initialBandwidthTrafficTempService.batchInsertServerRecoverTemp(interfaces);
|
||||||
|
// 初始流量数据入库
|
||||||
|
initialBandwidthTrafficService.batchInsert(data);
|
||||||
|
EpsInitialTrafficDataRemote epsInitialTrafficDataRemote = new EpsInitialTrafficDataRemote();
|
||||||
|
epsInitialTrafficDataRemote.setStartTime(timeStr);
|
||||||
|
epsInitialTrafficDataRemote.setEndTime(timeStr);
|
||||||
|
// 复制到业务初始库
|
||||||
|
remoteRevenueConfigService.autoSaveServiceTrafficData(epsInitialTrafficDataRemote, SecurityConstants.INNER);
|
||||||
|
}else{
|
||||||
|
throw new RuntimeException("NET流量data数据为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processExitsTraffic(String clientId) {
|
||||||
|
try {
|
||||||
|
String redisKey = "net_traffic_timestamps:" + clientId;
|
||||||
|
String storedTimestamps = redisTemplate.opsForValue().get(redisKey);
|
||||||
|
|
||||||
|
if (storedTimestamps != null && !storedTimestamps.isEmpty()) {
|
||||||
|
// 删除Redis中的时间戳数据
|
||||||
|
redisTemplate.delete(redisKey);
|
||||||
|
// 构建磁盘下发信息
|
||||||
|
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||||
|
policyTypeVo.setTrafficUsedTimestamp(storedTimestamps);
|
||||||
|
MessageProducer messageProducer = new MessageProducer();
|
||||||
|
String configJson = JSONObject.toJSONString(policyTypeVo);
|
||||||
|
DeviceMessage message = new DeviceMessage();
|
||||||
|
message.setClientId(clientId);
|
||||||
|
message.setData(configJson);
|
||||||
|
message.setDataType(MsgEnum.获取最新策略应答.getValue());
|
||||||
|
|
||||||
|
messageProducer.sendAsyncProducerMessage(
|
||||||
|
producerMode.getAgentTopic(),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
JSONObject.toJSONString(message)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("提取并删除Redis时间戳失败,clientId: {}", clientId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String generateKey(String mac, String name) {
|
private String generateKey(String mac, String name) {
|
||||||
if (mac == null) {
|
if (mac == null) {
|
||||||
mac = "";
|
mac = "";
|
||||||
|
|||||||
+2
@@ -83,4 +83,6 @@ public interface InitialBandwidthTrafficMapper
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<InitialBandwidthTraffic> getNetTrafficList(InitialBandwidthTraffic condition);
|
List<InitialBandwidthTraffic> getNetTrafficList(InitialBandwidthTraffic condition);
|
||||||
|
|
||||||
|
int countByClientIdAndTime(InitialBandwidthTraffic countQuery);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -70,4 +70,10 @@ public interface InitialBandwidthTrafficTempMapper
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int batchInsertServerTemp(@Param("list") List<InitialBandwidthTraffic> interfaces);
|
int batchInsertServerTemp(@Param("list") List<InitialBandwidthTraffic> interfaces);
|
||||||
|
|
||||||
|
int batchInsertServerRecoverTemp(@Param("list") List<InitialBandwidthTraffic> interfaces);
|
||||||
|
|
||||||
|
int deleteTempMsgByClientIdAndTime(InitialBandwidthTrafficTemp initialBandwidthTrafficTemp);
|
||||||
|
|
||||||
|
List<InitialBandwidthTrafficTemp> selectInitialBandwidthTrafficRecoverTempList(InitialBandwidthTrafficTemp initialBandwidthTrafficTemp);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -121,4 +121,6 @@ public interface IInitialBandwidthTrafficService
|
|||||||
Map<String, Object> serverDetails(InitialBandwidthTraffic initialBandwidthTraffic);
|
Map<String, Object> serverDetails(InitialBandwidthTraffic initialBandwidthTraffic);
|
||||||
|
|
||||||
Map<String, Object> pingDroppedEcharts(InitialBandwidthTraffic initialBandwidthTraffic);
|
Map<String, Object> pingDroppedEcharts(InitialBandwidthTraffic initialBandwidthTraffic);
|
||||||
|
|
||||||
|
int countByClientIdAndTime(InitialBandwidthTraffic countQuery);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -29,6 +29,8 @@ public interface IInitialBandwidthTrafficTempService
|
|||||||
*/
|
*/
|
||||||
public List<InitialBandwidthTrafficTemp> selectInitialBandwidthTrafficTempList(InitialBandwidthTrafficTemp initialBandwidthTrafficTemp);
|
public List<InitialBandwidthTrafficTemp> selectInitialBandwidthTrafficTempList(InitialBandwidthTrafficTemp initialBandwidthTrafficTemp);
|
||||||
|
|
||||||
|
public List<InitialBandwidthTrafficTemp> selectInitialBandwidthTrafficRecoverTempList(InitialBandwidthTrafficTemp initialBandwidthTrafficTemp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增初始带宽流量临时表
|
* 新增初始带宽流量临时表
|
||||||
*
|
*
|
||||||
@@ -67,6 +69,7 @@ public interface IInitialBandwidthTrafficTempService
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int deleteTempMsgByClientId(String clientId);
|
int deleteTempMsgByClientId(String clientId);
|
||||||
|
int deleteTempMsgByClientIdAndTime(InitialBandwidthTrafficTemp initialBandwidthTrafficTemp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量新增临时表信息
|
* 批量新增临时表信息
|
||||||
@@ -74,4 +77,10 @@ public interface IInitialBandwidthTrafficTempService
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int batchInsertServerTemp(List<InitialBandwidthTraffic> interfaces);
|
int batchInsertServerTemp(List<InitialBandwidthTraffic> interfaces);
|
||||||
|
/**
|
||||||
|
* 批量新增重试临时表信息
|
||||||
|
* @param interfaces
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int batchInsertServerRecoverTemp(List<InitialBandwidthTraffic> interfaces);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -649,6 +649,13 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countByClientIdAndTime(InitialBandwidthTraffic countQuery) {
|
||||||
|
String tableName = TableSubUtil.getTableName(countQuery.getCreateTime(), "initial_bandwidth_traffic");
|
||||||
|
countQuery.setTableName(tableName);
|
||||||
|
return initialBandwidthTrafficMapper.countByClientIdAndTime(countQuery);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建支持子网卡的批量echarts图表数据
|
* 构建支持子网卡的批量echarts图表数据
|
||||||
* @param initialBandwidthTraffic
|
* @param initialBandwidthTraffic
|
||||||
|
|||||||
+20
-1
@@ -45,7 +45,17 @@ public class InitialBandwidthTrafficTempServiceImpl implements IInitialBandwidth
|
|||||||
{
|
{
|
||||||
return initialBandwidthTrafficTempMapper.selectInitialBandwidthTrafficTempList(initialBandwidthTrafficTemp);
|
return initialBandwidthTrafficTempMapper.selectInitialBandwidthTrafficTempList(initialBandwidthTrafficTemp);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 查询初始带宽流量临时表列表
|
||||||
|
*
|
||||||
|
* @param initialBandwidthTrafficTemp 初始带宽流量临时表
|
||||||
|
* @return 初始带宽流量临时表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<InitialBandwidthTrafficTemp> selectInitialBandwidthTrafficRecoverTempList(InitialBandwidthTrafficTemp initialBandwidthTrafficTemp)
|
||||||
|
{
|
||||||
|
return initialBandwidthTrafficTempMapper.selectInitialBandwidthTrafficRecoverTempList(initialBandwidthTrafficTemp);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 新增初始带宽流量临时表
|
* 新增初始带宽流量临时表
|
||||||
*
|
*
|
||||||
@@ -101,8 +111,17 @@ public class InitialBandwidthTrafficTempServiceImpl implements IInitialBandwidth
|
|||||||
return initialBandwidthTrafficTempMapper.deleteTempMsgByClientId(clientId);
|
return initialBandwidthTrafficTempMapper.deleteTempMsgByClientId(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteTempMsgByClientIdAndTime(InitialBandwidthTrafficTemp initialBandwidthTrafficTemp) {
|
||||||
|
return initialBandwidthTrafficTempMapper.deleteTempMsgByClientIdAndTime(initialBandwidthTrafficTemp);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int batchInsertServerTemp(List<InitialBandwidthTraffic> interfaces) {
|
public int batchInsertServerTemp(List<InitialBandwidthTraffic> interfaces) {
|
||||||
return initialBandwidthTrafficTempMapper.batchInsertServerTemp(interfaces);
|
return initialBandwidthTrafficTempMapper.batchInsertServerTemp(interfaces);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public int batchInsertServerRecoverTemp(List<InitialBandwidthTraffic> interfaces) {
|
||||||
|
return initialBandwidthTrafficTempMapper.batchInsertServerRecoverTemp(interfaces);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -223,5 +223,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="endTime != null and endTime != ''"> and create_time <= #{endTime}</if>
|
<if test="endTime != null and endTime != ''"> and create_time <= #{endTime}</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="countByClientIdAndTime" parameterType="InitialBandwidthTraffic" resultType="java.lang.Integer">
|
||||||
|
select count(1)
|
||||||
|
from ${tableName}
|
||||||
|
<where>
|
||||||
|
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||||
|
<if test="startTime != null"> and create_time = #{startTime}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
+51
-1
@@ -59,7 +59,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="createTime != null"> and create_time = #{createTime}</if>
|
<if test="createTime != null"> and create_time = #{createTime}</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectInitialBandwidthTrafficRecoverTempList" parameterType="InitialBandwidthTrafficTemp" resultMap="InitialBandwidthTrafficTempResult">
|
||||||
|
select id, name, mac, status, type, ipV4, in_dropped, out_dropped, in_speed, out_speed,
|
||||||
|
speed, duplex, create_time, update_time, create_by, update_by, client_id, total_in_speed,
|
||||||
|
total_out_speed, ipv4_in_speed, ipv4_out_speed, ipv6_in_speed, ipv6_out_speed, total_ipv4_in_speed,
|
||||||
|
total_ipv4_out_speed, total_ipv6_in_speed, total_ipv6_out_speed, ipV6
|
||||||
|
from initial_bandwidth_traffic_recover_temp
|
||||||
|
<where>
|
||||||
|
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
||||||
|
<if test="mac != null and mac != ''"> and mac = #{mac}</if>
|
||||||
|
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||||
|
<if test="type != null and type != ''"> and type = #{type}</if>
|
||||||
|
<if test="ipV4 != null and ipV4 != ''"> and ipV4 = #{ipV4}</if>
|
||||||
|
<if test="inDropped != null "> and in_dropped = #{inDropped}</if>
|
||||||
|
<if test="outDropped != null "> and out_dropped = #{outDropped}</if>
|
||||||
|
<if test="inSpeed != null and inSpeed != ''"> and in_speed = #{inSpeed}</if>
|
||||||
|
<if test="outSpeed != null and outSpeed != ''"> and out_speed = #{outSpeed}</if>
|
||||||
|
<if test="speed != null and speed != ''"> and speed = #{speed}</if>
|
||||||
|
<if test="duplex != null and duplex != ''"> and duplex = #{duplex}</if>
|
||||||
|
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||||
|
<if test="totalInSpeed != null and totalInSpeed != ''"> and total_in_speed = #{totalInSpeed}</if>
|
||||||
|
<if test="totalOutSpeed != null and totalOutSpeed != ''"> and total_out_speed = #{totalOutSpeed}</if>
|
||||||
|
<if test="createTime != null"> and create_time = #{createTime}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
<select id="selectInitialBandwidthTrafficTempById" parameterType="Long" resultMap="InitialBandwidthTrafficTempResult">
|
<select id="selectInitialBandwidthTrafficTempById" parameterType="Long" resultMap="InitialBandwidthTrafficTempResult">
|
||||||
<include refid="selectInitialBandwidthTrafficTempVo"/>
|
<include refid="selectInitialBandwidthTrafficTempVo"/>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
@@ -174,6 +197,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<delete id="deleteTempMsgByClientId" parameterType="String">
|
<delete id="deleteTempMsgByClientId" parameterType="String">
|
||||||
delete from initial_bandwidth_traffic_temp where client_id = #{clientId}
|
delete from initial_bandwidth_traffic_temp where client_id = #{clientId}
|
||||||
</delete>
|
</delete>
|
||||||
|
<delete id="deleteTempMsgByClientIdAndTime" parameterType="InitialBandwidthTrafficTemp">
|
||||||
|
delete from initial_bandwidth_traffic_recover_temp where client_id = #{clientId} and create_time=#{createTime}
|
||||||
|
</delete>
|
||||||
|
|
||||||
<insert id="batchInsertServerTemp" parameterType="java.util.List">
|
<insert id="batchInsertServerTemp" parameterType="java.util.List">
|
||||||
insert IGNORE into initial_bandwidth_traffic_temp
|
insert IGNORE into initial_bandwidth_traffic_temp
|
||||||
@@ -199,4 +225,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
)
|
)
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
<insert id="batchInsertServerRecoverTemp" parameterType="java.util.List">
|
||||||
|
insert IGNORE into initial_bandwidth_traffic_recover_temp
|
||||||
|
(
|
||||||
|
name, mac, status, type, ipV4, in_dropped, out_dropped,
|
||||||
|
in_speed, out_speed, speed, duplex, create_time, update_time,
|
||||||
|
create_by, update_by, client_id, total_in_speed, total_out_speed,
|
||||||
|
ipv4_in_speed, ipv4_out_speed, ipv6_in_speed, ipv6_out_speed,
|
||||||
|
total_ipv4_in_speed, total_ipv4_out_speed, total_ipv6_in_speed, total_ipv6_out_speed,
|
||||||
|
ipV6
|
||||||
|
)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="item" index="index" separator=",">
|
||||||
|
(
|
||||||
|
#{item.name}, #{item.mac}, #{item.status}, #{item.type}, #{item.ipV4},
|
||||||
|
#{item.inDropped}, #{item.outDropped}, #{item.inSpeed}, #{item.outSpeed},
|
||||||
|
#{item.speed}, #{item.duplex}, #{item.createTime}, #{item.updateTime},
|
||||||
|
#{item.createBy}, #{item.updateBy}, #{item.clientId}, #{item.totalInSpeed},
|
||||||
|
#{item.totalOutSpeed},
|
||||||
|
#{item.ipv4InSpeed}, #{item.ipv4OutSpeed}, #{item.ipv6InSpeed}, #{item.ipv6OutSpeed},
|
||||||
|
#{item.totalIpv4InSpeed}, #{item.totalIpv4OutSpeed}, #{item.totalIpv6InSpeed}, #{item.totalIpv6OutSpeed},
|
||||||
|
#{item.ipV6}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user