/
proc_http.go
115 lines (98 loc) · 2.86 KB
/
proc_http.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
104
105
106
107
108
109
110
111
112
113
114
115
package http
import (
"net/http"
"strings"
cutils "github.com/Cepave/open-falcon-backend/common/utils"
"github.com/Cepave/open-falcon-backend/modules/graph/proc"
"github.com/Cepave/open-falcon-backend/modules/graph/store"
)
func configProcRoutes() {
// counter
http.HandleFunc("/counter/all", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, proc.GetAll())
})
// TO BE DISCARDed
http.HandleFunc("/statistics/all", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, proc.GetAll())
})
// items.history
http.HandleFunc("/history/", func(w http.ResponseWriter, r *http.Request) {
urlParam := r.URL.Path[len("/history/"):]
args := strings.Split(urlParam, "/")
argsLen := len(args)
endpoint := args[0]
metric := args[1]
tags := make(map[string]string)
if argsLen > 2 {
tagVals := strings.Split(args[2], ",")
for _, tag := range tagVals {
tagPairs := strings.Split(tag, "=")
if len(tagPairs) == 2 {
tags[tagPairs[0]] = tagPairs[1]
}
}
}
RenderDataJson(w, store.GetAllItems(cutils.Checksum(endpoint, metric, tags)))
})
http.HandleFunc("/v2/history", func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
if !(len(r.Form["e"]) > 0 && len(r.Form["m"]) > 0) {
RenderDataJson(w, "bad args")
return
}
endpoint := r.Form["e"][0]
metric := r.Form["m"][0]
tags := make(map[string]string)
if len(r.Form["t"]) > 0 {
tagstr := r.Form["t"][0]
tagVals := strings.Split(tagstr, ",")
for _, tag := range tagVals {
tagPairs := strings.Split(tag, "=")
if len(tagPairs) == 2 {
tags[tagPairs[0]] = tagPairs[1]
}
}
}
RenderDataJson(w, store.GetAllItems(cutils.Checksum(endpoint, metric, tags)))
})
// items.last
http.HandleFunc("/last/", func(w http.ResponseWriter, r *http.Request) {
urlParam := r.URL.Path[len("/last/"):]
args := strings.Split(urlParam, "/")
argsLen := len(args)
endpoint := args[0]
metric := args[1]
tags := make(map[string]string)
if argsLen > 2 {
tagVals := strings.Split(args[2], ",")
for _, tag := range tagVals {
tagPairs := strings.Split(tag, "=")
if len(tagPairs) == 2 {
tags[tagPairs[0]] = tagPairs[1]
}
}
}
RenderDataJson(w, store.GetLastItem(cutils.Checksum(endpoint, metric, tags)))
})
http.HandleFunc("/v2/last", func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
if !(len(r.Form["e"]) > 0 && len(r.Form["m"]) > 0) {
RenderDataJson(w, "bad args")
return
}
endpoint := r.Form["e"][0]
metric := r.Form["m"][0]
tags := make(map[string]string)
if len(r.Form["t"]) > 0 {
tagstr := r.Form["t"][0]
tagVals := strings.Split(tagstr, ",")
for _, tag := range tagVals {
tagPairs := strings.Split(tag, "=")
if len(tagPairs) == 2 {
tags[tagPairs[0]] = tagPairs[1]
}
}
}
RenderDataJson(w, store.GetLastItem(cutils.Checksum(endpoint, metric, tags)))
})
}