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

@ -18,7 +18,8 @@ type Service struct {
stacks map[VarName]*Stack stacks map[VarName]*Stack
Err error Err error
Restarted bool
} }
// NewService returns new Service object. // NewService returns new Service object.
@ -40,6 +41,10 @@ func NewService(port string, vars []VarName) *Service {
func (s *Service) Update(wg *sync.WaitGroup) { func (s *Service) Update(wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
expvar, err := FetchExpvar(s.Addr()) expvar, err := FetchExpvar(s.Addr())
// check for restart
if s.Err != nil && err == nil {
s.Restarted = true
}
s.Err = err s.Err = err
// Update Cmdline & Name only once // Update Cmdline & Name only once
@ -57,6 +62,7 @@ func (s *Service) Update(wg *sync.WaitGroup) {
for name, stack := range s.stacks { for name, stack := range s.stacks {
value, err := expvar.GetValue(name.ToSlice()...) value, err := expvar.GetValue(name.ToSlice()...)
if err != nil { if err != nil {
stack.Push(nil)
continue continue
} }
v := guessValue(value) 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. // Update updates UI widgets from UIData.
func (t *TermUI) Update(data 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.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 // List with service names
var services []string var services []string
@ -167,7 +167,11 @@ func (t *TermUI) Close() {
// StatusLine returns status line for service with it's name and status. // StatusLine returns status line for service with it's name and status.
func StatusLine(s *Service) string { func StatusLine(s *Service) string {
if s.Err != nil { 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) return fmt.Sprintf("[R] %s", s.Name)