Files
orca/server/src/st/date-histogram.go
Zheng Kai 05fe88de8b up
2023-06-16 16:17:42 +08:00

54 lines
995 B
Go

package st
import (
"fmt"
"project/es"
"project/pb"
"project/zj"
_ "embed" //
"github.com/zhengkai/zu"
)
//go:embed tpl/date-histogram.json
var queryDateHistogramTpl string
// DateHistogram ...
func DateHistogram() {
query := fmt.Sprintf(
queryDateHistogramTpl,
`now-24h`,
`now`,
)
d := &pb.EsResultDateHistogram{}
err := es.Search(query, d)
if err != nil {
zj.W(`fail`, err)
return
}
li := d.GetAggregations().GetBytesSum().GetBuckets()
if len(li) == 0 {
return
}
re := make([]*pb.EsDateHistogram, len(li))
for i, v := range li {
re[i] = &pb.EsDateHistogram{
Ts: uint32(v.GetKey() / 1000),
ReqBytes: v.GetReqBytes().GetValue(),
RspBytes: v.GetRspBytes().GetValue(),
TokenTotal: v.GetTokenTotal().GetValue(),
TokenCompletion: v.GetTokenCompletion().GetValue(),
TokenPrompt: v.GetTokenPrompt().GetValue(),
}
}
j := zu.JSONPretty(re)
// util.WriteFile(`date-histogram.json`, []byte(j))
zj.J(j)
}