metric.go 276 Bytes
Newer Older
“李磊”'s avatar
“李磊” committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
}