mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
48f1cb4ebe
Signed-off-by: John Howard <jhoward@microsoft.com>
32 lines
734 B
Go
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
|
|
}
|