healthcheck

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 10 Imported by: 4

Documentation

Overview

Package healthcheck contains a monitor which takes a set of liveness 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 CheckTorServiceStatus added in v1.2.0

func CheckTorServiceStatus(tc *tor.Controller,
	createService func() error) error

CheckTorServiceStatus checks whether the onion service is reachable by sending a GETINFO command to the Tor daemon using our tor controller. We will get an EOF or a broken pipe error if the Tor daemon is stopped/restarted as the previously created socket connection is no longer open. In this case, we will attempt a restart on our tor controller. If the tor daemon comes back, a new socket connection will then be created.

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 liveness 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) AddCheck added in v1.2.4

func (m *Monitor) AddCheck(check *Observation) error

AddCheck adds a new healthcheck to our monitor.

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

	// OnSuccess is a callback which will be executed when the healthcheck
	// succeeds. This is optional.
	OnSuccess func()

	// OnFailure is a callback which will be executed when the healthcheck
	// fails. This is optional.
	OnFailure func()
}

Observation represents a liveness check that we periodically check.

func NewObservation

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

NewObservation creates an observation.

func (*Observation) String

func (o *Observation) String() string

String returns a string representation of an observation.

type ObservationOption added in v1.2.4

type ObservationOption func(*Observation)

ObservationOption describes the signature of a functional option that can be used to modify the behaviour of an Observation.

func WithFailureCallback added in v1.2.4

func WithFailureCallback(callback func()) ObservationOption

WithFailureCallback configures an observation with a callback to be fired whenever the health check reaches its failure threshold.

func WithSuccessCallback added in v1.2.4

func WithSuccessCallback(callback func()) ObservationOption

WithSuccessCallback configures an observation with a callback to be fired whenever the health check succeeds.

Jump to

Keyboard shortcuts

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