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

55 lines
1.3 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() {
this.Nav("", "stat", "")
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 11:22:44 +08:00
{
resp, err := this.RPC().ServerDailyStatRPC().FindServerHourlyStats(this.AdminContext(), &pb.FindServerHourlyStatsRequest{
ServerId: params.ServerId,
Hours: 24,
})
2021-01-25 16:40:49 +08:00
if err != nil {
this.ErrorPage(err)
return
}
2021-06-08 11:22:44 +08:00
sort.Slice(resp.Stats, func(i, j int) bool {
stat1 := resp.Stats[i]
stat2 := resp.Stats[j]
return stat1.Hour < stat2.Hour
})
statMaps := []maps.Map{}
for _, stat := range resp.Stats {
statMaps = append(statMaps, maps.Map{
"day": stat.Hour[:4] + "-" + stat.Hour[4:6] + "-" + stat.Hour[6:8],
"hour": stat.Hour[8:],
"bytes": stat.Bytes,
"cachedBytes": stat.CachedBytes,
"countRequests": stat.CountRequests,
"countCachedRequests": stat.CountCachedRequests,
2021-01-25 16:40:49 +08:00
})
}
2021-06-08 11:22:44 +08:00
this.Data["hourlyStats"] = statMaps
2021-05-03 15:15:31 +08:00
}
2020-08-21 12:32:16 +08:00
this.Show()
}