Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Monitor ¶
type Monitor struct { // The scheduler object used to perform regular availability checks. Scheduler *Scheduler // Interface to the status storage. By default Monitor will use in-memory // internal storage (SimpleStore), but you might want to use some other // backend like Redis with RedisStore. StatusStore StatusStore // Expiration time for status values in the store. ExpirationTime time.Duration // If this flag describes how the monitor reacts to new statuses. // A new status is a status of a target, which has not been checked out into // status store yet. // If this flag is set to false, monitor will NOT send new OK statuses // into Updates chanel, but will send new error statuses. // If this flag is set to true, monitor will send any new status to Updates. NotifyFirstOK bool // Channel by which the monitor will send all status changes. // Whenever a type of a target's status (Status.Type) changes, monitor will // send the target and its _new_ status into this channel. // If the caller ignores this channel and does not read values from it, // the monitor (and its scheduler) will clobber and stop doing status checks. Updates chan TargetStatus // contains filtered or unexported fields }
Monitor is a wrapper around Scheduler, which saves statuses into a StatusStore and sends status changes into Updates channel.
func New ¶
func New(targets TargetsGetter) *Monitor
New creates a Monitor with given targets getter and default field values.
type Poller ¶
type Poller struct { // Timeout of network request. Timeout time.Duration // How many times should poller repeat the request if all previous ones // ended in timeout. TimeoutRetries int }
Poller makes HTTP request to some URL to return its availability status.
func (*Poller) PollService ¶
PollService makes HTTP GET request to the URL and returns its availability status. If there was an error during request, the returned Status structure will contain information about the error.
type RedisOptions ¶
RedisOptions contains options for connecting to a redis instance.
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore is an implementation of StatusStore, which uses Redis as storage backend.
func NewRedisStore ¶
func NewRedisStore(opt RedisOptions) *RedisStore
NewRedisStore constructs a new RedisStore, which connect to the redis instance, pointed by `opt`.
func (*RedisStore) GetStatus ¶
func (rs *RedisStore) GetStatus(t Target) (Status, bool, error)
GetStatus attempts to retrieve target's status from redis. If status is not set, it will return ok=false, err=nil.
func (*RedisStore) Ping ¶
func (rs *RedisStore) Ping() error
Ping checks redis instance for availability by issuing `PING` command. If redis is available, it returns nil.
func (*RedisStore) Scan ¶
func (rs *RedisStore) Scan() ([]TargetStatus, error)
Scan searches redis db for stored statuses using `SCAN` command and returns a list of all found items.
type Scheduler ¶
type Scheduler struct { // The Poller object which will be used to do polling. Poller *Poller // Source of lists of targets. Targets TargetsGetter // Time interval between targets polling. Interval time.Duration // Maximum number of parallel http requests. ParallelPolls uint // The channel into which the scheduler will write the polling results. Statuses chan TargetStatus // contains filtered or unexported fields }
Scheduler is an object which performs availability polling once every interval and writes the availability statuses into a channel.
func NewScheduler ¶
func NewScheduler(targets TargetsGetter) *Scheduler
NewScheduler constructs a new Scheduler with given TargetsGetter and default fields values.
func (*Scheduler) Errors ¶
Errors retruns a channel through which the Scheduler will send all errors, appearing in the process.
func (*Scheduler) PollTargets ¶
func (s *Scheduler) PollTargets()
PollTargets does single cycle of targets polling in foreground, which includes: - getting the targets list from s.Targets; - polling each target with s.Poller; - writing results into s.Statuses channel. If the s.Targets returns an error, which method will no perform polling and will attempt to send the error to s.Errors channel, if it's not nil.
type SimpleStore ¶
type SimpleStore map[uint]simpleStoreRecord
SimpleStore is the basic implementation of StatusStore which uses a map as a storage backend.
type Status ¶
type Status struct { Type StatusType // The exact error value, if Type is not StatusOK. // If Type is StatusOK it is nil. Err error // Time spent for the request. ResponseTime time.Duration // If HTTP response was not received, it's set to 0. HTTPStatusCode int }
Status contains information about service availability.
func (Status) ExpandedString ¶
ExpandedString returns a multi-line string, describing contents of the status object.
type StatusStore ¶
type StatusStore interface { GetStatus(t Target) (Status, bool, error) SetStatus(t Target, s Status, exp time.Duration) error }
StatusStore is an interface of storage of availability statuses. Standart implementation of this interface (RedisStore) uses Redis as backend, but some user may reimplement interface to store data in a RDB or in memory.
type StatusType ¶
type StatusType uint
StatusType describes availability status as one enumerable value.
const ( // StatusOK - the service is available. StatusOK StatusType = iota // StatusGenericError - some generic network error. StatusGenericError // StatusTimeout - HTTP request timed out. StatusTimeout // StatusURLParsingError - request URL is invalid. StatusURLParsingError // StatusDNSLookupError - could not resolve domain name. StatusDNSLookupError // StatusHTTPError - the service returned non-successfull HTTP status code. StatusHTTPError )
func ScanStatusType ¶
func ScanStatusType(s string) (StatusType, bool)
ScanStatusType tries to parse StatusType by strictly comparing it to the string representation of each StatusType variant.
func ScanStatusTypeSoft ¶
func ScanStatusTypeSoft(s string) (StatusType, bool)
ScanStatusTypeSoft is similar to ScanStatusType, but on comparing it converts both strings to lower case and does not check for strict equiality, but checks if StatusType's string starts with input string. This method is more error-tolerant and is intended to use with user input.
func (StatusType) String ¶
func (st StatusType) String() string
type Target ¶
type Target struct { // Unique identifier of this target. Targets' IDs cannot intercept. Target's // ID must be constant between GetTargets() calls. ID uint // User-supplied target title, used purely for display. Title string // The HTTP URL to poll. URL string }
Target is a URL, which has to be polled for availability.
type TargetStatus ¶
TargetStatus simply connects target and its status in one structure.
func (TargetStatus) String ¶
func (ts TargetStatus) String() string
type TargetsGetter ¶
TargetsGetter is an interface of targets source. Monitor uses it to retrieve list targets on every polling iteration. External frontend may implement this interface to store targets in a DB or in a configuration file.
type TargetsSlice ¶
type TargetsSlice []Target
TargetsSlice - the most basic implementation on TargetsGetter.
func NewTargetsSliceFromUrls ¶
func NewTargetsSliceFromUrls(urls []string) TargetsSlice
NewTargetsSliceFromUrls constructs TargetsSlice from a list of urls. Each target is given an ID equal to the url's index, and the title of format "Target N".
func (TargetsSlice) GetTargets ¶
func (ts TargetsSlice) GetTargets() ([]Target, error)
GetTargets implements TargetsGetter for TargetsSlice.