예제 #1
0
파일: util.go 프로젝트: huin/warren
func readIntFileIntoCounter(ctr promm.Counter, path string) {
	value, err := readIntFile(path)
	if err != nil {
		log.Printf("Unable to read integer from file %q for counter %v: %v",
			path, *ctr.Desc(), err)
		return
	}
	ctr.Set(float64(value))
}
예제 #2
0
func collectTrafficBytes(counter stat.Counter, oldTraffic, newTraffic *data.TrafficObject) {
	if newTraffic == nil {
		// If a client statistics has no traffic information, don't collect anything
		return
	}
	var value float64
	if oldTraffic != nil {
		value = float64(newTraffic.Bytes - oldTraffic.Bytes)
	} else {
		value = float64(newTraffic.Bytes)
	}
	if value > 0 {
		counter.Add(value)
	} else if newTraffic.Bytes > 0 {
		counter.Add(newTraffic.Bytes)
	} else {
		log.WithFields(log.Fields{
			"newTraffic": *newTraffic,
			"oldTraffic": oldTraffic,
			"value":      value,
		}).Errorf("New traffic value was smaller than the old value and the new traffic value even seemed to be negative")
	}
}
func readCounter(m prometheus.Counter) float64 {
	// TODO: Revisit this once client_golang offers better testing tools.
	pb := &dto.Metric{}
	m.Write(pb)
	return pb.GetCounter().GetValue()
}