Help us shape the future of Go! Take the 2026 Go Developer Survey

metrics

package
v0.0.167 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package metrics provides a metrics manager that uses OpenTelemetry to track various metrics related to the proxy server's performance. It includes tracking bytes sent and received, connection duration, and the number of connections. The metrics are recorded using OpenTelemetry's metric API and can be used for monitoring and observability purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConn

func NewConn(conn net.Conn, attrs *attributes, tracker *MetricsTracker) net.Conn

NewConn creates a new Conn instance.

func NewPacketConn

func NewPacketConn(conn N.PacketConn, attrs *attributes, tracker *MetricsTracker) N.PacketConn

NewPacketConn creates a new PacketConn instance.

func SetISPLookup

func SetISPLookup(lookup geo.ISPLookup)

SetISPLookup makes proxy.io carry client.asn and client.isp, resolved by lookup alongside the country. It must be called before SetupMetricsManager, which starts the workers that use it.

Only proxy.io gets them: every distinct ASN multiplies a series, and the connection, duration and goodput metrics (the goodput histogram has a series per bucket) don't need the split.

func SetupMetricsManager

func SetupMetricsManager(countryLookup geo.CountryLookup, track string)

Types

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn wraps a net.Conn and tracks metrics such as bytes sent and received.

func (*Conn) Close

func (c *Conn) Close() error

Close records the session's metrics once, then forwards the close: sing-box closes a routed conn up to 3x on non-graceful teardown.

func (*Conn) CloseWrite

func (c *Conn) CloseWrite() error

CloseWrite implements N.WriteCloser to support half-close semantics. This is critical for protocols tunneled over H2 (like Samizdat) where sing-box's bidirectional copy needs to half-close one direction without killing the entire stream.

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

Read overrides net.Conn's Read method to track received bytes.

func (*Conn) Upstream

func (c *Conn) Upstream() any

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

Write overrides net.Conn's Write method to track sent bytes.

type MetricsTracker

type MetricsTracker struct {
	// contains filtered or unexported fields
}

func NewTracker

func NewTracker(ctx context.Context) *MetricsTracker

func (*MetricsTracker) Close

func (t *MetricsTracker) Close() error

func (*MetricsTracker) Leave

func (t *MetricsTracker) Leave(duration int64, attrs *attributes)

func (*MetricsTracker) RoutedConnection

func (t *MetricsTracker) RoutedConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound) net.Conn

func (*MetricsTracker) RoutedPacketConnection

func (t *MetricsTracker) RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound) N.PacketConn

func (*MetricsTracker) TrackIO

func (t *MetricsTracker) TrackIO(d ioAttr, n int, attrs *attributes)

type PacketConn

type PacketConn struct {
	N.PacketConn
	// contains filtered or unexported fields
}

PacketConn wraps a sing-box network.PacketConn and tracks metrics such as bytes sent and received.

func (*PacketConn) Close

func (c *PacketConn) Close() error

Close mirrors Conn.Close: metrics once, then forward the close.

func (*PacketConn) ReadPacket

func (c *PacketConn) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error)

ReadPacket overrides network.PacketConn's ReadPacket method to track received bytes.

func (*PacketConn) Upstream

func (c *PacketConn) Upstream() any

func (*PacketConn) WritePacket

func (c *PacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error

WritePacket overrides network.PacketConn's WritePacket method to track sent bytes.

Jump to

Keyboard shortcuts

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