This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
out.go
54 lines (42 loc) · 1.26 KB
/
out.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
package out
import (
"fmt"
"os"
"strings"
"text/template"
"github.com/davecgh/go-spew/spew"
"github.com/grafana/metrictank/schema"
)
var QueryTime int64
func Dump(d schema.MetricDefinition) {
spew.Dump(d)
}
func List(d schema.MetricDefinition) {
fmt.Println(d.OrgId, d.NameWithTags())
}
func GetVegetaRender(addr, from string) func(d schema.MetricDefinition) {
return func(d schema.MetricDefinition) {
fmt.Printf("GET %s/render?target=%s&from=-%s\nX-Org-Id: %d\n\n", addr, d.Name, from, d.OrgId)
}
}
func GetVegetaRenderPattern(addr, from string) func(d schema.MetricDefinition) {
return func(d schema.MetricDefinition) {
fmt.Printf("GET %s/render?target=%s&from=-%s\nX-Org-Id: %d\n\n", addr, pattern(d.Name), from, d.OrgId)
}
}
func Template(format string) func(d schema.MetricDefinition) {
funcs := make(map[string]interface{})
funcs["pattern"] = pattern
funcs["patternCustom"] = patternCustom
funcs["age"] = age
funcs["roundDuration"] = roundDuration
// replace '\n' in the format string with actual newlines.
format = strings.Replace(format, "\\n", "\n", -1)
tpl := template.Must(template.New("format").Funcs(funcs).Parse(format))
return func(d schema.MetricDefinition) {
err := tpl.Execute(os.Stdout, &d)
if err != nil {
panic(err)
}
}
}