ignore sample if it leads cpu utilization < 0

This commit is contained in:
Nan Deng 2014-06-12 10:31:43 -07:00
parent 478ff3d45e
commit 0d85d23a89

View File

@ -203,6 +203,10 @@ func NewSample(prev, current *ContainerStats) (*ContainerStatsSample, error) {
if !current.Timestamp.After(prev.Timestamp) {
return nil, fmt.Errorf("wrong stats order")
}
// This data is invalid.
if current.Cpu.Usage.Total < prev.Cpu.Usage.Total {
return nil, fmt.Errorf("current CPU usage is less than prev CPU usage (cumulative).")
}
sample := new(ContainerStatsSample)
// Caculate the diff to get the CPU usage within the time interval.
sample.Cpu.Usage = current.Cpu.Usage.Total - prev.Cpu.Usage.Total