mirror of https://github.com/divan/expvarmon.git
Added restart status
This commit is contained in:
parent
672a4f9170
commit
a0ad89e433
|
@ -18,7 +18,8 @@ type Service struct {
|
|||
|
||||
stacks map[VarName]*Stack
|
||||
|
||||
Err error
|
||||
Err error
|
||||
Restarted bool
|
||||
}
|
||||
|
||||
// NewService returns new Service object.
|
||||
|
@ -40,6 +41,10 @@ func NewService(port string, vars []VarName) *Service {
|
|||
func (s *Service) Update(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
expvar, err := FetchExpvar(s.Addr())
|
||||
// check for restart
|
||||
if s.Err != nil && err == nil {
|
||||
s.Restarted = true
|
||||
}
|
||||
s.Err = err
|
||||
|
||||
// Update Cmdline & Name only once
|
||||
|
@ -57,6 +62,7 @@ func (s *Service) Update(wg *sync.WaitGroup) {
|
|||
for name, stack := range s.stacks {
|
||||
value, err := expvar.GetValue(name.ToSlice()...)
|
||||
if err != nil {
|
||||
stack.Push(nil)
|
||||
continue
|
||||
}
|
||||
v := guessValue(value)
|
||||
|
|
8
ui.go
8
ui.go
|
@ -123,7 +123,7 @@ func (t *TermUI) Init(data UIData) error {
|
|||
// Update updates UI widgets from UIData.
|
||||
func (t *TermUI) Update(data UIData) {
|
||||
t.Title.Text = fmt.Sprintf("monitoring %d services every %v, press q to quit", len(data.Services), *interval)
|
||||
t.Status.Text = fmt.Sprintf("Last update: %v", data.LastTimestamp.Format("15:04:05 02/Jan/06"))
|
||||
t.Status.Text = fmt.Sprintf("Last update: %v", data.LastTimestamp.Format(time.Stamp))
|
||||
|
||||
// List with service names
|
||||
var services []string
|
||||
|
@ -167,7 +167,11 @@ func (t *TermUI) Close() {
|
|||
// StatusLine returns status line for service with it's name and status.
|
||||
func StatusLine(s *Service) string {
|
||||
if s.Err != nil {
|
||||
return fmt.Sprintf("[ERR] %s failed", s.Name)
|
||||
return fmt.Sprintf("[ERR] ⛔ %s failed", s.Name)
|
||||
}
|
||||
|
||||
if s.Restarted {
|
||||
return fmt.Sprintf("[R] 🔥 %s", s.Name)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("[R] %s", s.Name)
|
||||
|
|
Loading…
Reference in New Issue