Added sparklines for each service

This commit is contained in:
Ivan Daniluk 2015-04-25 16:29:19 +03:00
parent 676cbb2081
commit 58da318423
3 changed files with 38 additions and 11 deletions

View File

@ -15,7 +15,9 @@ type Service struct {
Name string
Cmdline string
Memstats *runtime.MemStats
MemStats *runtime.MemStats
Values map[string]*Stack
Err error
}
@ -25,6 +27,8 @@ func NewService(port string) *Service {
return &Service{
Name: port, // we have only port on start, so use it as name until resolved
Port: port,
Values: make(map[string]*Stack),
}
}
@ -45,13 +49,21 @@ func (s *Service) Update() {
}
s.Err = expvar.Err
s.Memstats = expvar.MemStats
s.MemStats = expvar.MemStats
// Update name and cmdline only if empty
if len(s.Cmdline) == 0 {
s.Cmdline = strings.Join(expvar.Cmdline, " ")
s.Name = BaseCommand(expvar.Cmdline)
}
// Put metrics data
mem, ok := s.Values["memory"]
if !ok {
s.Values["memory"] = NewStack(40)
mem = s.Values["memory"]
}
mem.Push(int(s.MemStats.Alloc) / 1024)
}
// Addr returns fully qualified host:port pair for service.

View File

@ -21,9 +21,9 @@ func (u *DummyUI) Update(data Data) {
continue
}
if service.Memstats != nil {
alloc := byten.Size(int64(service.Memstats.Alloc))
sys := byten.Size(int64(service.Memstats.Sys))
if service.MemStats != nil {
alloc := byten.Size(int64(service.MemStats.Alloc))
sys := byten.Size(int64(service.MemStats.Sys))
fmt.Printf("%s/%s ", alloc, sys)
}

View File

@ -72,18 +72,33 @@ func (t *TermUI) Update(data Data) {
goroutines.Items = append(goroutines.Items, "N/A")
continue
}
alloc := byten.Size(int64(service.Memstats.Alloc))
heap := byten.Size(int64(service.Memstats.HeapAlloc))
totalAlloc += int64(service.Memstats.Alloc)
alloc := byten.Size(int64(service.MemStats.Alloc))
heap := byten.Size(int64(service.MemStats.HeapAlloc))
totalAlloc += int64(service.MemStats.Alloc)
name := fmt.Sprintf("[R] %s", service.Name)
meminfos := fmt.Sprintf("%s/%s", alloc, heap)
//goroutine := fmt.Sprintf("%d", service.Goroutines)
names.Items = append(names.Items, name)
meminfo.Items = append(meminfo.Items, meminfos)
//goroutines.Items = append(goroutines.Items, goroutine)
}
var sparklines []termui.Sparkline
for _, service := range data.Services {
spl := termui.NewSparkline()
spl.Data = service.Values["memory"].Values
spl.Height = 1
spl.LineColor = termui.ColorGreen
sparklines = append(sparklines, spl)
}
spls := termui.NewSparklines(sparklines...)
spls.Height = len(data.Services) + 1
spls.Width = 40
spls.Y = 3
spls.X = meminfo.X + meminfo.Width - spls.Width - 1
spls.HasBorder = false
data.TotalMemory.Push(int(totalAlloc / 1024))
spl3 := termui.NewSparkline()
@ -98,7 +113,7 @@ func (t *TermUI) Update(data Data) {
spls2.Border.FgColor = termui.ColorCyan
spls2.Border.Label = fmt.Sprintf("Total Memory Usage: %s", byten.Size(totalAlloc))
termui.Render(p, p1, names, meminfo, goroutines, spls2)
termui.Render(p, p1, names, meminfo, goroutines, spls2, spls)
}
func (t *TermUI) Close() {