Documentation
¶
Index ¶
- Variables
- func Run(plugins map[string]PluginLoader, configPath string)
- type Alert
- type AlertDetails
- type Check
- type CheckSettings
- type CheckState
- type CheckTombStone
- type Plugin
- type PluginLoader
- type Plum
- func (p *Plum) AlertsMatching(names []string) []Alert
- func (p *Plum) RaiseAlerts(c *ScheduledCheck, previousState CheckState)
- func (p *Plum) ReadConfig(path string) error
- func (p *Plum) RegisterPlugin(name string, loader PluginLoader)
- func (p *Plum) RegisterPlugins(plugins map[string]PluginLoader)
- func (p *Plum) RestoreState() error
- func (p *Plum) Run()
- func (p *Plum) RunCheck(c *ScheduledCheck)
- func (p *Plum) SaveState() error
- type Result
- type ResultHistory
- type ScheduledCheck
- type TombStone
Constants ¶
This section is empty.
Variables ¶
var DefaultSettings = CheckSettings{ Alerts: []string{"*"}, Interval: time.Second * 30, Timeout: time.Second * 20, GoodThreshold: 2, FailingThreshold: 2, }
Functions ¶
func Run ¶ added in v0.3.0
func Run(plugins map[string]PluginLoader, configPath string)
Run creates a new instance of Plum, registers plugins and loads configuration, and starts the main loop. Lists for interrupt and sigterm signals in order to save state and clean up. It is expected that flag.Parse has been called prior to calling this method.
Types ¶
type Alert ¶
type Alert interface {
// Send dispatches an alert in relation to the given check event.
Send(details AlertDetails) error
// Validate checks the configuration of this alert and returns any errors.
Validate() error
}
Alert defines the method to inform the user of a change to a service - e.g. when it comes up or goes down.
type AlertDetails ¶
type AlertDetails struct {
// Text is a short, pre-generated message describing the alert.
Text string `json:"text"`
// Name is the name of the check that transitioned.
Name string `json:"name"`
// Type is the type of check involved.
Type string `json:"type"`
// Config is the user-supplied parameters to the check.
Config interface{} `json:"config"`
// LastResult is the most recent result that caused the transition.
LastResult *Result `json:"last_result"`
// PreviousState is the state this check was previously in.
PreviousState CheckState `json:"previous_state"`
// NewState is the state this check is now in.
NewState CheckState `json:"new_state"`
}
AlertDetails contains information about a triggered alert
type Check ¶
type Check interface {
// Execute performs the actual check to see if the service is up or not.
// It should block until a result is available or the passed context is cancelled.
Execute(ctx context.Context) Result
// Validate checks the configuration of this check and returns any errors.
Validate() error
}
Check defines the method to see if a service is up or not. The check is persistent - its Execute method will be called repeatedly over the lifetime of the application.
type CheckSettings ¶
type CheckSettings struct {
Alerts []string
Interval time.Duration
Timeout time.Duration
GoodThreshold int `config:"good_threshold"`
FailingThreshold int `config:"failing_threshold"`
}
func (CheckSettings) Copy ¶ added in v0.2.0
func (c CheckSettings) Copy() CheckSettings
type CheckState ¶
type CheckState int
CheckState describes the state of a check.
const ( // StateIndeterminate indicates that it's not clear if the check passed or failed, e.g. it hasn't run yet. StateIndeterminate CheckState = iota // StateGood indicates the service is operating correctly. StateGood // StateFailing indicates a problem with the service. StateFailing )
func (CheckState) MarshalJSON ¶
func (c CheckState) MarshalJSON() ([]byte, error)
func (CheckState) String ¶
func (c CheckState) String() string
String returns an english, lowercase name for the state.
func (*CheckState) UnmarshalJSON ¶ added in v0.3.0
func (c *CheckState) UnmarshalJSON(val []byte) error
type CheckTombStone ¶ added in v0.3.0
type CheckTombStone struct {
LastRun time.Time
Settled bool
State CheckState
History ResultHistory
}
type Plugin ¶
Plugin is the API between plugins and the core. Plugins must provide an exported "Plum()" method in the main package which returns an instance of Plugin.
The Check and Alert funcs should provide new instances of the named type, or nil if such a type does not exist. Exported fields of the checks and alerts will then be populated according to the user's config, and the Validate() func will be called.
type PluginLoader ¶ added in v0.2.0
type Plum ¶
type Plum struct {
Alerts map[string]Alert
Checks []*ScheduledCheck
// contains filtered or unexported fields
}
func (*Plum) AlertsMatching ¶
func (*Plum) RaiseAlerts ¶
func (p *Plum) RaiseAlerts(c *ScheduledCheck, previousState CheckState)
func (*Plum) ReadConfig ¶ added in v0.2.0
func (*Plum) RegisterPlugin ¶ added in v0.2.0
func (p *Plum) RegisterPlugin(name string, loader PluginLoader)
func (*Plum) RegisterPlugins ¶ added in v0.2.0
func (p *Plum) RegisterPlugins(plugins map[string]PluginLoader)
func (*Plum) RestoreState ¶ added in v0.3.0
func (*Plum) RunCheck ¶
func (p *Plum) RunCheck(c *ScheduledCheck)
type Result ¶
type Result struct {
// State gives the current state of the service.
State CheckState `json:"state"`
// Time is the time the check was performed.
Time time.Time `json:"time"`
// Detail is an short, optional explanation of the current state.
Detail string `json:"detail,omitempty"`
}
Result contains information about a check that was performed.
func FailingResult ¶
FailingResult creates a new result indicating the service is in a bad state.
func GoodResult ¶
func GoodResult() Result
GoodResult creates a new result indicating the service is in a good state.
type ResultHistory ¶
type ResultHistory [10]*Result
func (ResultHistory) State ¶
func (h ResultHistory) State(thresholds map[CheckState]int) CheckState
type ScheduledCheck ¶
type ScheduledCheck struct {
Name string
Type string
Config *CheckSettings
Check Check
LastRun time.Time
Scheduled bool
Settled bool
State CheckState
History ResultHistory
}
func (*ScheduledCheck) AddResult ¶
func (c *ScheduledCheck) AddResult(result *Result) ResultHistory
func (*ScheduledCheck) LastResult ¶
func (c *ScheduledCheck) LastResult() *Result
func (*ScheduledCheck) Remaining ¶
func (c *ScheduledCheck) Remaining() time.Duration
type TombStone ¶ added in v0.3.0
type TombStone struct {
Time time.Time
Checks map[string]CheckTombStone
}
func LoadTombStone ¶ added in v0.3.0
func NewTombStone ¶ added in v0.3.0
func NewTombStone(checks []*ScheduledCheck) *TombStone
func (*TombStone) Restore ¶ added in v0.3.0
func (ts *TombStone) Restore(checks []*ScheduledCheck) error