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
- 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
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 ¶
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 liveliness checks to ensure that lnd has access to all critical resources.
func NewMonitor ¶
NewMonitor returns a monitor with the provided config.
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.