Added restart status

This commit is contained in:
Ivan Daniluk 2015-05-03 15:37:52 +03:00
parent 672a4f9170
commit a0ad89e433
2 changed files with 13 additions and 3 deletions

View File

@ -19,6 +19,7 @@ type Service struct {
stacks map[VarName]*Stack
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
View File

@ -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)