From a3e8c73865de4c9af33489edd4da825cc78db555 Mon Sep 17 00:00:00 2001 From: Bas van der Lei Date: Mon, 10 Apr 2017 14:10:48 +0200 Subject: [PATCH] gnore unused cpus in Prometheus metrics Only include cpu's in the Prometheus metrics endpoint that were used. In recent kernels the cpuacct.statcpus behavior has changed to include all possible cpu's. This can results in a high number of stale metrics in the Prometheus endpoint. --- metrics/prometheus.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/metrics/prometheus.go b/metrics/prometheus.go index 775866bb..6f65cb45 100644 --- a/metrics/prometheus.go +++ b/metrics/prometheus.go @@ -130,10 +130,12 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc) *PrometheusCo getValues: func(s *info.ContainerStats) metricValues { values := make(metricValues, 0, len(s.Cpu.Usage.PerCpu)) for i, value := range s.Cpu.Usage.PerCpu { - values = append(values, metricValue{ - value: float64(value) / float64(time.Second), - labels: []string{fmt.Sprintf("cpu%02d", i)}, - }) + if value > 0 { + values = append(values, metricValue{ + value: float64(value) / float64(time.Second), + labels: []string{fmt.Sprintf("cpu%02d", i)}, + }) + } } return values },