package stats type metric struct { value float64 ts int64 } func calculateRate(v1, v2 metric) float64 { diff := v2.value - v1.value interval := float64(v2.ts - v1.ts) if diff <= float64(0) || interval <= float64(0) { return float64(0) } return diff / interval }