2016-12-22 16:15:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-12-22 22:04:21 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/fsouza/go-dockerclient"
|
2016-12-22 16:15:22 +00:00
|
|
|
)
|
|
|
|
|
2016-12-22 22:04:21 +00:00
|
|
|
type Container struct {
|
|
|
|
id string
|
|
|
|
done chan bool
|
2016-12-25 22:39:16 +00:00
|
|
|
stats chan *docker.Stats
|
|
|
|
widgets *Widgets
|
|
|
|
reader *StatReader
|
2016-12-22 22:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Container) Collect(client *docker.Client) {
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
fmt.Sprintf("starting collector for container: %s\n", c.id)
|
|
|
|
opts := docker.StatsOptions{
|
|
|
|
ID: c.id,
|
|
|
|
Stats: c.stats,
|
|
|
|
Stream: true,
|
|
|
|
Done: c.done,
|
|
|
|
}
|
|
|
|
client.Stats(opts)
|
|
|
|
fmt.Sprintf("stopping collector for container: %s\n", c.id)
|
|
|
|
}()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for s := range c.stats {
|
2016-12-25 22:39:16 +00:00
|
|
|
c.reader.Read(s)
|
|
|
|
c.widgets.SetCPU(c.reader.CPUUtil)
|
|
|
|
c.widgets.SetMem(c.reader.MemUsage, c.reader.MemLimit)
|
2016-12-26 17:57:55 +00:00
|
|
|
c.widgets.SetNet(c.reader.NetRx, c.reader.NetTx)
|
2016-12-22 22:04:21 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
}
|