Files
EdgeAdmin/internal/web/actions/default/servers/server/stat/index.go

55 lines
1.4 KiB
Go
Raw Normal View History

2021-06-08 11:22:44 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2020-08-21 12:32:16 +08:00
package stat
2021-01-25 16:40:49 +08:00
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
2021-06-08 11:22:44 +08:00
"sort"
2021-01-25 16:40:49 +08:00
)
2020-08-21 12:32:16 +08:00
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
2021-06-08 15:08:38 +08:00
this.Nav("", "stat", "minutely")
2020-08-21 21:09:42 +08:00
this.SecondMenu("index")
2020-08-21 12:32:16 +08:00
}
2021-01-25 16:40:49 +08:00
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
2021-06-08 15:08:38 +08:00
this.Data["serverId"] = params.ServerId
resp, err := this.RPC().ServerDailyStatRPC().FindLatestServerMinutelyStats(this.AdminContext(), &pb.FindLatestServerMinutelyStatsRequest{
ServerId: params.ServerId,
Minutes: 120,
})
if err != nil {
this.ErrorPage(err)
return
}
sort.Slice(resp.Stats, func(i, j int) bool {
stat1 := resp.Stats[i]
stat2 := resp.Stats[j]
return stat1.Minute < stat2.Minute
})
statMaps := []maps.Map{}
for _, stat := range resp.Stats {
statMaps = append(statMaps, maps.Map{
"day": stat.Minute[:4] + "-" + stat.Minute[4:6] + "-" + stat.Minute[6:8],
"minute": stat.Minute[8:10] + ":" + stat.Minute[10:12],
"bytes": stat.Bytes,
"cachedBytes": stat.CachedBytes,
"countRequests": stat.CountRequests,
"countCachedRequests": stat.CountCachedRequests,
2021-06-08 11:22:44 +08:00
})
2021-05-03 15:15:31 +08:00
}
2021-06-08 15:08:38 +08:00
this.Data["minutelyStats"] = statMaps
2021-05-03 15:15:31 +08:00
2020-08-21 12:32:16 +08:00
this.Show()
}