Skip to content

Commit 6615f98

Browse files
committed
add additional metrics
1 parent 1759c35 commit 6615f98

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

pcap/net_parse.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ func (p *NetworkTrafficParser) ParseFromInterface(
140140
// Signal caller that we're done on exit
141141
defer close(out)
142142

143+
startTime := time.Now()
144+
bufferTimeSum := 0 * time.Second
145+
intervalLength := 1 * time.Minute
143146
for {
144147
select {
145148
// packets channel is going to read until EOF or when signalClose is
@@ -160,6 +163,15 @@ func (p *NetworkTrafficParser) ParseFromInterface(
160163
}
161164
p.observer(packet)
162165
p.packetToParsedNetworkTraffic(out, assembler, packet)
166+
167+
now := time.Now()
168+
if now.Sub(startTime) >= intervalLength {
169+
bufferLength := float64(bufferTimeSum.Nanoseconds()) / float64(intervalLength.Nanoseconds())
170+
printer.Debugf("Approximate unprocessed-packets buffer length: %v", bufferLength)
171+
bufferTimeSum = 0 * time.Second
172+
startTime = now
173+
}
174+
bufferTimeSum += now.Sub(packet.Metadata().Timestamp)
163175
case <-ticker.C:
164176
// The assembler stops reassembly for streams older than streamFlushTimeout.
165177
// This means the corresponding tcpFlow readers will return EOF.

pcap/pcap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (p *pcapImpl) capturePackets(done <-chan struct{}, interfaceName, bpfFilter
7575
now := time.Now()
7676
if now.Sub(startTime) >= intervalLength {
7777
bufferLength := float64(bufferTimeSum.Nanoseconds()) / float64(intervalLength.Nanoseconds())
78-
printer.Debugf("Aproximate pcap buffer length: %v", bufferLength)
78+
printer.Debugf("Aproximate captured-packets buffer length: %v", bufferLength)
7979
bufferTimeSum = 0 * time.Second
8080
startTime = now
8181
}

pcap/run.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pcap
22

33
import (
4+
"time"
5+
46
"github.com/akitasoftware/akita-libs/akinet"
57
akihttp "github.com/akitasoftware/akita-libs/akinet/http"
68
akihttp2 "github.com/akitasoftware/akita-libs/akinet/http2"
@@ -11,6 +13,7 @@ import (
1113
"github.com/google/gopacket"
1214
"github.com/google/gopacket/layers"
1315
"github.com/pkg/errors"
16+
"github.com/postmanlabs/postman-insights-agent/printer"
1417
"github.com/postmanlabs/postman-insights-agent/trace"
1518
)
1619

@@ -50,13 +53,25 @@ func Collect(
5053
return errors.Wrap(err, "couldn't start parsing from interface")
5154
}
5255

56+
startTime := time.Now()
57+
bufferTimeSum := 0 * time.Second
58+
intervalLength := 1 * time.Minute
5359
for t := range parsedChan {
5460
t.Interface = intf
5561
err := proc.Process(t)
5662
t.Content.ReleaseBuffers()
5763
if err != nil {
5864
return err
5965
}
66+
67+
now := time.Now()
68+
if now.Sub(startTime) >= intervalLength {
69+
bufferLength := float64(bufferTimeSum.Nanoseconds()) / float64(intervalLength.Nanoseconds())
70+
printer.Debugf("Aproximate parsed-network-traffic buffer length: %v", bufferLength)
71+
bufferTimeSum = 0 * time.Second
72+
startTime = now
73+
}
74+
bufferTimeSum += now.Sub(t.ObservationTime)
6075
}
6176

6277
return nil

trace/backend_collector.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ func (c *BackendCollector) periodicFlush() {
425425
}
426426

427427
func (c *BackendCollector) flushPairCache(cutoffTime time.Time) {
428+
now := time.Now()
429+
bufferTimeSum := 0 * time.Second
428430
c.pairCache.Range(func(k, v interface{}) bool {
429431
e := v.(*witnessWithInfo)
430432
if e.observationTime.Before(cutoffTime) {
@@ -435,7 +437,13 @@ func (c *BackendCollector) flushPairCache(cutoffTime time.Time) {
435437

436438
c.queueUpload(e)
437439
c.pairCache.Delete(k)
440+
441+
if !e.witnessFlushed {
442+
bufferTimeSum += now.Sub(e.observationTime)
443+
}
438444
}
439445
return true
440446
})
447+
bufferLength := float64(bufferTimeSum.Nanoseconds()) / float64(pairCacheCleanupInterval.Nanoseconds())
448+
printer.Debugf("Approximate unpaired-witness-cache buffer length: %v", bufferLength)
441449
}

0 commit comments

Comments
 (0)