-
Notifications
You must be signed in to change notification settings - Fork 3
/
rra.go
89 lines (73 loc) · 2.34 KB
/
rra.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package rrd
import (
"fmt"
"strings"
)
// Round Robin Algorithms
const (
Average = "AVERAGE"
Min = "MIN"
Max = "MAX"
Last = "LAST"
HoltWintersPredict = "HWPREDICT"
MultipliedHoltWinterPredict = "MHWPREDICT"
Seasonal = "SEASONAL"
DevSeasonal = "DEVSEASONAL"
DevPredict = "DEVPREDICT"
Failures = "FAILURES"
)
// RRA represents a raw RRA.
type RRA string
// NewRRA returns a new raw RRA set to val.
func NewRRA(val string) RRA {
return RRA(val)
}
func newRRA(rra string, vals ...interface{}) RRA {
parts := make([]string, len(vals)+2)
parts[0] = "RRA"
parts[1] = rra
for i, v := range vals {
parts[i+2] = fmt.Sprint(v)
}
return RRA(strings.Join(parts, ":"))
}
// NewAverage returns a new AVERAGE RRA.
func NewAverage(xff float32, steps, rows int) RRA {
return newRRA(Average, xff, steps, rows)
}
// NewMin returns a new MIN RRA.
func NewMin(xff float32, steps, rows int) RRA {
return newRRA(Min, xff, steps, rows)
}
// NewMax returns a new AVERAGE RRA.
func NewMax(xff float32, steps, rows int) RRA {
return newRRA(Max, xff, steps, rows)
}
// NewLast returns a new AVERAGE RRA.
func NewLast(xff float32, steps, rows int) RRA {
return newRRA(Last, xff, steps, rows)
}
// NewHWPredict returns a new HWPREDICT RRA.
func NewHWPredict(rows int, alpha, beta float32, period int, idx int) RRA {
return newRRA(HoltWintersPredict, rows, alpha, beta, period, idx)
}
// NewMHWPredict returns a new HWPREDICT RRA.
func NewMHWPredict(rows int, alpha, beta float32, period int, idx int) RRA {
return newRRA(MultipliedHoltWinterPredict, rows, alpha, beta, period, idx)
}
// NewSeasonal returns a new HWPREDICT RRA.
func NewSeasonal(period int, gamma float32, idx int, window float32) RRA {
return newRRA(Seasonal, period, gamma, idx, fmt.Sprintf("smoothing-window=%v", window))
}
// NewDevSeasonal returns a new HWPREDICT RRA.
func NewDevSeasonal(period int, gamma float32, idx int, window float32) RRA {
return newRRA(DevSeasonal, period, gamma, idx, fmt.Sprintf("smoothing-window=%v", window))
}
// NewDevPredict returns a new HWPREDICT RRA.
func NewDevPredict(rows, idx int) RRA {
return newRRA(DevPredict, rows, idx)
}
// NewFailures returns a new HWPREDICT RRA.
func NewFailures(rows, threshold, window, idx int) RRA {
return newRRA(Failures, rows, threshold, window, idx)
}