MCPcopy Create free account
hub / github.com/PasarGuard/node / Delta

Method Delta

pkg/stats/interface_counters.go:25–49  ·  view source on GitHub ↗

Delta calculates counters relative to the current baseline. On first sample, it sets baseline and returns zero. If counters roll back (interface reset/restart), it rebases and returns zero.

(currentRx, currentTx int64, reset bool)

Source from the content-addressed store, hash-verified

23// On first sample, it sets baseline and returns zero.
24// If counters roll back (interface reset/restart), it rebases and returns zero.
25func (t *InterfaceCountersTracker) Delta(currentRx, currentTx int64, reset bool) (int64, int64) {
26 t.mu.Lock()
27 defer t.mu.Unlock()
28
29 if !t.baseSet {
30 t.baseRx = currentRx
31 t.baseTx = currentTx
32 t.baseSet = true
33 }
34
35 if currentRx < t.baseRx || currentTx < t.baseTx {
36 t.baseRx = currentRx
37 t.baseTx = currentTx
38 }
39
40 deltaRx := currentRx - t.baseRx
41 deltaTx := currentTx - t.baseTx
42
43 if reset {
44 t.baseRx = currentRx
45 t.baseTx = currentTx
46 }
47
48 return deltaRx, deltaTx
49}
50
51func buildDeltaStats(name, link string, rx, tx int64) []*common.Stat {
52 if rx == 0 && tx == 0 {

Calls

no outgoing calls