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 ¶
- func NewConn(conn net.Conn, attrs *attributes, tracker *MetricsTracker) net.Conn
- func NewPacketConn(conn N.PacketConn, attrs *attributes, tracker *MetricsTracker) N.PacketConn
- func SetISPLookup(lookup geo.ISPLookup)
- func SetupMetricsManager(countryLookup geo.CountryLookup, track string)
- type Conn
- type MetricsTracker
- func (t *MetricsTracker) Close() error
- func (t *MetricsTracker) Leave(duration int64, attrs *attributes)
- func (t *MetricsTracker) RoutedConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, ...) net.Conn
- func (t *MetricsTracker) RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, ...) N.PacketConn
- func (t *MetricsTracker) TrackIO(d ioAttr, n int, attrs *attributes)
- type PacketConn
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 ¶
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 ¶
Conn wraps a net.Conn and tracks metrics such as bytes sent and received.
func (*Conn) Close ¶
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 ¶
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.
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 (*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 ¶
ReadPacket overrides network.PacketConn's ReadPacket method to track received bytes.
func (*PacketConn) Upstream ¶
func (c *PacketConn) Upstream() any
func (*PacketConn) WritePacket ¶
WritePacket overrides network.PacketConn's WritePacket method to track sent bytes.