mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-25 11:36:34 +08:00
请求统计增加即时、按天
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// 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 DailyRequestsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DailyRequestsAction) Init() {
|
||||
this.Nav("", "stat", "daily")
|
||||
this.SecondMenu("index")
|
||||
}
|
||||
|
||||
func (this *DailyRequestsAction) RunGet(params struct {
|
||||
ServerId int64
|
||||
}) {
|
||||
this.Data["serverId"] = params.ServerId
|
||||
|
||||
resp, err := this.RPC().ServerDailyStatRPC().FindLatestServerDailyStats(this.AdminContext(), &pb.FindLatestServerDailyStatsRequest{
|
||||
ServerId: params.ServerId,
|
||||
Days: 30,
|
||||
})
|
||||
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.Day < stat2.Day
|
||||
})
|
||||
statMaps := []maps.Map{}
|
||||
for _, stat := range resp.Stats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"day": stat.Day[:4] + "-" + stat.Day[4:6] + "-" + stat.Day[6:8],
|
||||
"bytes": stat.Bytes,
|
||||
"cachedBytes": stat.CachedBytes,
|
||||
"countRequests": stat.CountRequests,
|
||||
"countCachedRequests": stat.CountCachedRequests,
|
||||
})
|
||||
}
|
||||
this.Data["dailyStats"] = statMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// 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 HourlyRequestsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *HourlyRequestsAction) Init() {
|
||||
this.Nav("", "stat", "hourly")
|
||||
this.SecondMenu("index")
|
||||
}
|
||||
|
||||
func (this *HourlyRequestsAction) RunGet(params struct {
|
||||
ServerId int64
|
||||
}) {
|
||||
this.Data["serverId"] = params.ServerId
|
||||
|
||||
resp, err := this.RPC().ServerDailyStatRPC().FindLatestServerHourlyStats(this.AdminContext(), &pb.FindLatestServerHourlyStatsRequest{
|
||||
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()
|
||||
}
|
||||
@@ -14,41 +14,41 @@ type IndexAction struct {
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "stat", "")
|
||||
this.Nav("", "stat", "minutely")
|
||||
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
|
||||
}
|
||||
this.Data["serverId"] = params.ServerId
|
||||
|
||||
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
|
||||
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,
|
||||
})
|
||||
}
|
||||
this.Data["minutelyStats"] = statMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ func init() {
|
||||
Helper(serverutils.NewServerHelper()).
|
||||
Prefix("/servers/server/stat").
|
||||
Get("", new(IndexAction)).
|
||||
Get("/hourlyRequests", new(HourlyRequestsAction)).
|
||||
Get("/dailyRequests", new(DailyRequestsAction)).
|
||||
Get("/regions", new(RegionsAction)).
|
||||
Get("/providers", new(ProvidersAction)).
|
||||
Get("/clients", new(ClientsAction)).
|
||||
|
||||
Reference in New Issue
Block a user