conntrack

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogFieldBytesIn         = "bytes_in"
	LogFieldBytesOut        = "bytes_out"
	LogFieldEndTime         = "end_time"
	LogFieldDuration        = "duration"
	LogFieldError           = "error"
	LogFieldLastActivity    = "last_activity"
	LogFieldOutboundAddr    = "outbound_remote_addr"
	CanonicalProxyConnClose = "CANONICAL-PROXY-CN-CLOSE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnSuccessRateStats

type ConnSuccessRateStats struct {
	CalculatedAt    time.Time
	ConnSuccessRate float64
	TotalConns      int
}

ConnSuccessRateStats represents a timestamped output of computations performed over connection attempts.

ConnSuccessRate represents the proportion of unique domains whose most recent connection attempt was successful, compared to the total number of domains with connection attempts.

type ConnSuccessRateTracker

type ConnSuccessRateTracker struct {
	ConnAttempts         *cache.Cache
	ConnSuccessRateStats atomic.Value
}

ConnSuccessRateTracker tracks statistics about the overall success rate of connection attempts over some time interval (which is set in StartNewConnSuccessRateTracker()).

It tracks only the *most recently seen* connection to an individual destination host within the configured time interval, to prevent a single destination host from having an outsized impact on statistics.

func StartNewConnSuccessRateTracker

func StartNewConnSuccessRateTracker(calculationInterval time.Duration, calculationWindow time.Duration, cleanupInterval time.Duration, statsc metrics.MetricsClientInterface) *ConnSuccessRateTracker

StartNewConnSuccessRateTracker creates a new ConnSuccessRateTracker with a specific calculation interval at which ConnSuccessRateStats will be recomputed, and a time window to calculate those statistics over. - calculationInterval is how often statistics will be recomputed. - calculationWindow is the period that statistics will be calculated over. - cleanupInterval is how often expired items (e.g., items older than the calculationWindow) will be deleted from memory.

type InstrumentedConn

type InstrumentedConn struct {
	net.Conn
	Role         string
	OutboundHost string

	ConnError error

	Start        time.Time
	LastActivity *int64 // Unix nano

	BytesIn  *uint64
	BytesOut *uint64

	sync.Mutex

	CloseError error
	// contains filtered or unexported fields
}

func (*InstrumentedConn) Close

func (ic *InstrumentedConn) Close() error

func (*InstrumentedConn) Error

func (ic *InstrumentedConn) Error(err error)

func (*InstrumentedConn) Idle

func (ic *InstrumentedConn) Idle() bool

Idle returns true when the connection's last activity occured before the configured idle threshold.

Idle should be called with the connection's lock held.

func (*InstrumentedConn) JsonStats

func (ic *InstrumentedConn) JsonStats() ([]byte, error)

func (*InstrumentedConn) Read

func (ic *InstrumentedConn) Read(b []byte) (int, error)

func (*InstrumentedConn) Stats

func (*InstrumentedConn) Write

func (ic *InstrumentedConn) Write(b []byte) (int, error)

type InstrumentedConnStats

type InstrumentedConnStats struct {
	Role                     string    `json:"role"`
	Rhost                    string    `json:"rhost"`
	Raddr                    string    `json:"raddr"`
	Created                  time.Time `json:"created"`
	BytesIn                  uint64    `json:"bytesIn"`
	BytesOut                 uint64    `json:"bytesOut"`
	SecondsSinceLastActivity float64   `json:"secondsSinceLastActivity"`
	ProxyType                string    `json:"proxyType"`
}

type Tracker

type Tracker struct {
	*sync.Map
	ShuttingDown atomic.Value

	SuccessRateTracker *ConnSuccessRateTracker

	// A connection is idle if it has been inactive (no bytes in/out) for this
	// many seconds.
	IdleTimeout time.Duration
	// contains filtered or unexported fields
}

func NewTracker

func NewTracker(idle time.Duration, statsc metrics.MetricsClientInterface, logger *logrus.Logger, sd atomic.Value, successRateTracker *ConnSuccessRateTracker) *Tracker

func (*Tracker) MaybeIdleIn

func (tr *Tracker) MaybeIdleIn(d time.Duration) time.Duration

MaybeIdleIn returns the longest amount of time it will take for all tracked connections to become idle based on the configured IdleTimeout.

A duration of 0 indicates all connections are idle.

func (*Tracker) NewInstrumentedConn

func (t *Tracker) NewInstrumentedConn(conn net.Conn, logger *logrus.Entry, role, outboundHost, proxyType string) *InstrumentedConn

func (*Tracker) NewInstrumentedConnWithTimeout

func (t *Tracker) NewInstrumentedConnWithTimeout(conn net.Conn, timeout time.Duration, logger *logrus.Entry, role, outboundHost, proxyType string) *InstrumentedConn

func (*Tracker) RecordAttempt

func (tr *Tracker) RecordAttempt(dest string, success bool)

RecordAttempt stores the result of the most recent connection attempt for a destination.

func (*Tracker) ReportConnectionSuccessRate

func (tr *Tracker) ReportConnectionSuccessRate() *ConnSuccessRateStats

func (*Tracker) Wg

func (tr *Tracker) Wg() *sync.WaitGroup

type TrackerInterface

type TrackerInterface interface {
	ReportConnectionSuccessRate() *ConnSuccessRateStats
	RecordAttempt(string, bool)
	MaybeIdleIn(time.Duration) time.Duration
	NewInstrumentedConn(net.Conn, *logrus.Entry, string, string, string) *InstrumentedConn
	NewInstrumentedConnWithTimeout(net.Conn, time.Duration, *logrus.Entry, string, string, string) *InstrumentedConn
	Wg() *sync.WaitGroup
	Range(f func(interface{}, interface{}) bool)
}

Jump to

Keyboard shortcuts

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