Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor periodically pings both legs of a proxied connection and records the round trip times so that they may be emitted to consumers.
func NewMonitor ¶
func NewMonitor(cfg MonitorConfig) (*Monitor, error)
NewMonitor creates an unstarted Monitor with the provided configuration. To begin sampling connection latencies Monitor.Run must be called.
func (*Monitor) GetStats ¶
func (m *Monitor) GetStats() Statistics
GetStats returns a copy of the last known latency measurements.
type MonitorConfig ¶
type MonitorConfig struct { // ClientPinger measure the round trip time for client half of the connection. ClientPinger Pinger // ServerPinger measure the round trip time for server half of the connection. ServerPinger Pinger // Reporter periodically emits statistics to consumers. Reporter Reporter // Clock used to measure time. Clock clockwork.Clock // InitialPingInterval an optional duration to use for the first PingInterval. InitialPingInterval time.Duration // PingInterval is the frequency at which both legs of the connection are pinged for // latency calculations. PingInterval time.Duration // InitialReportInterval an optional duration to use for the first ReportInterval. InitialReportInterval time.Duration // ReportInterval is the frequency at which the latency information is reported. ReportInterval time.Duration }
MonitorConfig provides required dependencies for the Monitor.
func (*MonitorConfig) CheckAndSetDefaults ¶
func (c *MonitorConfig) CheckAndSetDefaults() error
CheckAndSetDefaults ensures required fields are provided and sets default values for any omitted optional fields.
type Pinger ¶
Pinger abstracts the mechanism used to measure the round trip time of a connection. All "ping" messages should be responded to before returning from [Pinger.Ping].
type Reporter ¶
type Reporter interface {
Report(ctx context.Context, statistics Statistics) error
}
Reporter is an abstraction over how to provide the latency statistics to the consumer. Used by the Monitor to provide periodic latency updates.
type ReporterFunc ¶
type ReporterFunc func(ctx context.Context, stats Statistics) error
ReporterFunc type is an adapter to allow the use of ordinary functions as a Reporter. If f is a function with the appropriate signature, Reporter(f) is a Reporter that calls f.
func (ReporterFunc) Report ¶
func (f ReporterFunc) Report(ctx context.Context, stats Statistics) error
Report calls f(ctx, stats).
type SSHClient ¶
type SSHClient interface {
SendRequest(ctx context.Context, name string, wantReply bool, payload []byte) (bool, []byte, error)
}
SSHClient is the subset of the [ssh.Client] required by the SSHPinger.
type SSHPinger ¶
type SSHPinger struct {
// contains filtered or unexported fields
}
SSHPinger is a Pinger implementation that measures the latency of an SSH connection. To calculate round trip time, a keepalive@openssh.com request is sent.
func NewSSHPinger ¶
NewSSHPinger creates a new SSHPinger with the provided configuration.
type Statistics ¶
type Statistics struct { // Client measures the round trip time between the client and the Proxy. Client int64 // Server measures the round trip time the Proxy and the target host. Server int64 }
Statistics contain latency measurements for both legs of a proxied connection.
type WebSocket ¶
type WebSocket interface { WriteControl(messageType int, data []byte, deadline time.Time) error PongHandler() func(appData string) error SetPongHandler(h func(appData string) error) }
WebSocket is the subset of [websocket.Conn] required by the WebSocketPinger.
type WebSocketPinger ¶
type WebSocketPinger struct {
// contains filtered or unexported fields
}
WebSocketPinger is a Pinger implementation that measures the latency of a websocket connection.
func NewWebsocketPinger ¶
func NewWebsocketPinger(clock clockwork.Clock, ws WebSocket) (*WebSocketPinger, error)
NewWebsocketPinger creates a WebSocketPinger with the provided configuration.
func (*WebSocketPinger) Ping ¶
func (s *WebSocketPinger) Ping(ctx context.Context) error
Ping writes a ping control message and waits for the corresponding pong control message to be received before returning. The random identifier in the ping message is expected to be returned in the pong payload so that we can determine the true round trip time for a ping/pong message pair.