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
- func AvailableDiskSpace(path string) (uint64, error)
- func AvailableDiskSpaceRatio(path string) (float64, error)
- func CheckTorServiceStatus(tc *tor.Controller, createService func() error) error
- func CreateCheck(checkFunc func() error) func() chan error
- func DisableLog()
- func UseLogger(logger btclog.Logger)
- type Config
- type Monitor
- type Observation
- type ObservationOption
Constants ¶
const Subsystem = "HLCK"
Subsystem defines the logging code for this subsystem.
Variables ¶
This section is empty.
Functions ¶
func AvailableDiskSpace ¶
AvailableDiskSpace returns the available disk space in bytes of the given file system.
func AvailableDiskSpaceRatio ¶
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 ¶
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.
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 ¶
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.
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) Debugf ¶ added in v1.2.5
func (o *Observation) Debugf(format string, params ...interface{})
Debugf logs a debug message for an observation prefixed with the health check name.
func (*Observation) Infof ¶ added in v1.2.5
func (o *Observation) Infof(format string, params ...interface{})
Infof logs an info message for an observation prefixed with the health check name.
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.