ctop/container.go

42 lines
917 B
Go
Raw Normal View History

2016-12-22 16:15:22 +00:00
package main
import (
2017-02-23 02:03:55 +00:00
"github.com/bcicen/ctop/metrics"
"github.com/bcicen/ctop/widgets"
2016-12-22 16:15:22 +00:00
)
type Container struct {
id string
name string
2017-02-03 23:33:13 +00:00
state string
2017-02-23 02:03:55 +00:00
metrics metrics.Metrics
widgets widgets.ContainerWidgets
}
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)
}
2017-02-03 23:33:13 +00:00
func (c *Container) SetState(s string) {
c.state = s
c.widgets.SetStatus(s)
}
// Read metric stream, updating widgets
2017-02-23 02:03:55 +00:00
func (c *Container) Read(stream chan metrics.Metrics) {
go func() {
for metrics := range stream {
c.metrics = metrics
c.widgets.SetCPU(metrics.CPUUtil)
c.widgets.SetMem(metrics.MemUsage, metrics.MemLimit, metrics.MemPercent)
c.widgets.SetNet(metrics.NetRx, metrics.NetTx)
}
log.Infof("reader stopped for container: %s", c.id)
}()
log.Infof("reader started for container: %s", c.id)
}