Documentation
¶
Overview ¶
Package metrics provides utilities for tracking network connection and listener metrics.
Index ¶
- func NewConn(c net.Conn) net.Conn
- func NewConnWithCloser(c net.Conn, closer func(net.Conn)) net2.DoneConn
- func NewConnWithLogger(c net.Conn, logger zerolog.Logger) net2.DoneConn
- func NewConnWithStartTime(c net.Conn, startTime time.Time) net.Conn
- type Conn
- func (s *Conn) BytesRead() uint64
- func (s *Conn) BytesWritten() uint64
- func (s *Conn) Close() error
- func (s *Conn) Done() <-chan struct{}
- func (s *Conn) Duration() time.Duration
- func (s *Conn) EndTime() time.Time
- func (s *Conn) LocalAddr() net.Addr
- func (s *Conn) NetConn() net.Conn
- func (s *Conn) Read(b []byte) (int, error)
- func (s *Conn) RemoteAddr() net.Addr
- func (s *Conn) ResetMetrics()
- func (s *Conn) SetDeadline(t time.Time) error
- func (s *Conn) SetKeepAlive(keepalive bool) error
- func (s *Conn) SetKeepAlivePeriod(d time.Duration) error
- func (s *Conn) SetReadDeadline(t time.Time) error
- func (s *Conn) SetWriteDeadline(t time.Time) error
- func (s *Conn) StartTime() time.Time
- func (s *Conn) Write(b []byte) (int, error)
- type ConnMetrics
- type Listener
- type ListenerMetrics
- type ReadCounter
- type ReadWriteCounter
- type WrittenCounter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConn ¶
NewConn returns a new net.Conn that wraps the given net.Conn and starts recording metrics from the current time.
func NewConnWithCloser ¶
NewConnWithCloser returns a new net.Conn that wraps the given net.Conn and
func NewConnWithLogger ¶
NewConnWithLogger returns a new net.Conn that wraps the given net.Conn and logs connection stats when the connection is closed.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a net.Conn that records metrics.
func FindMetricsConn ¶ added in v0.45.0
func (*Conn) BytesWritten ¶
BytesWritten returns the number of bytes written.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Conn) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the
func (*Conn) SetKeepAlive ¶
SetKeepAlive sets whether the operating system should send keepalive
func (*Conn) SetKeepAlivePeriod ¶
SetKeepAlivePeriod sets period between keep alives.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the deadline for future Read calls.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets the deadline for future Write calls.
type ConnMetrics ¶
type ConnMetrics interface {
BytesRead() uint64
BytesWritten() uint64
ResetMetrics()
Duration() time.Duration
StartTime() time.Time
EndTime() time.Time
}
ConnMetrics is an interface that exposes metrics for a connection.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener wraps a net.Listener and tracks accepted connection metrics.
func NewListener ¶
NewListener creates a new Listener wrapping the provided net.Listener.
func NewListenerWithLogger ¶
NewListenerWithLogger creates a new Listener wrapping the provided net.Listener and logs metrics using the provided logger.
func (*Listener) AcceptedCount ¶
func (*Listener) ResetMetrics ¶
func (l *Listener) ResetMetrics()
type ListenerMetrics ¶
type ListenerMetrics interface {
AcceptedCount() int
ResetMetrics()
}
type ReadCounter ¶
type ReadCounter interface {
BytesRead() int
}
ReadCounter is an interface that exposes the number of bytes read.
type ReadWriteCounter ¶
type ReadWriteCounter interface {
BytesRead()
BytesWritten()
}
ReadWriteCounter is an interface that exposes the number of bytes read and written.
type WrittenCounter ¶
type WrittenCounter interface {
BytesWritten() int
}
WrittenCounter is an interface that exposes the number of bytes written.