From 3a29c948335302c8b0cb660a8915b4376b60d2cc Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 13 Nov 2020 11:02:14 +0200 Subject: [PATCH] Use percent() function to calc CPU usage --- connector/collector/docker.go | 4 ++-- connector/collector/runc.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/connector/collector/docker.go b/connector/collector/docker.go index 18c29d0..a74e39a 100644 --- a/connector/collector/docker.go +++ b/connector/collector/docker.go @@ -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 diff --git a/connector/collector/runc.go b/connector/collector/runc.go index 3734e19..9b52aee 100644 --- a/connector/collector/runc.go +++ b/connector/collector/runc.go @@ -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