浏览代码

增加decode的报文数统计,decode在处理数据包之前

sensordb2 1 年之前
父节点
当前提交
8c3a297e72

+ 2 - 0
insert-app/src/main/java/db/controller/StatisticController.java

@@ -3,6 +3,7 @@ package db.controller;
 import db.dto.StatisticDto;
 import db.entity.ResponseDto;
 import db.service.StatisticService;
+import db.tools.DecodeStatistic;
 import db.util.ResponseUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +25,7 @@ public class StatisticController {
         log.info("==> [api查看统计] 收到查看探针请求");
 
         StatisticDto statisticDto = statisticService.getStatistic().toDto();
+        statisticDto.setNeedDecodePacketNum(DecodeStatistic.getInstance().getNeedDecodePacketNum());
 
         ResponseDto<StatisticDto> ret;
 

+ 2 - 0
insert-app/src/main/java/db/dto/StatisticDto.java

@@ -17,6 +17,8 @@ public class StatisticDto {
     long beginTime;
     long runningTime;
     long dataCount;
+
+    long needDecodePacketNum;
     long dataCountTsdbSuccess;
     long dataCountDiskSuccess;
     double dataRate;

+ 2 - 0
protocol/src/main/java/db/netty/Decoder.java

@@ -2,6 +2,7 @@ package db.netty;
 
 import db.Globals;
 import db.entity.packages.*;
+import db.tools.DecodeStatistic;
 import db.util.ConvertUtils;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
@@ -20,6 +21,7 @@ public class Decoder extends MessageToMessageDecoder<DatagramPacket> {
 
     @Override
     protected void decode(ChannelHandlerContext ctx, DatagramPacket datagramPacket, List<Object> out) throws Exception {
+        DecodeStatistic.getInstance().increaseNeedDecodePacketNum(1);
         if(!decode) return;
 
         ByteBuf udpPacketBytes = datagramPacket.content();

+ 26 - 0
protocol/src/main/java/db/tools/DecodeStatistic.java

@@ -0,0 +1,26 @@
+package db.tools;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * 功能描述
+ *
+ * @author: scott
+ * @date: 2023年01月12日 2:50 PM
+ */
+public class DecodeStatistic {
+    private static DecodeStatistic instance = new DecodeStatistic();
+    private AtomicLong needDecodePacketNum = new AtomicLong();
+    public static DecodeStatistic getInstance() {
+        return instance;
+    }
+
+    public void increaseNeedDecodePacketNum(int num) {
+        this.needDecodePacketNum.addAndGet(num);
+    }
+
+    public long getNeedDecodePacketNum() {
+        return this.needDecodePacketNum.get();
+    }
+
+}

+ 6 - 0
shell/resetAndStartInsert.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+ROOT=$(cd `dirname $0`/../; pwd)
+$ROOT/shell/stopAllAndCleanData.sh
+$ROOT/shell/insert/start.sh
+$ROOT/shell/insert/status.sh
+echo "finish"