1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/stats.go
John Howard 48f1cb4ebe Windows: refactor stats
Signed-off-by: John Howard <jhoward@microsoft.com>
2015-05-20 09:08:45 -07:00

32 lines
734 B
Go

package daemon
import (
"encoding/json"
"io"
"github.com/docker/docker/daemon/execdriver"
)
func (daemon *Daemon) ContainerStats(name string, stream bool, out io.Writer) error {
updates, err := daemon.SubscribeToContainerStats(name)
if err != nil {
return err
}
enc := json.NewEncoder(out)
for v := range updates {
update := v.(*execdriver.ResourceStats)
ss := convertToAPITypes(update.Stats)
ss.MemoryStats.Limit = uint64(update.MemoryLimit)
ss.Read = update.Read
ss.CpuStats.SystemUsage = update.SystemUsage
if err := enc.Encode(ss); err != nil {
// TODO: handle the specific broken pipe
daemon.UnsubscribeToContainerStats(name, updates)
return err
}
if !stream {
break
}
}
return nil
}