types

package
v1.10.13 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgMonitorCfg
	ErrorValidatorError
)

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig(indent string) []byte

func SetDefaultConfig

func SetDefaultConfig(cfg []byte)

Types

type Config

type Config struct {
	// Name define the name of the monitor
	Name string `json:"name" yaml:"name" toml:"name" mapstructure:"name"`

	// CheckTimeout define the timeout use for healthcheck. Default is 5 second.
	CheckTimeout time.Duration `json:"check-timeout" yaml:"check-timeout" toml:"check-timeout" mapstructure:"check-timeout"`

	// IntervalCheck define the time waiting between 2 healthcheck. Default is 5 second.
	IntervalCheck time.Duration `json:"interval-check" yaml:"interval-check" toml:"interval-check" mapstructure:"interval-check"`

	// IntervalFall define the time waiting between 2 healthcheck when last check is KO. Default is 5 second.
	IntervalFall time.Duration `json:"interval-fall" yaml:"interval-fall" toml:"interval-fall" mapstructure:"interval-down"`

	// IntervalRise define the time waiting between 2 healthcheck when status is KO or Warn but last check is OK. Default is 5 second.
	IntervalRise time.Duration `json:"interval-rise" yaml:"interval-rise" toml:"interval-rise" mapstructure:"interval-rise"`

	// FallCountKO define the number of KO before considerate the component as down.
	FallCountKO uint8 `json:"fall-count-ko" yaml:"fall-count-ko" toml:"fall-count-ko" mapstructure:"fall-count-ko"`

	// FallCountWarn define the number of KO before considerate the component as warn.
	FallCountWarn uint8 `json:"fall-count-warn" yaml:"fall-count-warn" toml:"fall-count-warn" mapstructure:"fall-count-warn"`

	// RiseCountKO define the number of OK when status is KO before considerate the component as up.
	RiseCountKO uint8 `json:"rise-count-ko" yaml:"rise-count-ko" toml:"rise-count-ko" mapstructure:"rise-count-ko"`

	// RiseCountWarn define the number of OK when status is Warn before considerate the component as up.
	RiseCountWarn uint8 `json:"rise-count-warn" yaml:"rise-count-warn" toml:"rise-count-warn" mapstructure:"rise-count-warn"`

	// Logger define the logger options for current monitor log
	Logger liblog.Options `json:"logger" yaml:"logger" toml:"logger" mapstructure:"logger"`
}

func (Config) Clone

func (o Config) Clone() Config

func (Config) Validate

func (o Config) Validate() liberr.Error

type FuncPool

type FuncPool func() Pool

type HealthCheck

type HealthCheck func(ctx context.Context) error

type Info

type Info interface {
	encoding.TextMarshaler
	json.Marshaler

	Name() string
	Info() map[string]interface{}
}

type Monitor

type Monitor interface {
	MonitorInfo
	MonitorStatus
	MonitorMetrics
	libsrv.Server

	// SetConfig is used to set or update config of the monitor
	SetConfig(ctx libctx.FuncContext, cfg Config) liberr.Error

	// RegisterLoggerDefault is used to define the default logger.
	// Default logger can be used to extend options logger from it
	RegisterLoggerDefault(fct liblog.FuncLog)

	// GetConfig is used to retrieve config of the monitor
	GetConfig() Config

	// SetHealthCheck is used to set or update the healthcheck func
	SetHealthCheck(fct HealthCheck)

	// GetHealthCheck is used to retrieve the healthcheck func
	GetHealthCheck() HealthCheck

	// Clone is used to clone monitor to another standalone instance
	Clone(ctx context.Context) (Monitor, liberr.Error)
}

type MonitorInfo

type MonitorInfo interface {
	InfoGet() Info
	InfoUpd(inf Info)
	InfoName() string
	InfoMap() map[string]interface{}
}

type MonitorMetrics

type MonitorMetrics interface {
	RegisterMetricsName(names ...string)
	RegisterMetricsAddName(names ...string)
	RegisterCollectMetrics(fct libprm.FuncCollectMetrics)

	CollectLatency() time.Duration
	CollectUpTime() time.Duration
	CollectDownTime() time.Duration
	CollectRiseTime() time.Duration
	CollectFallTime() time.Duration
	CollectStatus() (sts monsts.Status, rise bool, fall bool)
}

type MonitorStatus

type MonitorStatus interface {
	encoding.TextMarshaler
	json.Marshaler

	// Name return the name of the monitor.
	Name() string

	// Status return the last status (OK / Warn / KO).
	Status() monsts.Status

	// Message return the last error, warning, message of the last status
	Message() string

	// IsRise return true if rising status from KO or Warn
	IsRise() bool

	// IsFall return true if falling status to KO or Warn
	IsFall() bool

	// Latency return the last check's latency
	Latency() time.Duration

	// Uptime return the total duration of uptime (OK status)
	Uptime() time.Duration

	// Downtime return the total duration of downtime (KO status)
	Downtime() time.Duration
}

type Pool

type Pool interface {
	PoolStatus

	MonitorAdd(mon Monitor) error
	MonitorGet(name string) Monitor
	MonitorSet(mon Monitor) error
	MonitorDel(name string)
	MonitorList() []string
	MonitorWalk(fct func(name string, val Monitor) bool, validName ...string)
}

type PoolStatus

type PoolStatus interface {
	encoding.TextMarshaler
	json.Marshaler
}

Jump to

Keyboard shortcuts

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