2019-08-06 17:53:14 +01:00
|
|
|
// Package monitor monitors service health
|
|
|
|
package monitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
StatusUnknown StatusCode = iota
|
|
|
|
StatusRunning
|
|
|
|
StatusFailed
|
|
|
|
)
|
|
|
|
|
|
|
|
type StatusCode int
|
|
|
|
|
|
|
|
// Monitor monitors a service and reaps dead instances
|
|
|
|
type Monitor interface {
|
2019-08-06 19:02:57 +01:00
|
|
|
// Reap a service and stop monitoring
|
|
|
|
Reap(service string) error
|
2019-09-20 17:55:02 +01:00
|
|
|
// Check the status of the service now
|
|
|
|
Check(service string) error
|
2019-08-06 17:53:14 +01:00
|
|
|
// Status of the service
|
|
|
|
Status(service string) (Status, error)
|
|
|
|
// Watch starts watching the service
|
|
|
|
Watch(service string) error
|
2019-08-06 19:02:57 +01:00
|
|
|
// Run the monitor to watch all services
|
|
|
|
Run() error
|
2019-08-06 17:53:14 +01:00
|
|
|
// Stop monitoring
|
|
|
|
Stop() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Status struct {
|
|
|
|
Code StatusCode
|
|
|
|
Info string
|
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrNotWatching = errors.New("not watching")
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewMonitor returns a new monitor
|
|
|
|
func NewMonitor(opts ...Option) Monitor {
|
|
|
|
return newMonitor(opts...)
|
|
|
|
}
|