-
Notifications
You must be signed in to change notification settings - Fork 140
/
function.go
103 lines (89 loc) · 2.7 KB
/
function.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package aboveSeries
import (
"context"
"fmt"
"regexp"
"github.com/go-graphite/carbonapi/expr/consolidations"
"github.com/go-graphite/carbonapi/expr/helper"
"github.com/go-graphite/carbonapi/expr/interfaces"
"github.com/go-graphite/carbonapi/expr/types"
"github.com/go-graphite/carbonapi/pkg/parser"
)
type aboveSeries struct {
interfaces.FunctionBase
}
func GetOrder() interfaces.Order {
return interfaces.Any
}
func New(configFile string) []interfaces.RewriteFunctionMetadata {
res := make([]interfaces.RewriteFunctionMetadata, 0)
f := &aboveSeries{}
functions := []string{"useSeriesAbove", "aboveSeries"}
for _, n := range functions {
res = append(res, interfaces.RewriteFunctionMetadata{Name: n, F: f})
}
return res
}
func (f *aboveSeries) Do(ctx context.Context, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) (bool, []string, error) {
args, err := helper.GetSeriesArg(ctx, e.Arg(0), from, until, values)
if err != nil {
return false, nil, err
}
max, err := e.GetFloatArg(1)
if err != nil {
return false, nil, err
}
search, err := e.GetStringArg(2)
if err != nil {
return false, nil, err
}
replace, err := e.GetStringArg(3)
if err != nil {
return false, nil, err
}
rre, err := regexp.Compile(search)
if err != nil {
return false, nil, err
}
var rv []string
for _, a := range args {
if consolidations.MaxValue(a.Values) > max {
rv = append(rv, rre.ReplaceAllString(a.Name, replace))
}
}
fmt.Printf("\n\n\n\n%+v\n\n\n", rv)
return true, rv, nil
}
func (f *aboveSeries) Description() map[string]types.FunctionDescription {
return map[string]types.FunctionDescription{
"useSeriesAbove": {
Name: "useSeriesAbove",
Description: "Takes a seriesList and compares the maximum of each series against the given value. If the series maximum is greater than value, the regular expression search and replace is applied against the series name to plot a related metric e.g. given useSeriesAbove(ganglia.metric1.reqs,10,’reqs’,’time’), the response time metric will be plotted only when the maximum value of the corresponding request/s metric is > 10\n\nShort form: aboveSeries()",
Function: "useSeriesAbove(seriesList, value, search, replace)",
Group: "Filter Series",
Module: "graphite.render.functions",
Params: []types.FunctionParam{
{
Name: "seriesList",
Required: true,
Type: types.SeriesList,
},
{
Name: "value",
Required: true,
Type: types.Float,
},
{
Name: "search",
Required: true,
Type: types.String,
},
{
Name: "replace",
Required: true,
Type: types.String,
},
},
},
}
}