Documentation
¶
Index ¶
- func CheckIfMonitorRegistered(name string) bool
- func GetRegisteredMonitorNames() []string
- func RegisterMonitor(monitorType types.MonitorType, ...) error
- type BaseMonitor
- func (m *BaseMonitor) GetDescription() string
- func (m *BaseMonitor) GetGroup() string
- func (m *BaseMonitor) GetInterval() time.Duration
- func (m *BaseMonitor) GetLogger() Logger
- func (m *BaseMonitor) GetName() MonitorName
- func (m *BaseMonitor) GetState() *State
- func (m *BaseMonitor) GetTimeOut() time.Duration
- func (m *BaseMonitor) GetType() types.MonitorType
- func (m *BaseMonitor) HandleFailure(err error) error
- func (m *BaseMonitor) Initialize() error
- func (m *BaseMonitor) IsEnabled() bool
- func (m *BaseMonitor) ResetNotifyLimiter()
- func (m *BaseMonitor) Run(ctx context.Context) error
- func (m *BaseMonitor) SetDescription(description string)
- func (m *BaseMonitor) SetEnablePrometheusMetrics(enableMetrics bool)
- func (m *BaseMonitor) SetEnabled(enabled bool)
- func (m *BaseMonitor) SetGroup(group string)
- func (m *BaseMonitor) SetInterval(interval time.Duration)
- func (m *BaseMonitor) SetJitterFactor(jitterFactor int)
- func (m *BaseMonitor) SetLogger(logger Logger)
- func (m *BaseMonitor) SetMaxConcurrentRequests(maxConcurrentRequests int)
- func (m *BaseMonitor) SetMaxRetries(maxRetries int)
- func (m *BaseMonitor) SetName(name MonitorName)
- func (m *BaseMonitor) SetNotifyRateLimit(notifyRateLimit time.Duration)
- func (m *BaseMonitor) SetProcess(p MonitorProcess)
- func (m *BaseMonitor) SetTimeOut(timeOut time.Duration)
- func (m *BaseMonitor) SetType(monitorType types.MonitorType)
- func (m *BaseMonitor) Stop()
- type JSONBaseConfig
- type Logger
- type Monitor
- type MonitorName
- type MonitorProcess
- type NotificationBody
- func (n *NotificationBody) GetEndPoint() string
- func (n *NotificationBody) GetError() error
- func (n *NotificationBody) GetErrorString() string
- func (n *NotificationBody) GetName() MonitorName
- func (n *NotificationBody) GetNameString() string
- func (n *NotificationBody) GetStatus() StateStatus
- func (n *NotificationBody) GetStatusString() string
- func (n *NotificationBody) GetStatusWithIcon() string
- func (n *NotificationBody) GetTime() time.Time
- func (n *NotificationBody) GetType() types.MonitorType
- func (n *NotificationBody) GetTypeString() string
- type State
- func (s *State) Get() *State
- func (s *State) GetCurrent() StateStatus
- func (s *State) GetError() error
- func (s *State) GetErrorString() string
- func (s *State) GetPrevious() StateStatus
- func (s *State) GetStateChangeTime() time.Time
- func (s *State) Init(current StateStatus, previous StateStatus, stateCHangeTime time.Time)
- func (s *State) IsCurrentStateAFinalState() bool
- func (s *State) IsCurrentStatusDOWN() bool
- func (s *State) IsCurrentStatusUP() bool
- func (s *State) IsPreviousStateAFinalState() bool
- func (s *State) IsPreviousStatusDOWN() bool
- func (s *State) IsPreviousStatusUP() bool
- func (s *State) Subscribe(id string, subscriber func(s *State))
- func (s *State) UnSubscribe(id string)
- func (s *State) Update(newState StateStatus, err error) error
- type StateStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckIfMonitorRegistered ¶
CheckIfMonitorRegistered checks if a monitor is registered by name.
func GetRegisteredMonitorNames ¶
func GetRegisteredMonitorNames() []string
GetRegisteredMonitorNames returns a slice of strings containing the names of all the registered monitors
func RegisterMonitor ¶
func RegisterMonitor(monitorType types.MonitorType, initFunc func(configBody []byte, logger Logger, jitterFactor int, prometheusMetricsEnabled bool) (Monitor, error)) error
RegisterMonitor takes a monitor type and a function that returns a monitor and adds it to a map of monitors
Types ¶
type BaseMonitor ¶
type BaseMonitor struct {
Name MonitorName
Type types.MonitorType
Description string
Group string
Logger Logger
Interval time.Duration
TimeOut time.Duration
JitterFactor int
Enabled bool
StopChannel chan bool
Semaphore *semaphore.Weighted
InitOnce sync.Once
NotifyRate rate.Limit
PrometheusMetricsEnabled bool
PrometheusMetrics *metrics.PrometheusMetrics
NotifyLimiter *rate.Limiter
State *State
MaxConcurrentRequests int
MaxRetries int
RetryCounter int
Process func() error
}
BaseMonitor is the base monitor struct that all monitors should be composed of
func (*BaseMonitor) GetDescription ¶
func (m *BaseMonitor) GetDescription() string
GetDescription returns the description of the monitor
func (*BaseMonitor) GetGroup ¶
func (m *BaseMonitor) GetGroup() string
GetGroup returns the group for the monitor
func (*BaseMonitor) GetInterval ¶
func (m *BaseMonitor) GetInterval() time.Duration
GetInterval returns the interval for the monitor
func (*BaseMonitor) GetLogger ¶
func (m *BaseMonitor) GetLogger() Logger
GetLogger returns the logger for the monitor
func (*BaseMonitor) GetName ¶
func (m *BaseMonitor) GetName() MonitorName
GetName returns the name of the monitor
func (*BaseMonitor) GetState ¶
func (m *BaseMonitor) GetState() *State
GetState returns the state of the monitor
func (*BaseMonitor) GetTimeOut ¶
func (m *BaseMonitor) GetTimeOut() time.Duration
GetTimeOut returns the timeout for the monitor
func (*BaseMonitor) GetType ¶
func (m *BaseMonitor) GetType() types.MonitorType
GetType returns the type of the monitor
func (*BaseMonitor) HandleFailure ¶
func (m *BaseMonitor) HandleFailure(err error) error
HandleFailure handles a failure
func (*BaseMonitor) Initialize ¶
func (m *BaseMonitor) Initialize() error
Initialize the base monitor Call this method in all Init() methods of all monitors that are composed of BaseMonitor
func (*BaseMonitor) IsEnabled ¶
func (m *BaseMonitor) IsEnabled() bool
IsEnabled returns the enabled flag for the monitor
func (*BaseMonitor) ResetNotifyLimiter ¶
func (m *BaseMonitor) ResetNotifyLimiter()
ResetNotifyLimiter resets the notify limiter for the monitor
func (*BaseMonitor) Run ¶
func (m *BaseMonitor) Run(ctx context.Context) error
Run starts the monitor
func (*BaseMonitor) SetDescription ¶
func (m *BaseMonitor) SetDescription(description string)
SetDescription sets the description of the monitor
func (*BaseMonitor) SetEnablePrometheusMetrics ¶
func (m *BaseMonitor) SetEnablePrometheusMetrics(enableMetrics bool)
SetEnablePrometheusMetrics sets the enable metrics flag for the monitor
func (*BaseMonitor) SetEnabled ¶
func (m *BaseMonitor) SetEnabled(enabled bool)
SetEnabled sets the enabled flag for the monitor
func (*BaseMonitor) SetGroup ¶
func (m *BaseMonitor) SetGroup(group string)
SetGroup sets the group for the monitor
func (*BaseMonitor) SetInterval ¶
func (m *BaseMonitor) SetInterval(interval time.Duration)
SetInterval sets the interval for the monitor
func (*BaseMonitor) SetJitterFactor ¶
func (m *BaseMonitor) SetJitterFactor(jitterFactor int)
SetJitterFactor sets the jitter factor for the monitor
func (*BaseMonitor) SetLogger ¶
func (m *BaseMonitor) SetLogger(logger Logger)
SetLogger sets the logger for the monitor
func (*BaseMonitor) SetMaxConcurrentRequests ¶
func (m *BaseMonitor) SetMaxConcurrentRequests(maxConcurrentRequests int)
SetMaxConcurrentRequests sets the max concurrent requests for the monitor
func (*BaseMonitor) SetMaxRetries ¶
func (m *BaseMonitor) SetMaxRetries(maxRetries int)
SetMaxRetries sets the max retries for the monitor
func (*BaseMonitor) SetName ¶
func (m *BaseMonitor) SetName(name MonitorName)
SetName sets the name of the monitor
func (*BaseMonitor) SetNotifyRateLimit ¶
func (m *BaseMonitor) SetNotifyRateLimit(notifyRateLimit time.Duration)
SetNotifyRateLimit sets the notify rate limit for the monitor
func (*BaseMonitor) SetProcess ¶
func (m *BaseMonitor) SetProcess(p MonitorProcess)
SetProcess is the main process for the monitor
func (*BaseMonitor) SetTimeOut ¶
func (m *BaseMonitor) SetTimeOut(timeOut time.Duration)
SetTimeOut sets the timeout for the monitor
func (*BaseMonitor) SetType ¶
func (m *BaseMonitor) SetType(monitorType types.MonitorType)
SetType sets the type of the monitor
type JSONBaseConfig ¶
type JSONBaseConfig struct {
Name MonitorName `json:"name"`
Description string `json:"description"`
Group string `json:"group"`
Enabled bool `json:"enabled"`
Interval utils.Duration `json:"interval"`
Timeout utils.Duration `json:"timeout"`
MaxConcurrentRequests int `json:"maxConcurrentRequests"`
MaxRetries int `json:"maxRetries"`
NotifyRateLimit utils.Duration `json:"notifyRateLimit"`
}
JSONBaseConfig is the base JSON config for all monitors
func (*JSONBaseConfig) Validate ¶
func (m *JSONBaseConfig) Validate() error
Validate validates the config for the Port monitor
type Logger ¶
type Logger interface {
// Info logs an info message
Info(msg ...interface{})
// Infof logs an info formatted string
Infof(format string, a ...interface{})
// Debug logs an debug message
Debug(msg ...interface{})
// Debugf logs an debug formatted string
Debugf(format string, a ...interface{})
// Warn logs a warn message
Warn(msg ...interface{})
// Warnf logs a warn message
Warnf(format string, v ...interface{})
// Error logs an error with the message
Error(err error, msg ...interface{})
// Errorf logs an error with the formatted string
Errorf(err error, format string, a ...interface{})
// GetLevel returns the current log level
GetLevel() log.LogLevel
// SetLevel sets the log level
SetLevel(level log.LogLevel)
}
Logger is the interface of the logger for the monitor
type Monitor ¶
type Monitor interface {
// Init initializes the monitor
Init() error
// Run starts the monitor
Run(ctx context.Context) error
// SetProcess sets the process for the monitor
// Have to use this method to pass Process function to embedded struct
SetProcess(p MonitorProcess)
// Stop stops the monitor
Stop()
// GetName returns the name of the monitor
GetName() MonitorName
// SetName sets the name of the monitor
SetName(name MonitorName)
// Group returns the group of the monitor
GetGroup() string
// SetGroup sets the group of the monitor
SetGroup(group string)
// GetDescription returns the description of the monitor
GetDescription() string
// SetDescription sets the description of the monitor
SetDescription(description string)
// SetType sets the type of the monitor
SetType(monitorType types.MonitorType)
// GetType returns the type of the monitor
GetType() types.MonitorType
// SetConfig sets the config for the monitor
SetConfig(config interface{}) error
// GetConfig returns the config for the monitor
GetConfig() interface{}
// SetLogger sets the logger for the monitor
SetLogger(logger Logger)
// GetLogger returns the logger for the monitor
GetLogger() Logger
// SetInterval sets the interval for the monitor
SetInterval(interval time.Duration)
// GetInterval returns the interval for the monitor
GetInterval() time.Duration
// SetEnabled sets the enabled flag for the monitor
SetEnabled(enabled bool)
// SetJitterFactor sets the jitter factor for the monitor
SetJitterFactor(jitterFactor int)
// IsEnabled returns the enabled flag for the monitor
IsEnabled() bool
// SetMaxConcurrentRequests sets the max concurrent requests for the monitor
SetMaxConcurrentRequests(maxConcurrentRequests int)
// SetTimeOut sets the timeout for the monitor
SetTimeOut(timeOut time.Duration)
// GetTimeOut returns the timeout for the monitor
GetTimeOut() time.Duration
// SetMaxRetries sets the max retries for the monitor
SetMaxRetries(maxRetries int)
// SetNotifyRateLimit sets the notify rate limit for the monitor
SetNotifyRateLimit(notifyRateLimit time.Duration)
// GetState returns the state of the monitor
GetState() *State
// SetEnablePrometheusMetrics sets the metrics enabled flag for the monitor
SetEnablePrometheusMetrics(enablePrometheusMetrics bool)
// GetNotificationBody returns the error notification body
GetNotificationBody(state *State) *NotificationBody
}
Monitor is an interface that all monoitors must implement
type MonitorName ¶
type MonitorName string
MonitorName is a string that represents the name of the monitor
func (MonitorName) String ¶
func (m MonitorName) String() string
type MonitorProcess ¶
type MonitorProcess func() error
MonitorProcess is the process for the monitor
type NotificationBody ¶
type NotificationBody struct {
Name MonitorName `json:"name"`
Type types.MonitorType `json:"type"`
EndPoint string `json:"endPoint"`
Time time.Time `json:"time"`
Status StateStatus `json:"status"`
Error error `json:"error,omitempty"`
}
NotificationBody is the body of the notification
func (*NotificationBody) GetEndPoint ¶
func (n *NotificationBody) GetEndPoint() string
GetEndPoint returns the end point for the state from NotificationBody
func (*NotificationBody) GetError ¶
func (n *NotificationBody) GetError() error
GetError returns the error for the state from NotificationBody
func (*NotificationBody) GetErrorString ¶
func (n *NotificationBody) GetErrorString() string
GetErrorString returns the error string for the state from NotificationBody
func (*NotificationBody) GetName ¶
func (n *NotificationBody) GetName() MonitorName
GetName returns the name of the monitor from NotificationBody
func (*NotificationBody) GetNameString ¶
func (n *NotificationBody) GetNameString() string
GetNameString returns the name of the monitor from NotificationBody
func (*NotificationBody) GetStatus ¶
func (n *NotificationBody) GetStatus() StateStatus
GetStatus returns the status of the state from NotificationBody
func (*NotificationBody) GetStatusString ¶
func (n *NotificationBody) GetStatusString() string
GetStatusString returns the status string for the state from NotificationBody
func (*NotificationBody) GetStatusWithIcon ¶
func (n *NotificationBody) GetStatusWithIcon() string
GetStatusWithIcon returns the current state with icon from NotificationBody
func (*NotificationBody) GetTime ¶
func (n *NotificationBody) GetTime() time.Time
GetTime returns the time of the state change from NotificationBody
func (*NotificationBody) GetType ¶
func (n *NotificationBody) GetType() types.MonitorType
GetType returns the type of the monitor from NotificationBody
func (*NotificationBody) GetTypeString ¶
func (n *NotificationBody) GetTypeString() string
GetTypeString returns the type of the monitor from NotificationBody
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the state of the monitor
func (*State) GetCurrent ¶
func (s *State) GetCurrent() StateStatus
GetCurrent returns the current state
func (*State) GetErrorString ¶
GetErrorString returns the error string for the state
func (*State) GetPrevious ¶
func (s *State) GetPrevious() StateStatus
GetPrevious returns the previous state
func (*State) GetStateChangeTime ¶
GetStateChangeTime returns the state change time
func (*State) Init ¶
func (s *State) Init(current StateStatus, previous StateStatus, stateCHangeTime time.Time)
Init initializes the state
func (*State) IsCurrentStateAFinalState ¶
IsCurrentStateAFinalState returns true if the current state is a final state
func (*State) IsCurrentStatusDOWN ¶
IsCurrentStatusDOWN returns if the current status down
func (*State) IsCurrentStatusUP ¶
IsCurrentStatusUP returns if the current status up
func (*State) IsPreviousStateAFinalState ¶
IsPreviousStateAFinalState returns true if the previous state is a final state
func (*State) IsPreviousStatusDOWN ¶
IsPreviousStatusDOWN returns if the previous status error
func (*State) IsPreviousStatusUP ¶
IsPreviousStatusUP returns if the previous status ok
func (*State) UnSubscribe ¶
UnSubscribe unsubscribes the subscriber
type StateStatus ¶
type StateStatus string
StateStatus is the state of the monitor
const ( // StateStatusUP indicates that the monitor is in a healthy state StateStatusUP StateStatus = "UP" // StateStatusDOWN indicates that the monitor is in a down state StateStatusDOWN StateStatus = "DOWN" // StateStatusINIT indicates that the monitor is in a initializing state StateStatusINIT StateStatus = "INIT" // StateStatusSTARTING indicates that the monitor is in a initializing state StateStatusSTARTING StateStatus = "STARTING" )
func (StateStatus) String ¶
func (s StateStatus) String() string
String returns the string representation of the state