mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-16 05:36:36 +08:00
对服务增加基础的数据统计
This commit is contained in:
@@ -70,10 +70,10 @@ func (this *UpdateSchedulingPopupAction) RunGet(params struct {
|
||||
if !types.IsSlice(networks) {
|
||||
continue
|
||||
}
|
||||
if (serverConfig.IsHTTP() && lists.Contains(networks, "http")) ||
|
||||
(serverConfig.IsTCP() && lists.Contains(networks, "tcp")) ||
|
||||
(serverConfig.IsUDP() && lists.Contains(networks, "udp")) ||
|
||||
(serverConfig.IsUnix() && lists.Contains(networks, "unix")) {
|
||||
if (serverConfig.IsHTTPFamily() && lists.Contains(networks, "http")) ||
|
||||
(serverConfig.IsTCPFamily() && lists.Contains(networks, "tcp")) ||
|
||||
(serverConfig.IsUDPFamily() && lists.Contains(networks, "udp")) ||
|
||||
(serverConfig.IsUnixFamily() && lists.Contains(networks, "unix")) {
|
||||
schedulingTypes = append(schedulingTypes, m)
|
||||
}
|
||||
}
|
||||
|
||||
110
internal/web/actions/default/servers/server/stat/clients.go
Normal file
110
internal/web/actions/default/servers/server/stat/clients.go
Normal 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,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
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,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["systemStats"] = systemMaps
|
||||
this.Data["browserStats"] = browserMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -1,6 +1,13 @@
|
||||
package stat
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
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 IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
@@ -11,6 +18,133 @@ func (this *IndexAction) Init() {
|
||||
this.SecondMenu("index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
func (this *IndexAction) 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
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ func init() {
|
||||
Helper(serverutils.NewServerHelper()).
|
||||
Prefix("/servers/server/stat").
|
||||
Get("", new(IndexAction)).
|
||||
Get("/providers", new(ProvidersAction)).
|
||||
Get("/clients", new(ClientsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -77,13 +77,13 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
|
||||
|
||||
// 协议簇
|
||||
family := ""
|
||||
if serverConfig.IsHTTP() {
|
||||
if serverConfig.IsHTTPFamily() {
|
||||
family = "http"
|
||||
} else if serverConfig.IsTCP() {
|
||||
} else if serverConfig.IsTCPFamily() {
|
||||
family = "tcp"
|
||||
} else if serverConfig.IsUnix() {
|
||||
} else if serverConfig.IsUnixFamily() {
|
||||
family = "unix"
|
||||
} else if serverConfig.IsUDP() {
|
||||
} else if serverConfig.IsUDPFamily() {
|
||||
family = "udp"
|
||||
}
|
||||
action.Data["serverFamily"] = family
|
||||
@@ -94,7 +94,9 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
|
||||
tabbar.Add("服务列表", "", "/servers", "", false)
|
||||
//tabbar.Add("看板", "", "/servers/server/board?serverId="+serverIdString, "dashboard", selectedTabbar == "board")
|
||||
tabbar.Add("日志", "", "/servers/server/log?serverId="+serverIdString, "history", selectedTabbar == "log")
|
||||
//tabbar.Add("统计", "", "/servers/server/stat?serverId="+serverIdString, "chart area", selectedTabbar == "stat")
|
||||
if family == "http" {
|
||||
tabbar.Add("统计", "", "/servers/server/stat?serverId="+serverIdString, "chart area", selectedTabbar == "stat")
|
||||
}
|
||||
tabbar.Add("设置", "", "/servers/server/settings?serverId="+serverIdString, "setting", selectedTabbar == "setting")
|
||||
tabbar.Add("删除", "", "/servers/server/delete?serverId="+serverIdString, "trash", selectedTabbar == "delete")
|
||||
{
|
||||
@@ -155,10 +157,20 @@ func (this *ServerHelper) createLogMenu(secondMenuItem string, serverIdString st
|
||||
func (this *ServerHelper) createStatMenu(secondMenuItem string, serverIdString string, serverConfig *serverconfigs.ServerConfig) []maps.Map {
|
||||
menuItems := []maps.Map{}
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "统计",
|
||||
"name": "地域分布",
|
||||
"url": "/servers/server/stat?serverId=" + serverIdString,
|
||||
"isActive": secondMenuItem == "index",
|
||||
})
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "运营商",
|
||||
"url": "/servers/server/stat/providers?serverId=" + serverIdString,
|
||||
"isActive": secondMenuItem == "provider",
|
||||
})
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "终端",
|
||||
"url": "/servers/server/stat/clients?serverId=" + serverIdString,
|
||||
"isActive": secondMenuItem == "client",
|
||||
})
|
||||
return menuItems
|
||||
}
|
||||
|
||||
@@ -179,7 +191,7 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
||||
}
|
||||
|
||||
// HTTP
|
||||
if serverConfig.IsHTTP() {
|
||||
if serverConfig.IsHTTPFamily() {
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "域名",
|
||||
"url": "/servers/server/settings/serverNames?serverId=" + serverIdString,
|
||||
@@ -294,7 +306,7 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
||||
"isActive": secondMenuItem == "websocket",
|
||||
"isOn": serverConfig.Web != nil && serverConfig.Web.WebsocketRef != nil && serverConfig.Web.WebsocketRef.IsOn,
|
||||
})
|
||||
} else if serverConfig.IsTCP() {
|
||||
} else if serverConfig.IsTCPFamily() {
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "TCP",
|
||||
"url": "/servers/server/settings/tcp?serverId=" + serverIdString,
|
||||
@@ -313,14 +325,14 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
||||
"isActive": secondMenuItem == "reverseProxy",
|
||||
"isOn": serverConfig.ReverseProxyRef != nil && serverConfig.ReverseProxyRef.IsOn,
|
||||
})
|
||||
} else if serverConfig.IsUnix() {
|
||||
} else if serverConfig.IsUnixFamily() {
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "Unix",
|
||||
"url": "/servers/server/settings/unix?serverId=" + serverIdString,
|
||||
"isActive": secondMenuItem == "unix",
|
||||
"isOn": serverConfig.Unix != nil && serverConfig.Unix.IsOn && len(serverConfig.Unix.Listen) > 0,
|
||||
})
|
||||
} else if serverConfig.IsUDP() {
|
||||
} else if serverConfig.IsUDPFamily() {
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "UDP",
|
||||
"url": "/servers/server/settings/udp?serverId=" + serverIdString,
|
||||
|
||||
Reference in New Issue
Block a user