Documentation ¶
Index ¶
- Constants
- type ConnSuccessRateStats
- type ConnSuccessRateTracker
- type InstrumentedConn
- func (ic *InstrumentedConn) Close() error
- func (ic *InstrumentedConn) Error(err error)
- func (ic *InstrumentedConn) Idle() bool
- func (ic *InstrumentedConn) JsonStats() ([]byte, error)
- func (ic *InstrumentedConn) Read(b []byte) (int, error)
- func (ic *InstrumentedConn) Stats() *InstrumentedConnStats
- func (ic *InstrumentedConn) Write(b []byte) (int, error)
- type InstrumentedConnStats
- type Tracker
- func (tr *Tracker) MaybeIdleIn(d time.Duration) time.Duration
- func (t *Tracker) NewInstrumentedConn(conn net.Conn, logger *logrus.Entry, role, outboundHost, proxyType string) *InstrumentedConn
- func (t *Tracker) NewInstrumentedConnWithTimeout(conn net.Conn, timeout time.Duration, logger *logrus.Entry, ...) *InstrumentedConn
- func (tr *Tracker) RecordAttempt(dest string, success bool)
- func (tr *Tracker) ReportConnectionSuccessRate() *ConnSuccessRateStats
- func (tr *Tracker) Wg() *sync.WaitGroup
- type TrackerInterface
Constants ¶
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 ¶
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 ¶
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) Stats ¶
func (ic *InstrumentedConn) Stats() *InstrumentedConnStats
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 ¶
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 (*Tracker) NewInstrumentedConnWithTimeout ¶
func (*Tracker) RecordAttempt ¶
RecordAttempt stores the result of the most recent connection attempt for a destination.
func (*Tracker) ReportConnectionSuccessRate ¶
func (tr *Tracker) ReportConnectionSuccessRate() *ConnSuccessRateStats
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) }