// values should be a "cpu"-prefixed set of values from /proc/stat. // cc.metricLabels must have "core" label set or removed as appropriate for cv. func (cc *cpuCollector) exportValues(values []string, cv *promm.CounterVec) { for stateIndex, valueStr := range values { if stateIndex > len(cpuStates) { break } if cc.recordedStates&(1<<uint(stateIndex)) != 0 { jiffies, err := strconv.ParseUint(valueStr, 10, 64) if err != nil { continue } cc.metricLabels["state"] = cpuStates[stateIndex] cv.With(cc.metricLabels).Set(float64(jiffies) * cc.jiffiesScaler) } } }
func readCounterVec(m *prometheus.CounterVec, l prometheus.Labels) float64 { pb := &dto.Metric{} c := m.With(l) c.Write(pb) return pb.GetCounter().GetValue() }