Skip to content

Commit 73debf8

Browse files
committed
handle counter reset
1 parent 0775082 commit 73debf8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cli/clistat/cgroup.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@ func (s *Statter) ContainerCPU(m Prefix) (*Result, error) {
7878
return nil, xerrors.Errorf("get cgroup CPU usage: %w", err)
7979
}
8080

81+
if used2 < used1 {
82+
// Someone reset the counter. Best we can do is count from zero.
83+
used1 = 0
84+
}
85+
8186
r := &Result{
8287
Unit: "cores",
8388
Prefix: m,
84-
Used: (used2 - used1),
89+
Used: used2 - used1,
8590
Total: ptr.To(total),
8691
}
8792
return r, nil

0 commit comments

Comments
 (0)