From 350cb093389383d4829332a94c06493817ae5585 Mon Sep 17 00:00:00 2001 From: Florian Vahl Date: Wed, 29 Dec 2021 17:56:22 +0100 Subject: [PATCH 1/2] Fix cpu count estimation (#281) * Fix query for the number of cpu cores. * Fix formating * Fix formating again... --- connector/collector/docker.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/connector/collector/docker.go b/connector/collector/docker.go index 68a12745..46cd499c 100644 --- a/connector/collector/docker.go +++ b/connector/collector/docker.go @@ -76,7 +76,10 @@ func (c *Docker) Stop() { } func (c *Docker) ReadCPU(stats *api.Stats) { - ncpus := uint8(len(stats.CPUStats.CPUUsage.PercpuUsage)) + ncpus := uint8(stats.CPUStats.OnlineCPUs) + if ncpus == 0 { + ncpus = uint8(len(stats.CPUStats.CPUUsage.PercpuUsage)) + } total := float64(stats.CPUStats.CPUUsage.TotalUsage) system := float64(stats.CPUStats.SystemCPUUsage) From da09b95d29cc14fe1fff5d9195800ce2fa127c0e Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Thu, 6 Jan 2022 22:12:35 +0000 Subject: [PATCH 2/2] prevent panic on container IDs < 12 chars --- container/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/container/main.go b/container/main.go index 8b59a50d..fd382159 100644 --- a/container/main.go +++ b/container/main.go @@ -31,10 +31,14 @@ type Container struct { func New(id string, collector collector.Collector, manager manager.Manager) *Container { widgets := compact.NewCompactRow() + shortID := id + if len(shortID) > 12 { + shortID = shortID[0:12] + } return &Container{ Metrics: models.NewMetrics(), Id: id, - Meta: models.NewMeta("id", id[:12]), + Meta: models.NewMeta("id", shortID), Widgets: widgets, updater: widgets, collector: collector,