Documentation ¶
Overview ¶
These are types that conform to the Checker interface and can be assigned to a Check for watching service health.
Index ¶
- Constants
- type AlwaysSuccessfulCmd
- type Check
- type Checker
- type ExternalCmd
- type HttpGetCmd
- type Monitor
- func (m *Monitor) AddCheck(check *Check)
- func (m *Monitor) CheckForService(svc *service.Service, disco discovery.Discoverer) *Check
- func (m *Monitor) GetCommandNamed(name string) Checker
- func (m *Monitor) MarkService(svc *service.Service)
- func (m *Monitor) Run(looper director.Looper)
- func (m *Monitor) Services() []service.Service
- func (m *Monitor) Watch(disco discovery.Discoverer, looper director.Looper)
Constants ¶
const ( HEALTHY = 0 SICKLY = iota FAILED = iota UNKNOWN = iota )
const ( FOREVER = -1 WATCH_INTERVAL = 500 * time.Millisecond HEALTH_INTERVAL = 3 * time.Second )
const (
DEFAULT_STATUS_ENDPOINT = "/"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlwaysSuccessfulCmd ¶
type AlwaysSuccessfulCmd struct{}
A Checker that always returns success. Usually used in cases where a service can't actually be health checked for some reason.
type Check ¶
type Check struct { // The ID of this check ID string // The most recent status of this check Status int // The number of runs it has been in failed state Count int // The maximum number before we declare that it failed MaxCount int // String describing the kind of check Type string // The arguments to pass to the Checker Args string // The Checker to run to validate this Command Checker // The last recorded error on this check LastError error }
A Check defines some information about how to talk to the service to determine health. Each Check has a Command that is used to actually do the work. The command is invoked each interval and passed the arguments stored in the Check. The default Check type is an HttpGetCmd and the Args must be the URL to pass to the check.
func (*Check) ServiceStatus ¶
func (*Check) UpdateStatus ¶
UpdateStatus take the status integer and error and applies them to the status of the current Check.
type ExternalCmd ¶
type ExternalCmd struct{}
A Checker that works with Nagios checks or other simple external tools. It expects a 0 exit code from the command that was run. Anything else is considered to be SICKLY. The command is passed as the args to the Run method. The command will be executed without a shell wrapper to keep the call as lean as possible in the majority case. If you need a shell you must invoke it yourself.
type HttpGetCmd ¶
type HttpGetCmd struct{}
A Checker that makes an HTTP get call and expects to get a 200-299 back as success. Anything else is considered a failure. The URL to hit is passed as the args to the Run method.
type Monitor ¶
type Monitor struct { Checks map[string]*Check CheckInterval time.Duration DefaultCheckHost string DiscoveryFn func() []service.Service DefaultCheckEndpoint string sync.RWMutex }
The Monitor is responsible for managing and running Checks. It has a fixed check interval that is used for all checks. Access must be synchronized so direct access to struct members is possible but requires use of the RWMutex.
func NewMonitor ¶
NewMonitor returns a properly configured default configuration of a Monitor.
func (*Monitor) CheckForService ¶
CheckForService returns a Check that has been properly configured for this particular service.
func (*Monitor) GetCommandNamed ¶
func (*Monitor) MarkService ¶
MarkService takes a service and mark its Status appropriately based on the current check we have configured.
func (*Monitor) Run ¶
func (m *Monitor) Run(looper director.Looper)
Run runs the main monitoring loop. The looper controls the actual run behavior.
func (*Monitor) Watch ¶
func (m *Monitor) Watch(disco discovery.Discoverer, looper director.Looper)
Watch loops over a list of services and adds checks for services we don't already know about. It then removes any checks for services which have gone away. All services are expected to be local to this node.