gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/monitor/monitor.go (about)

     1  // Package monitor monitors service health
     2  package monitor
     3  
     4  import (
     5  	"errors"
     6  )
     7  
     8  const (
     9  	StatusUnknown StatusCode = iota
    10  	StatusRunning
    11  	StatusFailed
    12  )
    13  
    14  type StatusCode int
    15  
    16  // Monitor monitors a service and reaps dead instances
    17  type Monitor interface {
    18  	// Reap a service and stop monitoring
    19  	Reap(service string) error
    20  	// Check the status of the service now
    21  	Check(service string) error
    22  	// Status of the service
    23  	Status(service string) (Status, error)
    24  	// Watch starts watching the service
    25  	Watch(service string) error
    26  	// Run the monitor to watch all services
    27  	Run() error
    28  	// Stop monitoring
    29  	Stop() error
    30  }
    31  
    32  type Status struct {
    33  	Code  StatusCode
    34  	Info  string
    35  	Error string
    36  }
    37  
    38  var (
    39  	ErrNotWatching = errors.New("not watching")
    40  )
    41  
    42  // NewMonitor returns a new monitor
    43  func NewMonitor(opts ...Option) Monitor {
    44  	return newMonitor(opts...)
    45  }