Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
package stat
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type ClientsAction struct {
actionutils.ParentAction
}
func (this *ClientsAction) Init() {
this.Nav("", "stat", "")
this.SecondMenu("client")
}
func (this *ClientsAction) RunGet(params struct {
ServerId int64
Month string
}) {
month := params.Month
if len(month) != 6 {
month = timeutil.Format("Ym")
}
this.Data["month"] = month
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
serverType := serverTypeResp.Type
statIsOn := false
// 是否已开启
if serverconfigs.IsHTTPServerType(serverType) {
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
if webConfig != nil && webConfig.StatRef != nil {
statIsOn = webConfig.StatRef.IsOn
}
} else {
this.WriteString("此类型服务暂不支持统计")
return
}
this.Data["statIsOn"] = statIsOn
// 统计数据
systemMaps := []maps.Map{}
browserMaps := []maps.Map{}
if statIsOn {
{
resp, err := this.RPC().ServerClientSystemMonthlyStatRPC().FindTopServerClientSystemMonthlyStats(this.AdminContext(), &pb.FindTopServerClientSystemMonthlyStatsRequest{
ServerId: params.ServerId,
Month: month,
Offset: 0,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
for _, stat := range resp.Stats {
systemMaps = append(systemMaps, maps.Map{
"count": stat.Count,
"system": maps.Map{
"id": stat.ClientSystem.Id,
"name": stat.ClientSystem.Name + " " + stat.Version,
},
})
}
}
{
resp, err := this.RPC().ServerClientBrowserMonthlyStatRPC().FindTopServerClientBrowserMonthlyStats(this.AdminContext(), &pb.FindTopServerClientBrowserMonthlyStatsRequest{
ServerId: params.ServerId,
Month: month,
Offset: 0,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
for _, stat := range resp.Stats {
browserMaps = append(browserMaps, maps.Map{
"count": stat.Count,
"browser": maps.Map{
"id": stat.ClientBrowser.Id,
"name": stat.ClientBrowser.Name + " " + stat.Version,
},
})
}
}
}
this.Data["systemStats"] = systemMaps
this.Data["browserStats"] = browserMaps
this.Show()
}

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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 IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "stat", "minutely")
this.SecondMenu("index")
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
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,
})
}
this.Data["minutelyStats"] = statMaps
this.Show()
}

View File

@@ -0,0 +1,25 @@
package stat
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
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)).
Get("/waf", new(WafAction)).
EndAll()
})
}

View File

