// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. package stat import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" "sort" ) type IndexAction struct { actionutils.ParentAction } func (this *IndexAction) Init() { this.Nav("", "stat", "") this.SecondMenu("index") } func (this *IndexAction) RunGet(params struct { ServerId int64 }) { { resp, err := this.RPC().ServerDailyStatRPC().FindServerHourlyStats(this.AdminContext(), &pb.FindServerHourlyStatsRequest{ ServerId: params.ServerId, Hours: 24, }) 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.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, }) } this.Data["hourlyStats"] = statMaps } this.Show() }