Documentation ¶
Index ¶
- type Duration
- type HTTPRequestMetrics
- type Scout
- func (s *Scout) AddService(serv *Service)
- func (s *Scout) DelService(id uuid.UUID)
- func (s *Scout) GetResponseChannel() chan interface{}
- func (s *Scout) GetService(id uuid.UUID) *Service
- func (s *Scout) GetServices() []*Service
- func (s *Scout) HandleResponses()
- func (s *Scout) StartScoutingServices()
- func (s *Scout) StopScoutingServices()
- type Service
- func (s *Service) Check()
- func (s *Service) CheckHTTP()
- func (s *Service) CheckICMP()
- func (s *Service) CheckNet()
- func (s *Service) DNSCheck() (int64, error)
- func (s *Service) Failure(issue string)
- func (s *Service) Initialize()
- func (s *Service) IsRunning() bool
- func (s *Service) LinearJitterBackoff()
- func (s *Service) Scout()
- func (s *Service) Start()
- func (s *Service) Stop()
- func (s *Service) Success()
- type ServiceFailure
- type ServiceSuccess
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Duration ¶
Duration is a custom type to use for human readable durations in JSON/YAML
func (Duration) MarshalJSON ¶
MarshalJSON marshals human redable durations
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON unmarshals human redable durations
type HTTPRequestMetrics ¶
type HTTPRequestMetrics struct { GetConn int64 GotConn int64 GotFirstResponseByte int64 DNSStart int64 DNSDone int64 ConnectStart int64 ConnectDone int64 TLSHandshakeStart int64 TLSHandshakeDone int64 WroteHeaderField int64 WroteHeaders int64 WroteRequest int64 GotResponse int64 }
func HTTPRequest ¶
func HTTPRequest(ctx context.Context, url, resolveTo, method string, contentType interface{}, headers http.Header, body io.Reader, timeout time.Duration, verifySSL bool) ([]byte, *http.Response, *HTTPRequestMetrics, error)
HTTPRequest is a global function to send a HTTP request
ctx - Context to be used in request url - The URL for HTTP request resolveTo - The ip:port of where to resolve to method - GET, POST, DELETE, PATCH contentType - The HTTP request content type (text/plain, application/json, or nil) headers - Headers to be used for the request body - The body or form data to send with HTTP request timeout - Specific duration to timeout on. time.Duration(30 * time.Seconds) verifySSL - verify the SSL certificate You can use a HTTP Proxy if you HTTP_PROXY environment variable
func (*HTTPRequestMetrics) NetworkLatency ¶
func (m *HTTPRequestMetrics) NetworkLatency() int64
NetworkLatency returns the network connection latency in ms
func (*HTTPRequestMetrics) NetworkLatencyDuration ¶
func (m *HTTPRequestMetrics) NetworkLatencyDuration() time.Duration
NetworkLatencyDuration returns the network connection latency as a Duration
func (*HTTPRequestMetrics) RequestLatency ¶
func (m *HTTPRequestMetrics) RequestLatency() int64
RequestLatency returns the request latency in ms
func (*HTTPRequestMetrics) RequestLatencyDuration ¶
func (m *HTTPRequestMetrics) RequestLatencyDuration() time.Duration
RequestLatencyDuration returns the request latency as a Duration
type Scout ¶
type Scout struct { Services map[uuid.UUID]*Service Responses chan interface{} Running bool Logger logrus.FieldLogger // contains filtered or unexported fields }
func NewScout ¶
func NewScout(servs []*Service, log logrus.FieldLogger) *Scout
NewScout returns a scout
func (*Scout) AddService ¶
AddService adds a service to monitor
func (*Scout) DelService ¶
DelService adds a service to monitor
func (*Scout) GetResponseChannel ¶
func (s *Scout) GetResponseChannel() chan interface{}
GetResponseChannel returns a interface channel that has either ServiceSuccess or ServiceFailure responses
func (*Scout) GetService ¶
GetService returns a service
func (*Scout) GetServices ¶
GetServices returns all services
func (*Scout) HandleResponses ¶
func (s *Scout) HandleResponses()
HandleResponses simply logs current responses, this is not intended to be used, but demonatrates scouts usage
func (*Scout) StartScoutingServices ¶
func (s *Scout) StartScoutingServices()
StartScoutingServices will start the checking go routine for each service
func (*Scout) StopScoutingServices ¶
func (s *Scout) StopScoutingServices()
StopScoutingServices will start the checking go routine for each service
type Service ¶
type Service struct { ID uuid.UUID `json:"id"` Name string `json:"name"` Address string `json:"address"` ResolveTo string `json:"resolveTo"` Expected string `json:"expected"` ExpectedStatus int `json:"expectedStatus"` Interval Duration `json:"checkInterval"` Type string `json:"type"` Method string `json:"method"` PostData string `json:"postData"` Port int `json:"port"` Timeout Duration `json:"timeout"` VerifySSL bool `json:"verifySSL"` Headers http.Header `json:"headers"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` Online bool `json:"online"` DNSResolve int64 `json:"dnsResolve"` RequestLatency int64 `json:"requestLatency"` NetworkLatency int64 `json:"networkLatency"` Trace bool `json:"trace"` TraceData []traceroute.TraceData `json:"traceData,omitempty"` Retry bool `json:"retry"` RetryMinInterval Duration `json:"retryMinInterval"` RetryMaxInterval Duration `json:"retryMaxInterval"` RetryMax int `json:"retryMax"` RetryAttempts int `json:"-" bson:"-"` Running chan bool `json:"-" bson:"-"` Checkpoint time.Time `json:"-" bson:"-"` SleepDuration Duration `json:"-" bson:"-"` LastResponse string `json:"lastResponse"` DownText string `json:"downText"` LastStatusCode int `json:"statusCode"` LastOnline time.Time `json:"lastSuccess"` Logger logrus.FieldLogger `json:"-" bson:"-"` Responses chan interface{} `json:"-" bson:"-"` }
Service is the main struct for Services
func (*Service) Check ¶
func (s *Service) Check()
Check will run checkHttp for HTTP services and checkTcp for TCP services
func (*Service) CheckICMP ¶
func (s *Service) CheckICMP()
CheckICMP will send a ICMP ping packet to the service
func (*Service) DNSCheck ¶
DNSCheck will check the domain name and return a int64 representing the milliseconds it took to resolve DNS
func (*Service) LinearJitterBackoff ¶
func (s *Service) LinearJitterBackoff()
LinearJitterBackoff will perform linear backoff based on the attempt number and with jitter to prevent a thundering herd. Min and max here are NOT absolute values. The number to be multipled by the attempt number will be chosen at random from between them, thus they are bounding the jitter.
func (*Service) Scout ¶
func (s *Service) Scout()
Scout is the main go routine for checking a service
func (*Service) Start ¶
func (s *Service) Start()
Start will create a channel for use to stop the service checking go routine
type ServiceFailure ¶
type ServiceFailure struct { Service uuid.UUID `json:"service"` Issue string `json:"issue"` NetworkLatency int64 `json:"networkLatency"` TraceData []traceroute.TraceData `json:"traceData,omitempty"` RetriesExhausted bool `json:"retiresExhausted,omitempty"` CreatedAt time.Time `json:"createdAt"` ErrorCode int `json:"errorCode,omitempty"` }