|
@@ -46,7 +46,6 @@ func (s *containerStats) Collect(cli *DockerCli, streamStats bool) {
|
|
|
var (
|
|
|
previousCPU uint64
|
|
|
previousSystem uint64
|
|
|
- start = true
|
|
|
dec = json.NewDecoder(stream)
|
|
|
u = make(chan error, 1)
|
|
|
)
|
|
@@ -61,10 +60,9 @@ func (s *containerStats) Collect(cli *DockerCli, streamStats bool) {
|
|
|
memPercent = float64(v.MemoryStats.Usage) / float64(v.MemoryStats.Limit) * 100.0
|
|
|
cpuPercent = 0.0
|
|
|
)
|
|
|
- if !start {
|
|
|
- cpuPercent = calculateCPUPercent(previousCPU, previousSystem, v)
|
|
|
- }
|
|
|
- start = false
|
|
|
+ previousCPU = v.PreCpuStats.CpuUsage.TotalUsage
|
|
|
+ previousSystem = v.PreCpuStats.SystemUsage
|
|
|
+ cpuPercent = calculateCPUPercent(previousCPU, previousSystem, v)
|
|
|
s.mu.Lock()
|
|
|
s.CPUPercentage = cpuPercent
|
|
|
s.Memory = float64(v.MemoryStats.Usage)
|
|
@@ -73,8 +71,6 @@ func (s *containerStats) Collect(cli *DockerCli, streamStats bool) {
|
|
|
s.NetworkRx = float64(v.Network.RxBytes)
|
|
|
s.NetworkTx = float64(v.Network.TxBytes)
|
|
|
s.mu.Unlock()
|
|
|
- previousCPU = v.CpuStats.CpuUsage.TotalUsage
|
|
|
- previousSystem = v.CpuStats.SystemUsage
|
|
|
u <- nil
|
|
|
if !streamStats {
|
|
|
return
|
|
@@ -151,7 +147,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
|
|
|
}
|
|
|
// do a quick pause so that any failed connections for containers that do not exist are able to be
|
|
|
// evicted before we display the initial or default values.
|
|
|
- time.Sleep(500 * time.Millisecond)
|
|
|
+ time.Sleep(1500 * time.Millisecond)
|
|
|
var errs []string
|
|
|
for _, c := range cStats {
|
|
|
c.mu.Lock()
|