forked from open-falcon-archive/query
-
Notifications
You must be signed in to change notification settings - Fork 4
/
openFalconController.go
63 lines (56 loc) · 1.5 KB
/
openFalconController.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
package openFalcon
import (
"time"
"strconv"
"fmt"
cmodel "github.com/Cepave/common/model"
"github.com/Cepave/query/graph"
"github.com/Cepave/query/model"
log "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
)
func GetEndpoints(c *gin.Context) {
enps := model.EndpointQuery()
c.JSON(200, gin.H{
"status": "ok",
"data": map[string][]string{
"endpoints": enps,
},
})
}
func QDataGet(c *gin.Context) []*cmodel.GraphQueryResponse {
startTmp := c.DefaultQuery("startTs", string(time.Now().Unix()-(86400)))
startTmp2, _ := strconv.Atoi(startTmp)
startTs := int64(startTmp2)
endTmp := c.DefaultQuery("endTs", string(time.Now().Unix()))
endTmp2, _ := strconv.Atoi(endTmp)
endTs := int64(endTmp2)
consolFun := c.DefaultQuery("consolFun", "AVERAGE")
stepTmp := c.DefaultQuery("step", "60")
step, _ := strconv.Atoi(stepTmp)
counter := c.DefaultQuery("counter", "cpu.idle")
endpoints := model.EndpointQuery()
var result []*cmodel.GraphQueryResponse
for _, enp := range endpoints {
q := cmodel.GraphQueryParam{
Start: startTs,
End: endTs,
ConsolFun: consolFun,
Step: step,
Endpoint: enp,
Counter: counter,
}
res, _ := graph.QueryOne(q)
log.Debug(fmt.Sprintf("%v, %v, %v", res.Counter, res.Endpoint, len(res.Values)))
result = append(result, res)
}
log.Debug(fmt.Sprintf("%s: %d", "openfaclon query got", len(result)))
return result
}
func QueryData(c *gin.Context) {
result := QDataGet(c)
c.JSON(200, gin.H{
"status": "ok",
"data": result,
})
}