Unify CPU collector conventions (#806)

* Unify CPU collector conventions

Add a common CPU metric description.
* All collectors use the same `nodeCpuSecondsDesc`.
* All collectors drop the `cpu` prefix for `cpu` label values.

* Fix subsystem string in cpu_freebsd.

* Fix Linux CPU freq label names.
This commit is contained in:
Ben Kochie 2018-02-01 18:42:20 +01:00 committed by GitHub
commit 14d60958d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 117 deletions

View file

@ -58,11 +58,7 @@ func init() {
// NewCPUCollector returns a new Collector exposing CPU stats.
func NewCPUCollector() (Collector, error) {
return &statCollector{
cpu: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "cpu"),
"Seconds the cpus spent in each mode.",
[]string{"cpu", "mode"}, nil,
),
cpu: nodeCpuSecondsDesc,
}, nil
}
@ -111,7 +107,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
"nice": C.CPU_STATE_NICE,
"idle": C.CPU_STATE_IDLE,
} {
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(cpuTicks[v])/ClocksPerSec, "cpu"+strconv.Itoa(i), k)
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(cpuTicks[v])/ClocksPerSec, strconv.Itoa(i), k)
}
}
return nil