Skip to content

Commit

Permalink
Use percent() function to calc CPU usage
Browse files Browse the repository at this point in the history
  • Loading branch information
stokito committed Nov 13, 2020
1 parent a22d99f commit 3a29c94
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions connector/collector/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func (c *Docker) ReadCPU(stats *api.Stats) {
syscpudiff := system - c.lastSysCpu

if c.scaleCpu {
c.CPUUtil = round((cpudiff / syscpudiff * 100))
c.CPUUtil = percent(cpudiff, syscpudiff)
} else {
c.CPUUtil = round((cpudiff / syscpudiff * 100) * ncpus)
c.CPUUtil = percent(ncpus*cpudiff, syscpudiff)
}
c.lastCpu = total
c.lastSysCpu = system
Expand Down
4 changes: 2 additions & 2 deletions connector/collector/runc.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func (c *Runc) ReadCPU(stats *cgroups.Stats) {
syscpudiff := system - c.lastSysCpu

if c.scaleCpu {
c.CPUUtil = round((cpudiff / syscpudiff * 100))
c.CPUUtil = percent(cpudiff, syscpudiff)
} else {
c.CPUUtil = round((cpudiff / syscpudiff * 100) * ncpus)
c.CPUUtil = percent(ncpus*cpudiff, syscpudiff)
}
c.lastCpu = total
c.lastSysCpu = system
Expand Down

0 comments on commit 3a29c94

Please sign in to comment.