health

package module
v0.0.0-...-c948a37 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 8 Imported by: 0

README

health

The health-Package contains generic implementations of health monitoring using different protocols (tcp, http for the moment) in go.

License

Licensed under MIT.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHTTPHealthCheckProvider = &HTTPHealthCheckProvider{}

DefaultHTTPHealthCheckProvider holds a http health monitoring provider.

View Source
var DefaultHTTPSHealthCheckProvider = &HTTPHealthCheckProvider{
	HTTPS: true,
}
View Source
var DefaultNoneHealthCheckProvider = &NoneHealthCheckProvider{}

DefaultNoneHealthCheckProvider defines a nop-healthcheck provider which always returns "up".

View Source
var DefaultTCPHealthCheckProvider = &TCPHealthCheckProvider{}

DefaultTCPHealthCheckProvider holds a tcp health monitoring provider.

Functions

This section is empty.

Types

type HTTPHealthCheckProvider

type HTTPHealthCheckProvider struct {
	HTTPS              bool
	InsecureSkipVerify bool
	Path               string
}

HTTPHealthCheckProvider represents a HealthCheckProvider which monitors a http endpoint.

func NewHTTPHealthCheckProvider

func NewHTTPHealthCheckProvider(https bool, insecureSkipVerify bool, path string) *HTTPHealthCheckProvider

func (*HTTPHealthCheckProvider) CheckHealth

func (c *HTTPHealthCheckProvider) CheckHealth(h *HealthCheck) (string, bool)

CheckHealth validates whether the current endpoint is up

type HealthCheck

type HealthCheck struct {
	IP               net.IP
	Port             int
	Provider         HealthCheckProvider
	Healthy          bool
	LastTimeHealthy  time.Time
	LastCheck        time.Time
	LastMessage      string
	PlannedRetention time.Duration
	Retention        time.Duration
	MaxRetention     time.Duration
	MaxResponseTime  time.Duration
}

HealthCheck represents a health monitoring resource

func NewHealthCheck

func NewHealthCheck(
	ip net.IP,
	port int,
	provider HealthCheckProvider,
	plannedRetention time.Duration,
	maxRetention time.Duration,
	maxResponseTime time.Duration,
) *HealthCheck

NewHealthCheck creates a new HealthCheck instance with the specified parameters.

func (*HealthCheck) CheckHealth

func (h *HealthCheck) CheckHealth()

CheckHealth updates the current HealthCheck (e.g. the healthy-property)

func (*HealthCheck) GetAddress

func (h *HealthCheck) GetAddress() string

GetAddress returns the endpoint (i.e. 127.0.0.1:80) of the current HealthCheck.

func (*HealthCheck) Monitor

func (h *HealthCheck) Monitor(stopChan chan struct{}) chan HealthCheckStatus

Monitor starts monitoring the endpoint configured in the HealthCheck.

type HealthCheckProvider

type HealthCheckProvider interface {
	CheckHealth(healthCheck *HealthCheck) (string, bool)
}

HealthCheckProvider defines any implementation of the CheckHealth func

func GetHealthCheckProvider

func GetHealthCheckProvider(name string) (HealthCheckProvider, error)

type HealthCheckStatus

type HealthCheckStatus struct {
	IP        net.IP
	Port      int
	Healthy   bool
	Message   string
	DidChange bool
}

HealthCheckStatus represents the current status of a HealthCheck endpoint.

func (HealthCheckStatus) GetAddress

func (h HealthCheckStatus) GetAddress() string

GetAddress returns the endpoint (i.e. 127.0.0.1:80) of the current HealthCheckStatus.

func (HealthCheckStatus) String

func (s HealthCheckStatus) String() string

String returns a string representation of the current status.

type NoneHealthCheckProvider

type NoneHealthCheckProvider struct {
}

NoneHealthCheckProvider is a dummy provider which does no checking at all and always returns "up"

func (*NoneHealthCheckProvider) CheckHealth

func (c *NoneHealthCheckProvider) CheckHealth(h *HealthCheck) (string, bool)

CheckHealth with the none-provider always returns "up" for the current service.

type TCPHealthCheckProvider

type TCPHealthCheckProvider struct {
}

TCPHealthCheckProvider represents a HealthCheckProvider which monitors a tcp endpoint.

func (*TCPHealthCheckProvider) CheckHealth

func (c *TCPHealthCheckProvider) CheckHealth(h *HealthCheck) (string, bool)

CheckHealth validates whether the current endpoint is up

Jump to

Keyboard shortcuts

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