metrics

package
v0.52.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConn

func NewConn(c net.Conn) net.Conn

NewConn returns a new net.Conn that wraps the given net.Conn and starts recording metrics from the current time.

func NewConnWithCloser

func NewConnWithCloser(c net.Conn, closer func(net.Conn)) net2.DoneConn

NewConnWithCloser returns a new net.Conn that wraps the given net.Conn and

func NewConnWithLogger

func NewConnWithLogger(c net.Conn, logger zerolog.Logger) net2.DoneConn

NewConnWithLogger returns a new net.Conn that wraps the given net.Conn and logs connection stats when the connection is closed.

func NewConnWithStartTime

func NewConnWithStartTime(c net.Conn, startTime time.Time) net.Conn

NewConnWithStartTime returns a new net.Conn that wraps the given net.Conn and starts recording metrics from the given startTime.

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 FindMetricsConn(c net2.RawConn) *Conn

func (*Conn) BytesRead

func (s *Conn) BytesRead() uint64

BytesRead returns the number of bytes read.

func (*Conn) BytesWritten

func (s *Conn) BytesWritten() uint64

BytesWritten returns the number of bytes written.

func (*Conn) Close

func (s *Conn) Close() error

Close closes the connection.

func (*Conn) Done added in v0.44.0

func (s *Conn) Done() <-chan struct{}

func (*Conn) Duration

func (s *Conn) Duration() time.Duration

Duration returns the duration of the connection.

func (*Conn) EndTime

func (s *Conn) EndTime() time.Time

EndTime returns the time when the connection was closed.

func (*Conn) LocalAddr

func (s *Conn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Conn) NetConn

func (s *Conn) NetConn() net.Conn

NetConn returns the underlying net.Conn.

func (*Conn) Read

func (s *Conn) Read(b []byte) (int, error)

Read reads data from the connection.

func (*Conn) RemoteAddr

func (s *Conn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*Conn) ResetMetrics

func (s *Conn) ResetMetrics()

ResetMetrics resets the metrics.

func (*Conn) SetDeadline

func (s *Conn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the

func (*Conn) SetKeepAlive

func (s *Conn) SetKeepAlive(keepalive bool) error

SetKeepAlive sets whether the operating system should send keepalive

func (*Conn) SetKeepAlivePeriod

func (s *Conn) SetKeepAlivePeriod(d time.Duration) error

SetKeepAlivePeriod sets period between keep alives.

func (*Conn) SetReadDeadline

func (s *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls.

func (*Conn) SetWriteDeadline

func (s *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls.

func (*Conn) StartTime

func (s *Conn) StartTime() time.Time

StartTime returns the time when the connection was opened.

func (*Conn) Write

func (s *Conn) Write(b []byte) (int, error)

Write writes data to the connection.

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
}

func NewListener

func NewListener(l net.Listener) *Listener

func NewListenerWithLogger

func NewListenerWithLogger(l net.Listener, logger zerolog.Logger) *Listener

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

func (*Listener) AcceptedCount

func (l *Listener) AcceptedCount() int

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

func (*Listener) Close

func (l *Listener) Close() error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL