change capture rate
This commit is contained in:
parent
3fa975a29b
commit
39b5661e9f
|
@ -104,9 +104,6 @@ func (nc *networkCard) Listen() (receiver chan model.QueryPiece) {
|
|||
return nc.receiver
|
||||
}
|
||||
|
||||
func isFINPacket(data []byte) (isFIN bool) {
|
||||
return
|
||||
}
|
||||
|
||||
// Listen get a connection.
|
||||
func (nc *networkCard) listenNormal() {
|
||||
|
@ -119,6 +116,18 @@ func (nc *networkCard) listenNormal() {
|
|||
var ci gopacket.CaptureInfo
|
||||
var err error
|
||||
|
||||
// capture packets according to a certain probability
|
||||
capturePacketRate := communicator.GetMysqlCapturePacketRate()
|
||||
if capturePacketRate <= 0 {
|
||||
time.Sleep(time.Second*1)
|
||||
aliveCounter += 1
|
||||
if aliveCounter >= checkCount {
|
||||
aliveCounter = 0
|
||||
nc.receiver <- model.NewBaseQueryPiece(localIPAddr, nc.listenPort, capturePacketRate)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
data, ci, err = handler.ZeroCopyReadPacketData()
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
|
@ -138,21 +147,10 @@ func (nc *networkCard) listenNormal() {
|
|||
continue
|
||||
}
|
||||
|
||||
// capture packets according to a certain probability
|
||||
tcpCapturePacketRate := communicator.GetTCPCapturePacketRate()
|
||||
if tcpCapturePacketRate <= 0 {
|
||||
time.Sleep(time.Second*1)
|
||||
aliveCounter += 1
|
||||
if aliveCounter >= checkCount {
|
||||
aliveCounter = 0
|
||||
nc.receiver <- model.NewBaseQueryPiece(localIPAddr, nc.listenPort, tcpCapturePacketRate)
|
||||
}
|
||||
continue
|
||||
|
||||
} else if 0 < tcpCapturePacketRate && tcpCapturePacketRate < 1.0 {
|
||||
if 0 < capturePacketRate && capturePacketRate < 1.0 {
|
||||
// fall into throw range
|
||||
rn := rand.Float64()
|
||||
if rn > tcpCapturePacketRate {
|
||||
if rn > capturePacketRate {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue