healthcheck

package
v0.0.0-...-46f88e6 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: ISC, MIT Imports: 7 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func AvailableDiskSpace

func AvailableDiskSpace(path string) (uint64, er.R)

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

func AvailableDiskSpaceRatio

func AvailableDiskSpaceRatio(path string) (float64, er.R)

AvailableDiskSpaceRatio returns ratio of available disk space to total capacity.

func CreateCheck

func CreateCheck(checkFunc func() er.R) func() chan er.R

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.

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() er.R

Start launches the goroutines required to run our monitor.

func (*Monitor) Stop

func (m *Monitor) Stop() er.R

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 er.R

	// 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() er.R, 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