forked from open-falcon/falcon-plus
/
proc_http.go
106 lines (90 loc) · 2.7 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
package http
import (
"net/http"
"strconv"
"strings"
cutils "github.com/open-falcon/falcon-plus/common/utils"
"github.com/open-falcon/falcon-plus/modules/gateway/g"
"github.com/open-falcon/falcon-plus/modules/gateway/sender"
)
func configProcHttpRoutes() {
// TO BE DISCARDed
http.HandleFunc("/counter/all", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, make([]interface{}, 0))
})
http.HandleFunc("/statistics/all", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, make([]interface{}, 0))
})
// proc
http.HandleFunc("/proc/counters", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, make([]interface{}, 0))
})
http.HandleFunc("/proc/transfer/pools", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, sender.SenderConnPools.Proc())
})
http.HandleFunc("/proc/transfer/send", func(w http.ResponseWriter, r *http.Request) {
ret := make([]interface{}, 0)
for _, p := range sender.TransferSendCnt {
ret = append(ret, p.Get())
}
RenderDataJson(w, ret)
})
http.HandleFunc("/proc/transfer/sendfail", func(w http.ResponseWriter, r *http.Request) {
ret := make([]interface{}, 0)
for _, p := range sender.TransferSendFailCnt {
ret = append(ret, p.Get())
}
RenderDataJson(w, ret)
})
// trace
http.HandleFunc("/trace/", func(w http.ResponseWriter, r *http.Request) {
urlParam := r.URL.Path[len("/trace/"):]
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]
}
}
}
g.RecvDataTrace.SetPK(cutils.PK(endpoint, metric, tags))
RenderDataJson(w, g.RecvDataTrace.GetAllTraced())
})
// filter
http.HandleFunc("/filter/", func(w http.ResponseWriter, r *http.Request) {
urlParam := r.URL.Path[len("/filter/"):]
args := strings.Split(urlParam, "/")
argsLen := len(args)
endpoint := args[0]
metric := args[1]
opt := args[2]
threadholdStr := args[3]
threadhold, err := strconv.ParseFloat(threadholdStr, 64)
if err != nil {
RenderDataJson(w, "bad threadhold")
return
}
tags := make(map[string]string)
if argsLen > 4 {
tagVals := strings.Split(args[4], ",")
for _, tag := range tagVals {
tagPairs := strings.Split(tag, "=")
if len(tagPairs) == 2 {
tags[tagPairs[0]] = tagPairs[1]
}
}
}
err = g.RecvDataFilter.SetFilter(cutils.PK(endpoint, metric, tags), opt, threadhold)
if err != nil {
RenderDataJson(w, err.Error())
return
}
RenderDataJson(w, g.RecvDataFilter.GetAllFiltered())
})
}