tailscale/net/sockstats/sockstats.go
Mihai Parparita 3e71e0ef68
net/sockstats: remove explicit dependency on wgengine/monitor
Followup to #7177 to avoid adding extra dependencies to the CLI. We
instead declare an interface for the link monitor.

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
2023-03-03 08:37:14 -08:00

47 lines
1.1 KiB
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// Package sockstats collects statistics about network sockets used by
// the Tailscale client. The context where sockets are used must be
// instrumented with the WithSockStats() function.
//
// Only available on POSIX platforms when built with Tailscale's fork of Go.
package sockstats
import (
"context"
"tailscale.com/net/interfaces"
)
type SockStats struct {
Stats map[string]SockStat
Interfaces []string
}
type SockStat struct {
TxBytes int64
RxBytes int64
TxBytesByInterface map[string]int64
RxBytesByInterface map[string]int64
}
func WithSockStats(ctx context.Context, label string) context.Context {
return withSockStats(ctx, label)
}
func Get() *SockStats {
return get()
}
// LinkMonitor is the interface for the parts of wgengine/mointor's Mon that we
// need, to avoid the dependency.
type LinkMonitor interface {
InterfaceState() *interfaces.State
RegisterChangeCallback(interfaces.ChangeFunc) (unregister func())
}
func SetLinkMonitor(lm LinkMonitor) {
setLinkMonitor(lm)
}