mirror of https://github.com/divan/expvarmon.git
Added sparklines for each service
This commit is contained in:
parent
676cbb2081
commit
58da318423
16
service.go
16
service.go
|
@ -15,7 +15,9 @@ type Service struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
Cmdline string
|
Cmdline string
|
||||||
Memstats *runtime.MemStats
|
MemStats *runtime.MemStats
|
||||||
|
|
||||||
|
Values map[string]*Stack
|
||||||
|
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
@ -25,6 +27,8 @@ func NewService(port string) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
Name: port, // we have only port on start, so use it as name until resolved
|
Name: port, // we have only port on start, so use it as name until resolved
|
||||||
Port: port,
|
Port: port,
|
||||||
|
|
||||||
|
Values: make(map[string]*Stack),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,13 +49,21 @@ func (s *Service) Update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Err = expvar.Err
|
s.Err = expvar.Err
|
||||||
s.Memstats = expvar.MemStats
|
s.MemStats = expvar.MemStats
|
||||||
|
|
||||||
// Update name and cmdline only if empty
|
// Update name and cmdline only if empty
|
||||||
if len(s.Cmdline) == 0 {
|
if len(s.Cmdline) == 0 {
|
||||||
s.Cmdline = strings.Join(expvar.Cmdline, " ")
|
s.Cmdline = strings.Join(expvar.Cmdline, " ")
|
||||||
s.Name = BaseCommand(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.
|
// Addr returns fully qualified host:port pair for service.
|
||||||
|
|
|
@ -21,9 +21,9 @@ func (u *DummyUI) Update(data Data) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.Memstats != nil {
|
if service.MemStats != nil {
|
||||||
alloc := byten.Size(int64(service.Memstats.Alloc))
|
alloc := byten.Size(int64(service.MemStats.Alloc))
|
||||||
sys := byten.Size(int64(service.Memstats.Sys))
|
sys := byten.Size(int64(service.MemStats.Sys))
|
||||||
fmt.Printf("%s/%s ", alloc, sys)
|
fmt.Printf("%s/%s ", alloc, sys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
ui_termui.go
27
ui_termui.go
|
@ -72,18 +72,33 @@ func (t *TermUI) Update(data Data) {
|
||||||
goroutines.Items = append(goroutines.Items, "N/A")
|
goroutines.Items = append(goroutines.Items, "N/A")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
alloc := byten.Size(int64(service.Memstats.Alloc))
|
alloc := byten.Size(int64(service.MemStats.Alloc))
|
||||||
heap := byten.Size(int64(service.Memstats.HeapAlloc))
|
heap := byten.Size(int64(service.MemStats.HeapAlloc))
|
||||||
totalAlloc += int64(service.Memstats.Alloc)
|
totalAlloc += int64(service.MemStats.Alloc)
|
||||||
|
|
||||||
name := fmt.Sprintf("[R] %s", service.Name)
|
name := fmt.Sprintf("[R] %s", service.Name)
|
||||||
meminfos := fmt.Sprintf("%s/%s", alloc, heap)
|
meminfos := fmt.Sprintf("%s/%s", alloc, heap)
|
||||||
//goroutine := fmt.Sprintf("%d", service.Goroutines)
|
|
||||||
|
|
||||||
names.Items = append(names.Items, name)
|
names.Items = append(names.Items, name)
|
||||||
meminfo.Items = append(meminfo.Items, meminfos)
|
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))
|
data.TotalMemory.Push(int(totalAlloc / 1024))
|
||||||
|
|
||||||
spl3 := termui.NewSparkline()
|
spl3 := termui.NewSparkline()
|
||||||
|
@ -98,7 +113,7 @@ func (t *TermUI) Update(data Data) {
|
||||||
spls2.Border.FgColor = termui.ColorCyan
|
spls2.Border.FgColor = termui.ColorCyan
|
||||||
spls2.Border.Label = fmt.Sprintf("Total Memory Usage: %s", byten.Size(totalAlloc))
|
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() {
|
func (t *TermUI) Close() {
|
||||||
|
|
Loading…
Reference in New Issue