mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
further containermap refactoring
This commit is contained in:
18
container.go
18
container.go
@@ -20,7 +20,7 @@ func NewContainer(id, name string) *Container {
|
||||
id: id,
|
||||
name: name,
|
||||
}
|
||||
c.Collapse()
|
||||
c.widgets = widgets.NewCompact(c.ShortID(), c.ShortName(), c.state)
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -33,11 +33,12 @@ func (c *Container) ShortName() string {
|
||||
}
|
||||
|
||||
func (c *Container) Expand() {
|
||||
c.widgets = widgets.NewExpanded(c.id, c.name)
|
||||
}
|
||||
var curWidgets widgets.ContainerWidgets
|
||||
|
||||
func (c *Container) Collapse() {
|
||||
c.widgets = widgets.NewCompact(c.ShortID(), c.ShortName())
|
||||
curWidgets = c.widgets
|
||||
c.widgets = widgets.NewExpanded(c.ShortID(), c.ShortName())
|
||||
c.widgets.Render()
|
||||
c.widgets = curWidgets
|
||||
}
|
||||
|
||||
func (c *Container) SetState(s string) {
|
||||
@@ -45,6 +46,12 @@ func (c *Container) SetState(s string) {
|
||||
c.widgets.SetStatus(s)
|
||||
}
|
||||
|
||||
// Set metrics to zero state, clear widget gauges
|
||||
func (c *Container) reset() {
|
||||
c.metrics = metrics.Metrics{}
|
||||
c.widgets.Reset()
|
||||
}
|
||||
|
||||
// Read metric stream, updating widgets
|
||||
func (c *Container) Read(stream chan metrics.Metrics) {
|
||||
go func() {
|
||||
@@ -55,6 +62,7 @@ func (c *Container) Read(stream chan metrics.Metrics) {
|
||||
c.widgets.SetNet(metrics.NetRx, metrics.NetTx)
|
||||
}
|
||||
log.Infof("reader stopped for container: %s", c.id)
|
||||
c.reset()
|
||||
}()
|
||||
log.Infof("reader started for container: %s", c.id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user