healthy

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

These are types that conform to the Checker interface and can be assigned to a Check for watching service health.

Index

Constants

View Source
const (
	HEALTHY = 0
	SICKLY  = iota
	FAILED  = iota
	UNKNOWN = iota
)
View Source
const (
	FOREVER         = -1
	WATCH_INTERVAL  = 500 * time.Millisecond
	HEALTH_INTERVAL = 3 * time.Second
)
View Source
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.

func (*AlwaysSuccessfulCmd) Run

func (a *AlwaysSuccessfulCmd) Run(args string) (int, error)

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 NewCheck

func NewCheck(id string) *Check

NewCheck returns a properly configured default Check

func (*Check) ServiceStatus

func (check *Check) ServiceStatus() int

func (*Check) UpdateStatus

func (check *Check) UpdateStatus(status int, err error)

UpdateStatus take the status integer and error and applies them to the status of the current Check.

type Checker

type Checker interface {
	Run(args string) (int, error)
}

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.

func (*ExternalCmd) Run

func (e *ExternalCmd) Run(args string) (int, error)

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.

func (*HttpGetCmd) Run

func (h *HttpGetCmd) Run(args string) (int, error)

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

func NewMonitor(defaultCheckHost string, defaultCheckEndpoint string) *Monitor

NewMonitor returns a properly configured default configuration of a Monitor.

func (*Monitor) AddCheck

func (m *Monitor) AddCheck(check *Check)

Add a Check to the list. Handles synchronization.

func (*Monitor) CheckForService

func (m *Monitor) CheckForService(svc *service.Service, disco discovery.Discoverer) *Check

CheckForService returns a Check that has been properly configured for this particular service.

func (*Monitor) GetCommandNamed

func (m *Monitor) GetCommandNamed(name string) Checker

func (*Monitor) MarkService

func (m *Monitor) MarkService(svc *service.Service)

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) Services

func (m *Monitor) Services() []service.Service

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.

Jump to

Keyboard shortcuts

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