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

@ -94,11 +94,7 @@ func init() {
// NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector() (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
}
@ -143,7 +139,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
// Export order: user nice sys intr idle
cpuFields := []string{"user", "nice", "sys", "interrupt", "idle"}
for i, value := range cpuTimes {
cpux := fmt.Sprintf("cpu%d", i/fieldsCount)
cpux := fmt.Sprintf("%d", i/fieldsCount)
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, value, cpux, cpuFields[i%fieldsCount])
}