minor logging changes (#499)

Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com>
This commit is contained in:
David Levanon 2021-11-23 14:21:53 +02:00 committed by GitHub
parent 4c97316c02
commit 01d6005a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

3
.gitignore vendored
View File

@ -32,3 +32,6 @@ pprof/*
# Database Files # Database Files
*.bin *.bin
*.gob *.gob
# Nohup Files - https://man7.org/linux/man-pages/man1/nohup.1p.html
nohup.*

View File

@ -9,7 +9,7 @@ import (
var Log = logging.MustGetLogger("mizu") var Log = logging.MustGetLogger("mizu")
var format = logging.MustStringFormatter( var format = logging.MustStringFormatter(
`%{time:2006-01-02T15:04:05.999Z-07:00} %{level:-5s} ▶ %{message} ▶ %{pid} %{shortfile} %{shortfunc}`, `[%{time:2006-01-02T15:04:05.000-0700}] %{level:-5s} ▶ %{message} ▶ [%{pid} %{shortfile} %{shortfunc}]`,
) )
func InitLogger(logPath string) { func InitLogger(logPath string) {

View File

@ -16,6 +16,8 @@ import (
"github.com/up9inc/mizu/tap/source" "github.com/up9inc/mizu/tap/source"
) )
const PACKETS_SEEN_LOG_THRESHOLD = 1000
type tcpAssembler struct { type tcpAssembler struct {
*reassembly.Assembler *reassembly.Assembler
streamPool *reassembly.StreamPool streamPool *reassembly.StreamPool
@ -63,7 +65,11 @@ func (a *tcpAssembler) processPackets(dumpPacket bool, packets <-chan source.Tcp
for packetInfo := range packets { for packetInfo := range packets {
packetsCount := diagnose.AppStats.IncPacketsCount() packetsCount := diagnose.AppStats.IncPacketsCount()
logger.Log.Debugf("PACKET #%d", packetsCount)
if packetsCount % PACKETS_SEEN_LOG_THRESHOLD == 0 {
logger.Log.Debugf("Packets seen: #%d", packetsCount)
}
packet := packetInfo.Packet packet := packetInfo.Packet
data := packet.Data() data := packet.Data()
diagnose.AppStats.UpdateProcessedBytes(uint64(len(data))) diagnose.AppStats.UpdateProcessedBytes(uint64(len(data)))
@ -85,7 +91,7 @@ func (a *tcpAssembler) processPackets(dumpPacket bool, packets <-chan source.Tcp
CaptureInfo: packet.Metadata().CaptureInfo, CaptureInfo: packet.Metadata().CaptureInfo,
} }
diagnose.InternalStats.Totalsz += len(tcp.Payload) diagnose.InternalStats.Totalsz += len(tcp.Payload)
logger.Log.Debugf("%s : %v -> %s : %v", packet.NetworkLayer().NetworkFlow().Src(), tcp.SrcPort, packet.NetworkLayer().NetworkFlow().Dst(), tcp.DstPort) logger.Log.Debugf("%s:%v -> %s:%v", packet.NetworkLayer().NetworkFlow().Src(), tcp.SrcPort, packet.NetworkLayer().NetworkFlow().Dst(), tcp.DstPort)
a.assemblerMutex.Lock() a.assemblerMutex.Lock()
a.AssembleWithContext(packet.NetworkLayer().NetworkFlow(), tcp, &c) a.AssembleWithContext(packet.NetworkLayer().NetworkFlow(), tcp, &c)
a.assemblerMutex.Unlock() a.assemblerMutex.Unlock()