2016-12-22 16:15:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-01-20 12:41:26 +00:00
|
|
|
"github.com/bcicen/ctop/collector"
|
2017-01-06 11:51:11 +00:00
|
|
|
"github.com/bcicen/ctop/widgets"
|
2016-12-22 16:15:22 +00:00
|
|
|
)
|
|
|
|
|
2016-12-22 22:04:21 +00:00
|
|
|
type Container struct {
|
|
|
|
id string
|
2017-01-01 22:42:13 +00:00
|
|
|
name string
|
2017-02-03 23:33:13 +00:00
|
|
|
state string
|
2017-01-20 12:41:26 +00:00
|
|
|
metrics collector.Metrics
|
|
|
|
collect collector.Collector
|
2017-01-06 12:59:45 +00:00
|
|
|
widgets widgets.ContainerWidgets
|
2017-01-06 11:51:11 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 19:46:30 +00:00
|
|
|
func (c *Container) Expand() {
|
|
|
|
c.widgets = widgets.NewExpanded(c.id, c.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Container) Collapse() {
|
|
|
|
c.widgets = widgets.NewCompact(c.id, c.name)
|
|
|
|
}
|
2016-12-22 22:04:21 +00:00
|
|
|
|
2017-02-03 23:33:13 +00:00
|
|
|
func (c *Container) SetState(s string) {
|
|
|
|
c.state = s
|
|
|
|
c.widgets.SetStatus(s)
|
|
|
|
// start collector if necessary
|
|
|
|
if s == "running" && !c.collect.Running() {
|
|
|
|
c.Collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-20 12:41:26 +00:00
|
|
|
func (c *Container) Collect() {
|
2017-02-02 07:09:43 +00:00
|
|
|
c.collect.Start()
|
2016-12-22 22:04:21 +00:00
|
|
|
go func() {
|
2017-01-20 12:41:26 +00:00
|
|
|
for metrics := range c.collect.Stream() {
|
|
|
|
c.metrics = metrics
|
2017-01-09 14:09:26 +00:00
|
|
|
c.widgets.SetCPU(metrics.CPUUtil)
|
|
|
|
c.widgets.SetMem(metrics.MemUsage, metrics.MemLimit, metrics.MemPercent)
|
|
|
|
c.widgets.SetNet(metrics.NetRx, metrics.NetTx)
|
2016-12-22 22:04:21 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|