summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/stack.go
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2018-08-23 08:54:09 -0700
committerShentubot <shentubot@google.com>2018-08-23 08:55:23 -0700
commitabe7764928bb18fe417c53c8ea8aa9fb970114b7 (patch)
tree4ea44a38b3193ac29a4151daff471d8744f9071e /pkg/tcpip/stack/stack.go
parenta78df1d874f376c0924d5a8f91e9e2b5458cca0f (diff)
Encapsulate netstack metrics
PiperOrigin-RevId: 209943212 Change-Id: I96dcbc7c2ab2426e510b94a564436505256c5c79
Diffstat (limited to 'pkg/tcpip/stack/stack.go')
-rw-r--r--pkg/tcpip/stack/stack.go26
1 files changed, 7 insertions, 19 deletions
diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go
index e09c7efda..cc5427cf9 100644
--- a/pkg/tcpip/stack/stack.go
+++ b/pkg/tcpip/stack/stack.go
@@ -26,7 +26,6 @@ package stack
import (
"sync"
- "sync/atomic"
"time"
"gvisor.googlesource.com/gvisor/pkg/sleep"
@@ -308,6 +307,9 @@ type Options struct {
//
// If no Clock is specified, the clock source will be time.Now.
Clock tcpip.Clock
+
+ // Stats are optional statistic counters.
+ Stats tcpip.Stats
}
// New allocates a new networking stack with only the requested networking and
@@ -331,6 +333,7 @@ func New(network []string, transport []string, opts Options) *Stack {
linkAddrCache: newLinkAddrCache(ageLimit, resolutionTimeout, resolutionAttempts),
PortManager: ports.NewPortManager(),
clock: clock,
+ stats: opts.Stats.FillIn(),
}
// Add specified network protocols.
@@ -437,27 +440,12 @@ func (s *Stack) NowNanoseconds() int64 {
return s.clock.NowNanoseconds()
}
-// Stats returns a snapshot of the current stats.
-//
-// NOTE: The underlying stats are updated using atomic instructions as a result
-// the snapshot returned does not represent the value of all the stats at any
-// single given point of time.
-// TODO: Make stats available in sentry for debugging/diag.
-func (s *Stack) Stats() tcpip.Stats {
- return tcpip.Stats{
- UnknownProtocolRcvdPackets: atomic.LoadUint64(&s.stats.UnknownProtocolRcvdPackets),
- UnknownNetworkEndpointRcvdPackets: atomic.LoadUint64(&s.stats.UnknownNetworkEndpointRcvdPackets),
- MalformedRcvdPackets: atomic.LoadUint64(&s.stats.MalformedRcvdPackets),
- DroppedPackets: atomic.LoadUint64(&s.stats.DroppedPackets),
- }
-}
-
-// MutableStats returns a mutable copy of the current stats.
+// Stats returns a mutable copy of the current stats.
//
// This is not generally exported via the public interface, but is available
// internally.
-func (s *Stack) MutableStats() *tcpip.Stats {
- return &s.stats
+func (s *Stack) Stats() tcpip.Stats {
+ return s.stats
}
// SetRouteTable assigns the route table to be used by this stack. It