Пример #1
0
Файл: cpu.go Проект: huin/warren
// 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)
		}
	}
}
Пример #2
0
func (s *Sink) EmitEvent(job string, event string, kvs map[string]string) {
	var counter *prometheus.CounterVec
	if c, ok := s.Config.CounterVecs[job]; ok {
		counter = c
	} else {
		labels := labelsFromMap(kvs)

		counter = prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: s.Config.Job,
			Subsystem: "indexer",
			Name:      job,
			Help:      "Automaticaly created event",
		}, labels)

		s.Config.CounterVecs[job] = counter
		prometheus.Register(counter)
	}

	kvs["event"] = event

	if m, err := counter.GetMetricWith(kvs); err == nil {
		m.Inc()
	}
}
Пример #3
0
func readCounterVec(m *prometheus.CounterVec, l prometheus.Labels) float64 {
	pb := &dto.Metric{}
	c := m.With(l)
	c.Write(pb)
	return pb.GetCounter().GetValue()
}