@@ -0,0 +1,86 @@
package stat
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type ProvidersAction struct {
actionutils.ParentAction
}
func (this *ProvidersAction) Init() {
this.Nav("", "stat", "")
this.SecondMenu("provider")
}
func (this *ProvidersAction) RunGet(params struct {
ServerId int64
Month string
}) {
month := params.Month
if len(month) != 6 {
month = timeutil.Format("Ym")
}
this.Data["month"] = month
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
serverType := serverTypeResp.Type
statIsOn := false
// 是否已开启
if serverconfigs.IsHTTPServerType(serverType) {
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
if webConfig != nil && webConfig.StatRef != nil {
statIsOn = webConfig.StatRef.IsOn
}
} else {
this.WriteString("此类型服务暂不支持统计")
return
}
this.Data["statIsOn"] = statIsOn
// 统计数据
providerMaps := []maps.Map{}
if statIsOn {
{
resp, err := this.RPC().ServerRegionProviderMonthlyStatRPC().FindTopServerRegionProviderMonthlyStats(this.AdminContext(), &pb.FindTopServerRegionProviderMonthlyStatsRequest{
Month: month,
ServerId: params.ServerId,
Offset: 0,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
for _, stat := range resp.Stats {
providerMaps = append(providerMaps, maps.Map{
"count": stat.Count,
"provider": maps.Map{
"id": stat.RegionProvider.Id,
"name": stat.RegionProvider.Name,
},
})
}
}
}
this.Data["providerStats"] = providerMaps
this.Show()
}

View File

@@ -0,0 +1,160 @@
package stat
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type RegionsAction struct {
actionutils.ParentAction
}
func (this *RegionsAction) Init() {
this.Nav("", "stat", "")
this.SecondMenu("region")
}
func (this *RegionsAction) RunGet(params struct {
ServerId int64
Month string
}) {
month := params.Month
if len(month) != 6 {
month = timeutil.Format("Ym")
}
this.Data["month"] = month
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
serverType := serverTypeResp.Type
statIsOn := false
// 是否已开启
if serverconfigs.IsHTTPServerType(serverType) {
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
if webConfig != nil && webConfig.StatRef != nil {
statIsOn = webConfig.StatRef.IsOn
}
} else {
this.WriteString("此类型服务暂不支持统计")
return
}
this.Data["statIsOn"] = statIsOn
// 统计数据
countryStatMaps := []maps.Map{}
provinceStatMaps := []maps.Map{}
cityStatMaps := []maps.Map{}
if statIsOn {
// 地区
{
resp, err := this.RPC().ServerRegionCountryMonthlyStatRPC().FindTopServerRegionCountryMonthlyStats(this.AdminContext(), &pb.FindTopServerRegionCountryMonthlyStatsRequest{
Month: month,
ServerId: params.ServerId,
Offset: 0,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
for _, stat := range resp.Stats {
countryStatMaps = append(countryStatMaps, maps.Map{
"count": stat.Count,
"country": maps.Map{
"id": stat.RegionCountry.Id,
"name": stat.RegionCountry.Name,
},
})
}
}
// 省份
{
resp, err := this.RPC().ServerRegionProvinceMonthlyStatRPC().FindTopServerRegionProvinceMonthlyStats(this.AdminContext(), &pb.FindTopServerRegionProvinceMonthlyStatsRequest{
Month: month,
ServerId: params.ServerId,
Offset: 0,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
for _, stat := range resp.Stats {
provinceStatMaps = append(provinceStatMaps, maps.Map{
"count": stat.Count,
"country": maps.Map{
"id": stat.RegionCountry.Id,
"name": stat.RegionCountry.Name,
},
"province": maps.Map{
"id": stat.RegionProvince.Id,
"name": stat.RegionProvince.Name,
},
})
}
}
// 城市
{
resp, err := this.RPC().ServerRegionCityMonthlyStatRPC().FindTopServerRegionCityMonthlyStats(this.AdminContext(), &pb.FindTopServerRegionCityMonthlyStatsRequest{
Month: month,
ServerId: params.ServerId,
Offset: 0,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
for _, stat := range resp.Stats {
cityStatMaps = append(cityStatMaps, maps.Map{
"count": stat.Count,
"country": maps.Map{
"id": stat.RegionCountry.Id,
"name": stat.RegionCountry.Name,
},
"province": maps.Map{
"id": stat.RegionProvince.Id,
"name": stat.RegionProvince.Name,
},
"city": maps.Map{
"id": stat.RegionCity.Id,
"name": stat.RegionCity.Name,
},
})
}
}
}
this.Data["countryStats"] = countryStatMaps
this.Data["provinceStats"] = provinceStatMaps
this.Data["cityStats"] = cityStatMaps
// 记录最近使用
_, err = this.RPC().LatestItemRPC().IncreaseLatestItem(this.AdminContext(), &pb.IncreaseLatestItemRequest{
ItemType: "server",
ItemId: params.ServerId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Show()
}

View File

@@ -0,0 +1,78 @@
package stat
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type WafAction struct {
actionutils.ParentAction
}
func (this *WafAction) Init() {
this.Nav("", "stat", "")
this.SecondMenu("waf")
}
func (this *WafAction) RunGet(params struct {
ServerId int64
}) {
// 统计数据
resp, err := this.RPC().ServerHTTPFirewallDailyStatRPC().ComposeServerHTTPFirewallDashboard(this.AdminContext(), &pb.ComposeServerHTTPFirewallDashboardRequest{
Day: timeutil.Format("Ymd"),
ServerId: params.ServerId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["countDailyLog"] = resp.CountDailyLog
this.Data["countDailyBlock"] = resp.CountDailyBlock
this.Data["countDailyCaptcha"] = resp.CountDailyCaptcha
this.Data["countWeeklyBlock"] = resp.CountWeeklyBlock
this.Data["countMonthlyBlock"] = resp.CountMonthlyBlock
// 分组
groupStatMaps := []maps.Map{}
for _, group := range resp.HttpFirewallRuleGroups {
groupStatMaps = append(groupStatMaps, maps.Map{
"group": maps.Map{
"id": group.HttpFirewallRuleGroup.Id,
"name": group.HttpFirewallRuleGroup.Name,
},
"count": group.Count,
})
}
this.Data["groupStats"] = groupStatMaps
// 每日趋势
logStatMaps := []maps.Map{}
blockStatMaps := []maps.Map{}
captchaStatMaps := []maps.Map{}
for _, stat := range resp.LogDailyStats {
logStatMaps = append(logStatMaps, maps.Map{
"day": stat.Day,
"count": stat.Count,
})
}
for _, stat := range resp.BlockDailyStats {
blockStatMaps = append(blockStatMaps, maps.Map{
"day": stat.Day,
"count": stat.Count,
})
}
for _, stat := range resp.CaptchaDailyStats {
captchaStatMaps = append(captchaStatMaps, maps.Map{
"day": stat.Day,
"count": stat.Count,
})
}
this.Data["logDailyStats"] = logStatMaps
this.Data["blockDailyStats"] = blockStatMaps
this.Data["captchaDailyStats"] = captchaStatMaps
this.Show()
}