Documentation
¶
Overview ¶
Package gopatrol provides means for checking and reporting the status and performance of various endpoints in a distributed, lock-free, self-hosted fashion.
Index ¶
Constants ¶
const ( Healthy = "healthy" Degraded = "degraded" Down = "down" Unknown = "unknown" )
Text representations for the status of a check.
Variables ¶
var DefaultConcurrentChecks = 5
DefaultConcurrentChecks is how many checks, at most, to perform concurrently.
var DefaultHTTPClient = &http.Client{ Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 0, }).Dial, TLSHandshakeTimeout: 5 * time.Second, ExpectContinueTimeout: 1 * time.Second, MaxIdleConnsPerHost: 1, DisableCompression: true, DisableKeepAlives: true, ResponseHeaderTimeout: 5 * time.Second, }, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, Timeout: 10 * time.Second, }
DefaultHTTPClient is used when no other http.Client is specified on a HTTPChecker.
Functions ¶
This section is empty.
Types ¶
type CacheService ¶
type CheckersService ¶
type CheckersService interface {
InsertChecker(checker interface{}) error
GetAllCheckers(query map[string]interface{}) ([]interface{}, error)
GetCheckerBySlug(slug string) (interface{}, error)
CountCheckers(query map[string]interface{}) (int, error)
DeleteCheckerBySlug(slug string) error
UpdateCheckerBySlug(slug string, updateData interface{}) error
}
type Checkup ¶
type Checkup struct {
// Checkers is the list of Checkers to use with
// which to perform checks.
Checkers []Checker `json:"checkers,omitempty"`
// ConcurrentChecks is how many checks, at most, to
// perform concurrently. Default is
// DefaultConcurrentChecks.
ConcurrentChecks int `json:"concurrent_checks,omitempty"`
// Timestamp is the timestamp to force for all checks.
// Useful if wanting to perform distributed check
// "at the same time" even if they might actually
// be a few milliseconds or seconds apart.
Timestamp time.Time `json:"timestamp,omitempty"`
// Notifier is a notifier that will be passed the
// results after checks from all checkers have
// completed. Notifier may evaluate and choose to
// send a notification of potential problems.
Notifier []Notifier `json:"notifier,omitempty"`
}
Checkup performs a routine checkup on endpoints or services.
type DNSChecker ¶
type DNSChecker struct {
Slug string `json:"slug" valid:"required"`
// Name is the name of the endpoint.
Name string `json:"name,omitempty" valid:"required"`
// URL is the URL of the endpoint.
URL string `json:"url,omitempty" valid:"required"`
Type string `json:"type,omitempty" valid:"required"`
// ThresholdRTT is the maximum round trip time to
// allow for a healthy endpoint. If non-zero and a
// request takes longer than ThresholdRTT, the
// endpoint will be considered unhealthy. Note that
// this duration includes any in-between network
// latency.
ThresholdRTT time.Duration `json:"threshold_rtt,omitempty"`
// Attempts is how many requests the client will
// make to the endpoint in a single check.
Attempts int `json:"attempts,omitempty"` // This is the fqdn of the target server to query the DNS server for.
Host string `json:"hostname_fqdn,omitempty"`
// Timeout is the maximum time to wait for a
// TCP connection to be established.
Timeout time.Duration `json:"timeout,omitempty"`
LastChecked time.Time `json:"last_checked"`
LastChange time.Time `json:"last_change"`
LastStatus string `json:"last_status"`
}
DNSChecker implements a Checker for TCP endpoints.
func (DNSChecker) Check ¶
func (c DNSChecker) Check() (Result, error)
Check performs checks using c according to its configuration. An error is only returned if there is a configuration error.
type Errors ¶
type Errors []error
Errors is an error type that concatenates multiple errors.
type Event ¶
type Event struct {
Slug string `json:"slug" bson:"slug"`
Name string `json:"name" bson:"name"`
URL string `json:"url" bson:"url"`
Message string `json:"message" bson:"message"`
Type string `json:"type" bson:"type"`
Timestamp time.Time `json:"timestamp" bson:"timestamp"`
Reason string `json:"reason" bson:"reason"`
}
Event is an event (up or down) of a checker
type EventService ¶
type HTTPChecker ¶
type HTTPChecker struct {
Slug string `json:"slug" valid:"required"`
// Name is the name of the endpoint.
Name string `json:"name,omitempty" valid:"required"`
// URL is the URL of the endpoint.
URL string `json:"url,omitempty" valid:"required"`
Type string `json:"type,omitempty" valid:"required"`
// ThresholdRTT is the maximum round trip time to
// allow for a healthy endpoint. If non-zero and a
// request takes longer than ThresholdRTT, the
// endpoint will be considered unhealthy. Note that
// this duration includes any in-between network
// latency.
ThresholdRTT time.Duration `json:"threshold_rtt,omitempty"`
// Attempts is how many requests the client will
// make to the endpoint in a single check.
Attempts int `json:"attempts,omitempty"`
// UpStatus is the HTTP status code expected by
// a healthy endpoint. Default is http.StatusOK.
UpStatus int `json:"up_status,omitempty"`
// MustContain is a string that the response body
// must contain in order to be considered up.
// NOTE: If set, the entire response body will
// be consumed, which has the potential of using
// lots of memory and slowing down checks if the
// response body is large.
MustContain string `json:"must_contain,omitempty"`
// MustNotContain is a string that the response
// body must NOT contain in order to be considered
// up. If both MustContain and MustNotContain are
// set, they are and-ed together. NOTE: If set,
// the entire response body will be consumed, which
// has the potential of using lots of memory and
// slowing down checks if the response body is large.
MustNotContain string `json:"must_not_contain,omitempty"`
// Client is the http.Client with which to make
// requests. If not set, DefaultHTTPClient is
// used.
Client *http.Client `json:"-" bson:"-"`
// Headers contains headers to added to the request
// that is sent for the check
Headers http.Header `json:"headers,omitempty"`
LastChecked time.Time `json:"last_checked"`
LastChange time.Time `json:"last_change"`
LastStatus string `json:"last_status"`
}
HTTPChecker implements a Checker for HTTP endpoints.
func (HTTPChecker) Check ¶
func (c HTTPChecker) Check() (Result, error)
Check performs checks using c according to its configuration. An error is only returned if there is a configuration error.
type Notifier ¶
Notifier can notify ops or sysadmins of potential problems. A Notifier should keep state to avoid sending repeated notices more often than the admin would like.
type Result ¶
type Result struct {
Slug string
// Title is the title (or name) of the thing that was checked.
// It should be unique, as it acts like an identifier to users.
Name string
// Endpoint is the URL/address/path/identifier/locator/whatever
// of what was checked.
URL string
// Timestamp is when the check occurred; UTC UnixNano format.
Timestamp time.Time
// Times is a list of each individual check attempt.
Times Attempts
// ThresholdRTT is the maximum RTT that was tolerated before
// considering performance to be degraded. Leave 0 if irrelevant.
ThresholdRTT time.Duration
// Healthy, Degraded, and Down contain the ultimate conclusion
// about the endpoint. Exactly one of these should be true;
// any more or less is a bug.
Healthy bool
Degraded bool
Down bool
// Notice contains a description of some condition of this
// check that might have affected the result in some way.
// For example, that the median RTT is above the threshold.
Notice string
// Message is an optional message to show on the status page.
Message string
// Flag to determine whether this result is an event or notification
Event bool
Notification bool
}
Result is the result of a health check.
func (Result) ComputeStats ¶
ComputeStats computes basic statistics about r.
type SlackNotifier ¶
type SlackNotifier struct {
ID string `json:"-"`
RTM *slack.RTM `json:"-"`
SlackAPI *slack.Client `json:"-"`
ChannelID string `json:"channel" validate:"required"`
SlackToken string `json:"token" validate:"required"`
Type string `json:"type" validate:"required"`
}
SlackNotifier is the main struct consist of all the sub component including slack api, real-time messaing api and face detector
func NewSlackNotifier ¶
func NewSlackNotifier(slackToken string, channelID string) *SlackNotifier
NewSlackNotifier create new Thug bot
func (SlackNotifier) GetType ¶
func (t SlackNotifier) GetType() string
GetType return what type of notifier is thiss
func (SlackNotifier) Notify ¶
func (t SlackNotifier) Notify(result Result) error
Notify implements notifier interface, send slack message about an event
type Stats ¶
type Stats struct {
Total time.Duration `json:"total,omitempty"`
Mean time.Duration `json:"mean,omitempty"`
Median time.Duration `json:"median,omitempty"`
Min time.Duration `json:"min,omitempty"`
Max time.Duration `json:"max,omitempty"`
}
Stats is a type that holds information about a Result, especially its various Attempts.
type TCPChecker ¶
type TCPChecker struct {
Slug string `json:"slug" valid:"required"`
// Name is the name of the endpoint.
Name string `json:"name,omitempty" valid:"required"`
// URL is the URL of the endpoint.
URL string `json:"url,omitempty" valid:"required"`
Type string `json:"type,omitempty" valid:"required"`
// ThresholdRTT is the maximum round trip time to
// allow for a healthy endpoint. If non-zero and a
// request takes longer than ThresholdRTT, the
// endpoint will be considered unhealthy. Note that
// this duration includes any in-between network
// latency.
ThresholdRTT time.Duration `json:"threshold_rtt,omitempty"`
// Attempts is how many requests the client will
// make to the endpoint in a single check.
Attempts int `json:"attempts,omitempty"`
// TLSEnabled controls whether to enable TLS or not.
// If set, TLS is enabled.
TLSEnabled bool `json:"tls,omitempty"`
// TLSSkipVerify controls whether to skip server TLS
// certificat validation or not.
TLSSkipVerify bool `json:"tls_skip_verify,omitempty"`
// TLSCAFile is the Certificate Authority used
// to validate the server TLS certificate.
TLSCAFile string `json:"tls_ca_file,omitempty"`
// Timeout is the maximum time to wait for a
// TCP connection to be established.
Timeout time.Duration `json:"timeout,omitempty"`
LastChecked time.Time `json:"last_checked"`
LastChange time.Time `json:"last_change"`
LastStatus string `json:"last_status"`
}
TCPChecker implements a Checker for TCP endpoints.
func (TCPChecker) Check ¶
func (c TCPChecker) Check() (Result, error)
Check performs checks using c according to its configuration. An error is only returned if there is a configuration error.

