-
Notifications
You must be signed in to change notification settings - Fork 18
/
query.go
43 lines (35 loc) · 1000 Bytes
/
query.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
package cron
import (
"github.com/open-falcon/common/model"
"github.com/open-falcon/sdk/graph"
)
func queryCounterLast(numeratorOperands, denominatorOperands, hostnames []string, begin, end int64) (map[string]float64, error) {
counters := []string{}
for _, counter := range numeratorOperands {
counters = append(counters, counter)
}
for _, counter := range denominatorOperands {
counters = append(counters, counter)
}
params := []*model.GraphLastParam{}
counterSize := len(counters)
hostnameSize := len(hostnames)
for i := 0; i < counterSize; i++ {
for j := 0; j < hostnameSize; j++ {
params = append(params, &model.GraphLastParam{Endpoint: hostnames[j], Counter: counters[i]})
}
}
resp, err := graph.Lasts(params)
if err != nil {
return nil, err
}
ret := make(map[string]float64)
for _, res := range resp {
v := res.Value
if v.Timestamp < begin || v.Timestamp > end {
continue
}
ret[res.Endpoint+res.Counter] = float64(v.Value)
}
return ret, nil
}