Exemplo n.º 1
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")
	}
}