fix: aggregate data by group key

This commit is contained in:
710leo 2020-03-25 17:08:17 +08:00
parent fb43b03b2c
commit a047f19ba3
2 changed files with 11 additions and 9 deletions

View File

@ -72,7 +72,6 @@ func main() {
funcs.BuildMappers()
funcs.Collect()
stra.GetCollects()
//插件采集
plugins.Detect()

View File

@ -96,15 +96,15 @@ func FetchDataForUI(input dataobj.QueryDataForUI) []*dataobj.TsdbQueryResponse {
//进行数据计算
aggrDatas := []*dataobj.TsdbQueryResponse{}
if input.AggrFunc != "" && len(resp) > 1 {
aggrData := &dataobj.TsdbQueryResponse{
Start: input.Start,
End: input.End,
}
aggrCounter := make(map[string][]*dataobj.TsdbQueryResponse)
if len(input.GroupKey) == 0 || getTags(resp[0].Counter) == "" {
aggrData := &dataobj.TsdbQueryResponse{
Start: input.Start,
End: input.End,
Values: calc.Compute(input.AggrFunc, resp),
}
//没有聚合 tag, 或者曲线没有其他 tags, 直接所有曲线进行计算
aggrData.Values = calc.Compute(input.AggrFunc, resp)
aggrDatas = append(aggrDatas, aggrData)
} else {
for _, data := range resp {
@ -133,9 +133,12 @@ func FetchDataForUI(input dataobj.QueryDataForUI) []*dataobj.TsdbQueryResponse {
}
for counter, datas := range aggrCounter {
aggrData.Counter = counter
aggrData.Values = calc.Compute(input.AggrFunc, datas)
aggrData := &dataobj.TsdbQueryResponse{
Start: input.Start,
End: input.End,
Counter: counter,
Values: calc.Compute(input.AggrFunc, datas),
}
aggrDatas = append(aggrDatas, aggrData)
}
}