healthcheck

package
v0.12.1-beta-branch Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 9 Imported by: 6

Documentation

Overview

Package healthcheck contains a monitor which takes a set of liveliness checks which it periodically checks. If a check fails after its configured number of allowed call attempts, the monitor will send a request to shutdown using the function is is provided in its config. Checks are dispatched in their own goroutines so that they do not block each other.

Index

Constants

View Source
const Subsystem = "HLCK"

Subsystem defines the logging code for this subsystem.

Variables

This section is empty.

Functions

func AvailableDiskSpace

func AvailableDiskSpace(path string) (uint64, error)

AvailableDiskSpace returns the available disk space in bytes of the given file system.

func AvailableDiskSpaceRatio

func AvailableDiskSpaceRatio(path string) (float64, error)

AvailableDiskSpaceRatio returns ratio of available disk space to total capacity.

func CreateCheck

func CreateCheck(checkFunc func() error) func() chan error

CreateCheck is a helper function that takes a function that produces an error and wraps it in a function that returns its result on an error channel. We do not wait group the goroutine running our checkFunc because we expect to be dealing with health checks that may block; if we wait group them, we may wait forever. Ideally future health checks will allow callers to cancel them early, and we can wait group this.

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type Config

type Config struct {
	// Checks is a set of health checks that assert that lnd has access to
	// critical resources.
	Checks []*Observation

	// Shutdown should be called to request safe shutdown on failure of a
	// health check.
	Shutdown shutdownFunc
}

Config contains configuration settings for our monitor.

type Monitor

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

Monitor periodically checks a series of configured liveliness checks to ensure that lnd has access to all critical resources.

func NewMonitor

func NewMonitor(cfg *Config) *Monitor

NewMonitor returns a monitor with the provided config.

func (*Monitor) Start

func (m *Monitor) Start() error

Start launches the goroutines required to run our monitor.

func (*Monitor) Stop

func (m *Monitor) Stop() error

Stop sends all goroutines the signal to exit and waits for them to exit.

type Observation

type Observation struct {
	// Name describes the health check.
	Name string

	// Check runs the health check itself, returning an error channel that
	// is expected to receive nil or an error.
	Check func() chan error

	// Interval is a ticker which triggers running our check function. This
	// ticker must be started and stopped by the observation.
	Interval ticker.Ticker

	// Attempts is the number of calls we make for a single check before
	// failing.
	Attempts int

	// Timeout is the amount of time we allow our check function to take
	// before we time it out.
	Timeout time.Duration

	// Backoff is the amount of time we back off between retries for failed
	// checks.
	Backoff time.Duration
}

Observation represents a liveliness check that we periodically check.

func NewObservation

func NewObservation(name string, check func() error, interval,
	timeout, backoff time.Duration, attempts int) *Observation

NewObservation creates an observation.

func (*Observation) String

func (o *Observation) String() string

String returns a string representation of an observation.

Jump to

Keyboard shortcuts

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