mirror of
https://github.com/zhengkai/orca.git
synced 2026-02-12 15:42:27 +08:00
up
This commit is contained in:
53
server/src/st/date-histogram.go
Normal file
53
server/src/st/date-histogram.go
Normal file
@@ -0,0 +1,53 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user