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)
| 23 | // On first sample, it sets baseline and returns zero. |
| 24 | // If counters roll back (interface reset/restart), it rebases and returns zero. |
| 25 | func (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 | |
| 51 | func buildDeltaStats(name, link string, rx, tx int64) []*common.Stat { |
| 52 | if rx == 0 && tx == 0 { |
no outgoing calls