From a22d99fefba741aa0a6287ffbfec9cb8e669ca24 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Thu, 12 Nov 2020 19:29:54 +0200 Subject: [PATCH 1/2] file.go: remove duplicated trim The s var was already trimmed on line 67 --- config/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/file.go b/config/file.go index 77f33e9..b8851e4 100644 --- a/config/file.go +++ b/config/file.go @@ -66,7 +66,7 @@ func Read() error { for _, s := range strings.Split(colStr, ",") { s = strings.TrimSpace(s) if s != "" { - colNames = append(colNames, strings.TrimSpace(s)) + colNames = append(colNames, s) } } SetColumns(colNames) From 3a29c948335302c8b0cb660a8915b4376b60d2cc Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 13 Nov 2020 11:02:14 +0200 Subject: [PATCH 2/2] 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