2015-01-07 21:02:08 -05:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2015-04-13 02:33:53 -04:00
|
|
|
"io"
|
2015-01-07 21:02:08 -05:00
|
|
|
|
2015-01-19 18:29:42 -05:00
|
|
|
"github.com/docker/docker/daemon/execdriver"
|
2015-01-07 21:02:08 -05:00
|
|
|
)
|
|
|
|
|
2015-02-13 11:45:04 -05:00
|
|
|
func (daemon *Daemon) ContainerStats(name string, stream bool, out io.Writer) error {
|
2015-04-13 02:33:53 -04:00
|
|
|
updates, err := daemon.SubscribeToContainerStats(name)
|
2015-01-07 21:02:08 -05:00
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2015-01-07 21:02:08 -05:00
|
|
|
}
|
2015-04-13 02:33:53 -04:00
|
|
|
enc := json.NewEncoder(out)
|
2015-01-19 18:29:42 -05:00
|
|
|
for v := range updates {
|
|
|
|
update := v.(*execdriver.ResourceStats)
|
2015-03-05 12:55:14 -05:00
|
|
|
ss := convertToAPITypes(update.Stats)
|
2015-01-07 21:02:08 -05:00
|
|
|
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
|
2015-04-13 02:33:53 -04:00
|
|
|
daemon.UnsubscribeToContainerStats(name, updates)
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2015-01-07 21:02:08 -05:00
|
|
|
}
|
2015-02-13 11:45:04 -05:00
|
|
|
if !stream {
|
|
|
|
break
|
|
|
|
}
|
2015-01-07 21:02:08 -05:00
|
|
|
}
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2015-01-07 21:02:08 -05:00
|
|
|
}
|