mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add SetStatus method to Container
This commit is contained in:
10
container.go
10
container.go
@@ -8,6 +8,7 @@ import (
|
|||||||
type Container struct {
|
type Container struct {
|
||||||
id string
|
id string
|
||||||
name string
|
name string
|
||||||
|
state string
|
||||||
metrics collector.Metrics
|
metrics collector.Metrics
|
||||||
collect collector.Collector
|
collect collector.Collector
|
||||||
widgets widgets.ContainerWidgets
|
widgets widgets.ContainerWidgets
|
||||||
@@ -21,6 +22,15 @@ func (c *Container) Collapse() {
|
|||||||
c.widgets = widgets.NewCompact(c.id, c.name)
|
c.widgets = widgets.NewCompact(c.id, c.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Container) Collect() {
|
func (c *Container) Collect() {
|
||||||
c.collect.Start()
|
c.collect.Start()
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -62,11 +62,7 @@ func (cm *ContainerMap) Refresh() {
|
|||||||
removeIDs = append(removeIDs, id)
|
removeIDs = append(removeIDs, id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// start collector if necessary
|
c.SetState(states[id])
|
||||||
if states[id] == "running" && !c.collect.Running() {
|
|
||||||
c.Collect()
|
|
||||||
}
|
|
||||||
c.widgets.SetStatus(states[id])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove dead containers
|
// remove dead containers
|
||||||
|
|||||||
Reference in New Issue
Block a user