stats

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StatRecorder

type StatRecorder struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*StatRecorder) AddResponse

func (t *StatRecorder) AddResponse(responseTime time.Duration, statusCode int)

func (*StatRecorder) GetStat

func (t *StatRecorder) GetStat() TargetStats

type StatServer

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

func NewStatServer

func NewStatServer(opts ...StatServerOption) *StatServer

func (*StatServer) ListenAndServe

func (s *StatServer) ListenAndServe() error

func (*StatServer) PostRequest

func (s *StatServer) PostRequest(targetPrefix string) func(*http.Response) *http.Response

func (*StatServer) PreRequest

func (s *StatServer) PreRequest(targetPrefix string) func(*http.Request) *http.Request

func (*StatServer) RegisterTarget

func (s *StatServer) RegisterTarget(target proxy.Target)

type StatServerOption

type StatServerOption func(*StatServer)

func WithCaptureWindow

func WithCaptureWindow(window time.Duration) StatServerOption

func WithPort

func WithPort(port int) StatServerOption

type TargetStats

type TargetStats struct {
	StatStartDate time.Time `json:"statStartDate"`
	// the total number of requests
	TotalRequestCount int `json:"totalRequestCount"`
	// average response time
	TotalAvgResponseTime time.Duration `json:"totalAvgResponseTime"`

	// the time window to base the stats on
	// e.g. 1 minute would capture the responses of the last minute to calculate the stats
	WindowDuration time.Duration `json:"windowDuration"`

	// the average response time in the window duration
	AvgResponseTime time.Duration `json:"avgResponseTime"`
	// the number of requests in the window duration
	RequestCount int `json:"requestCount"`
	// the number of requests per second in the window duration
	RequestRate float64 `json:"requestRate"`

	// the number of requests that failed (Status >= 400) in the window duration
	ErrorRate float64 `json:"errorRate"`
}

Jump to

Keyboard shortcuts

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