3 Коміти 00da132a0e ... 8c3a297e72

Автор SHA1 Опис Дата
  sensordb2 8c3a297e72 增加decode的报文数统计,decode在处理数据包之前 1 рік тому
  sensordb2 ac766aeefd Merge branch 'dev' of http://47.101.131.235:3000/FutureYu/BlackBoxSystem into dev 1 рік тому
  sensordb2 ad165f9b5b 增加调试标志是否解析报文 1 рік тому

+ 2 - 1
conf/application-insert.yml

@@ -46,4 +46,5 @@ server:
     context-path: /api/v1
 
 debug:
-  justReceivePacket: false
+  justReceivePacket: false
+  decode: true

+ 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;

+ 8 - 1
insert-app/src/main/java/db/netty/NettyServer.java

@@ -50,6 +50,11 @@ public class NettyServer {
 
     @Value("${debug.justReceivePacket}")
     private Boolean isJustReceivePacket;
+    @Value("${debug.decode}")
+    private Boolean decodePacketOrNot;
+
+    @Value("${netty.recvBufferSize}")
+    private Integer recvBufferSize;
 
     private DelayQueue<BasePackage> sendingQueue = new DelayQueue<>();
 
@@ -72,13 +77,15 @@ public class NettyServer {
         Decoder decoder = new Decoder();
         NettyServerHandler nettyServerHandler = new NettyServerHandler();
         decoder.setShowRecvBytes(this.showRecvBytes);
+        decoder.setDecode(this.decodePacketOrNot);
+        log.info("Netty-Server decode showRecvBytes:{} decodePacketOrNot:{}", this.showRecvBytes, this.decodePacketOrNot);
 
         bootstrap.group(group)
                 // 指定Channel
                 .channel(useMultiThread ? EpollDatagramChannel.class : NioDatagramChannel.class)
 
                 .option(ChannelOption.SO_BROADCAST, true)
-                .option(ChannelOption.SO_RCVBUF, 1024 * 1024 * 10)
+                .option(ChannelOption.SO_RCVBUF, 1024 * 1024 * recvBufferSize)
 
                 .handler(new ChannelInitializer<Channel>() {
                     @Override

+ 3 - 1
insert-app/src/main/resources/application.yml

@@ -56,6 +56,7 @@ netty:
   host: 0.0.0.0
   port: 1208
   useSeperateThread: false
+  recvBufferSize: 3
 
 server:
   port: 8081
@@ -63,4 +64,5 @@ server:
     context-path: /api/v1
 
 debug:
-  justReceivePacket: false
+  justReceivePacket: false
+  decode: true

+ 9 - 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;
@@ -16,9 +17,13 @@ import java.util.List;
 @Sharable
 public class Decoder extends MessageToMessageDecoder<DatagramPacket> {
     private boolean showRecvBytes = true;
+    private boolean decode = true;
 
     @Override
     protected void decode(ChannelHandlerContext ctx, DatagramPacket datagramPacket, List<Object> out) throws Exception {
+        DecodeStatistic.getInstance().increaseNeedDecodePacketNum(1);
+        if(!decode) return;
+
         ByteBuf udpPacketBytes = datagramPacket.content();
         byte[] bytesReady = new byte[udpPacketBytes.readableBytes()];
         udpPacketBytes.getBytes(0, bytesReady);
@@ -185,6 +190,10 @@ public class Decoder extends MessageToMessageDecoder<DatagramPacket> {
     public void setShowRecvBytes(boolean showRecvBytes) {
         this.showRecvBytes = showRecvBytes;
     }
+
+    public void setDecode(boolean decode) {
+        this.decode = decode;
+    }
 }
 
 

+ 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();
+    }
+
+}

+ 30 - 0
shell/insert/threadStatus.sh

@@ -0,0 +1,30 @@
+#!/bin/sh
+
+ROOT=$(cd `dirname $0`/../../; pwd)
+cd $ROOT
+APP_NAME=blackbox-insert
+JAVA_HOME=$ROOT/jdk8
+JAR_NAME=$ROOT/lib/insert-app-0.0.1-SNAPSHOT.jar
+#PID  代表是PID文件
+PID=$ROOT/pid/$APP_NAME\.pid
+
+get_pid(){
+  pid=`ps -ef|grep $JAR_NAME|grep -v grep|awk '{print $2}' `
+  #如果不存在返回1,存在返回0
+  if [ -z "${pid}" ]; then
+   return 1
+  else
+    return 0
+  fi
+}
+
+get_pid
+
+if [ $? -eq "0" ]; then
+  echo ">>> ${JAR_NAME} is running PID is ${pid} <<<"
+  #ps -fT -p ${pid}
+  top -H -p ${pid}
+else
+  echo ">>> ${JAR_NAME} is not running <<<"
+fi
+exit 0

+ 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"

+ 16 - 0
shell/udp/diagnose.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+ROOT=$(cd `dirname $0`/../../; pwd)
+
+NET_CARD=enp2s0
+
+echo ethtool
+#ethtool -S $NET_CARD
+ethtool -S $NET_CARD | grep rx_ | grep errors
+
+echo ifconfig
+ifconfig $NET_CARD
+
+echo netstat
+netstat -s -u
+
+

+ 8 - 0
shell/udp/increaseLinuxUdpRmem.sh

@@ -0,0 +1,8 @@
+#!/bin/bash
+rmemCount=`cat /etc/sysctl.conf|grep "net.core.rmem_max" | wc -l`
+if [ ${rmemCount} -eq 0 ]
+then
+    echo "net.core.rmem_max = 2147483647" >> /etc/sysctl.conf
+    sysctl -p
+    echo "finish"
+fi

+ 4 - 0
shell/udp/linuxUdpMonitor.sh

@@ -0,0 +1,4 @@
+#!/bin/bash
+ROOT=$(cd `dirname $0`/../../; pwd)
+watch -n 1 -d 'cat /proc/net/udp'
+#watch -n 1 -d 'cat /proc/net/udp >> $ROOT/logs/udpDump.txt'