monitor

package
v0.0.0-...-2af547a Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: AGPL-3.0 Imports: 13 Imported by: 2

Documentation

Overview

Package monitor contains mechanisms for monitorring remote services

Index

Constants

View Source
const DuplicateServiceRegistrationError = errors.New(
	"A service with this name has already been registered",
)

DuplicateServiceRegistrationError indicates that a service with that name has already been registered to this monitor.

View Source
const UnknownServiceError = errors.New(
	"No service has been registered with the requested name",
)

UnknownServiceError indicates that no service with the given name has been registered.

Variables

This section is empty.

Functions

func LoadPlugin

func LoadPlugin()

LoadPlugin being called forces the package to be loaded in order to ensure that the resource types are registered during the package's Init.

Types

type MinMonitor

type MinMonitor struct {
	// contains filtered or unexported fields
}

MinMonitor is a minimal service monitor not intended to be used in production. Named services will have an up status cached for a time, while a down status will never be cached. It is possible to explicitly set a service as being up (which will be cached as with a normal probe). It is also possible to explicitly re-probe a service regardless of the status of the cache.

func NewMinMonitor

func NewMinMonitor() *MinMonitor

NewMinMonitor constructs a new MinMonitor.

func (*MinMonitor) Add

func (monitor *MinMonitor) Add(
	name string,
	service *MinMonitorredService,
) (err error)

Add adds a named service to the monitor. The named service is associated with a specific protocol (i.e. TCP, UDP) on a specific port at a specific address. A grace period can be used to keep this monitor from unnecessarily overwhelming the service by allowing an up status to be cached for a time. This function also allows the initial probe to either begin immediately or to be deferred until the first status request.

At this time, it is suggested that only TCP services be probed as the current version of MinMonitor only checks to see that net.Dial() does not fail, which would not be enough information to make a determination of the status of a service that communicates over UDP. As the inability to interact beyond an attempt to open a connection is a handicap in determining even the status of some TCP-based services, future monitor implementations (including any intended to be used in a production environment) should allow service status to be determined by some amount of specified interaction (perhaps involving regular expressions or callback functions).

func (*MinMonitor) NewMinMonitorFilter

func (monitor *MinMonitor) NewMinMonitorFilter(
	name string,
) (http.Handler, error)

NewMinMonitorFilter produces an http.Handler for a given named service. This handler will forward to the service if it is up, otherwise it will display an error page to the requester. There are also optional triggers which would be run if the service is down (presumably to bring it up), or if the service is already up, or in either case, respectively.

func (*MinMonitor) Reprobe

func (monitor *MinMonitor) Reprobe(name string) (up bool, err error)

Reprobe forces the status of the named service to be checked immediately without regard to a possible previously cached up status. The result of this probe will automatically be cached by the monitor.

func (*MinMonitor) SetStatusUp

func (monitor *MinMonitor) SetStatusUp(name string) (err error)

SetStatusUp explicitly sets the status of a named service as being up. This up status will be cached just as if it were the result of a normal probe.

func (*MinMonitor) Status

func (monitor *MinMonitor) Status(name string) (up bool, err error)

Status returns true if the status of the named service is currently believed to be up. The service could have its status reported as being up if a brand new probe of the service indicates that the service is indeed up, or if a recent probe indicated that the service was up (specifically if the most recent probe indicated that the service was up and that probe was within a grace period that was specified when the service was registered), or if the status of the service was explicitly set as being up within that same grace period (and no other forced re-probe has occurred since this forced status up assignment). However, if the status of the service is reported as being down, then it necessarily means that a probe has just occurred and the service was unable to be reached.

type MinMonitorredService

type MinMonitorredService struct {
	URL         *url.URL
	GracePeriod time.Duration
	OnDown      trigger.Triggerrer
	OnUp        trigger.Triggerrer
	Always      trigger.Triggerrer
	// contains filtered or unexported fields
}

MinMonitorredService holds the information for a single service definition.

func NewMinMonitorredService

func NewMinMonitorredService(
	u *url.URL,
	gracePeriod time.Duration,
	onDown trigger.Triggerrer,
	onUp trigger.Triggerrer,
	always trigger.Triggerrer,
) (service *MinMonitorredService, err error)

NewMinMonitorredService creates an initialized MinMonitorredService.

func (*MinMonitorredService) Reprobe

func (s *MinMonitorredService) Reprobe() (up bool, err error)

Reprobe forces the status of the service to be checked immediately without regard to a possible previously cached up status. The result of this probe will automatically be cached by the monitor.

func (*MinMonitorredService) ServeHTTP

func (s *MinMonitorredService) ServeHTTP(
	w http.ResponseWriter,
	req *http.Request,
)

func (*MinMonitorredService) SetStatusUp

func (s *MinMonitorredService) SetStatusUp() error

SetStatusUp explicitly sets the status of the service as being up. This up status will be cached just as if it were the result of a normal probe.

func (*MinMonitorredService) Status

func (s *MinMonitorredService) Status() (up bool, err error)

Status returns true if the status of the service is currently believed to be up. The service could have its status reported as being up if a brand new probe of the service indicates that the service is indeed up, or if a recent probe indicated that the service was up (specifically if the most recent probe indicated that the service was up and that probe was within a grace period that was specified when the service was registered), or if the status of the service was explicitly set as being up within that same grace period (and no other forced re-probe has occurred since this forced status up assignment). However, if the status of the service is reported as being down, then it necessarily means that a probe has just occurred and the service was unable to be reached.

func (*MinMonitorredService) UnmarshalJSON

func (s *MinMonitorredService) UnmarshalJSON(data []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

Jump to

Keyboard shortcuts

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