Documentation ¶
Overview ¶
Package bytecounter contains code to track the number of bytes sent and received by a probe.
Index ¶
- func MaybeWrap(conn net.Conn, counter *Counter) net.Conn
- func MaybeWrapWithContextByteCounters(ctx context.Context, conn net.Conn) net.Conn
- func WithExperimentByteCounter(ctx context.Context, counter *Counter) context.Context
- func WithSessionByteCounter(ctx context.Context, counter *Counter) context.Context
- func Wrap(conn net.Conn, counter *Counter) net.Conn
- type Conn
- type Counter
- func (c *Counter) BytesReceived() int64
- func (c *Counter) BytesSent() int64
- func (c *Counter) CountBytesReceived(count int)
- func (c *Counter) CountBytesSent(count int)
- func (c *Counter) CountKibiBytesReceived(count float64)
- func (c *Counter) CountKibiBytesSent(count float64)
- func (c *Counter) KibiBytesReceived() float64
- func (c *Counter) KibiBytesSent() float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaybeWrap ¶ added in v3.14.0
MaybeWrap is like wrap if counter is not nil, otherwise it's a no-op.
func MaybeWrapWithContextByteCounters ¶ added in v3.14.0
MaybeWrapWithContextByteCounters wraps a conn with the byte counters that have previosuly been configured into a context.
func WithExperimentByteCounter ¶ added in v3.14.0
WithExperimentByteCounter assigns the experiment byte counter to the context.
func WithSessionByteCounter ¶ added in v3.14.0
WithSessionByteCounter assigns the session byte counter to the context.
Types ¶
type Conn ¶
type Conn struct { // net.Conn is the underlying net.Conn. net.Conn // Counter is the byte counter. Counter *Counter }
Conn wraps a network connection and counts bytes.
type Counter ¶
type Counter struct { // Received contains the bytes received. You MUST initialize // this field, or you can just use the New factory. Received *atomicx.Int64 // Sent contains the bytes sent. You MUST initialize // this field, or you can just use the New factory. Sent *atomicx.Int64 }
Counter counts bytes sent and received.
func ContextExperimentByteCounter ¶ added in v3.14.0
ContextExperimentByteCounter retrieves the experiment byte counter from the context
func ContextSessionByteCounter ¶ added in v3.14.0
ContextSessionByteCounter retrieves the session byte counter from the context
func (*Counter) BytesReceived ¶
BytesReceived returns the bytes received so far.
func (*Counter) CountBytesReceived ¶
CountBytesReceived adds count to the bytes received counter.
func (*Counter) CountBytesSent ¶
CountBytesSent adds count to the bytes sent counter.
func (*Counter) CountKibiBytesReceived ¶
CountKibiBytesReceived adds 1024*count to the bytes received counter.
func (*Counter) CountKibiBytesSent ¶
CountKibiBytesSent adds 1024*count to the bytes sent counter.
func (*Counter) KibiBytesReceived ¶
KibiBytesReceived returns the KiB received so far.
func (*Counter) KibiBytesSent ¶
KibiBytesSent returns the KiB sent so far.