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.
This commit is contained in:
Bas van der Lei 2017-04-10 14:10:48 +02:00
parent 8a87edd987
commit a3e8c73865

View File

@ -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
},