2020-07-22 22:19:39 +08:00
|
|
|
package dashboard
|
|
|
|
|
|
2020-12-02 23:47:50 +08:00
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
2021-01-21 18:55:53 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
2020-12-02 23:47:50 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2021-01-21 18:55:53 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
"math"
|
|
|
|
|
"regexp"
|
2020-12-02 23:47:50 +08:00
|
|
|
)
|
2020-07-22 22:19:39 +08:00
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.Nav("", "", "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct{}) {
|
2020-12-02 23:47:50 +08:00
|
|
|
// 取得用户的权限
|
|
|
|
|
module, ok := configloaders.FindFirstAdminModule(this.AdminId())
|
|
|
|
|
if ok {
|
2021-01-21 18:55:53 +08:00
|
|
|
if module != "dashboard" {
|
|
|
|
|
for _, m := range configloaders.AllModuleMaps() {
|
|
|
|
|
if m.GetString("code") == module {
|
|
|
|
|
this.RedirectURL(m.GetString("url"))
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-12-02 23:47:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 11:03:12 +08:00
|
|
|
|
2021-01-21 18:55:53 +08:00
|
|
|
// 读取看板数据
|
|
|
|
|
resp, err := this.RPC().AdminRPC().ComposeAdminDashboard(this.AdminContext(), &pb.ComposeAdminDashboardRequest{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.Data["dashboard"] = maps.Map{
|
|
|
|
|
"countServers": resp.CountServers,
|
|
|
|
|
"countNodeClusters": resp.CountNodeClusters,
|
|
|
|
|
"countNodes": resp.CountNodes,
|
|
|
|
|
"countUsers": resp.CountUsers,
|
|
|
|
|
"countAPINodes": resp.CountAPINodes,
|
|
|
|
|
"countDBNodes": resp.CountDBNodes,
|
|
|
|
|
"countUserNodes": resp.CountUserNodes,
|
2021-01-21 19:22:06 +08:00
|
|
|
|
|
|
|
|
"canGoServers": configloaders.AllowModule(this.AdminId(), configloaders.AdminModuleCodeServer),
|
|
|
|
|
"canGoNodes": configloaders.AllowModule(this.AdminId(), configloaders.AdminModuleCodeNode),
|
|
|
|
|
"canGoSettings": configloaders.AllowModule(this.AdminId(), configloaders.AdminModuleCodeSetting),
|
|
|
|
|
"canGoUsers": configloaders.AllowModule(this.AdminId(), configloaders.AdminModuleCodeUser),
|
2021-01-21 18:55:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 今日流量
|
|
|
|
|
todayTrafficBytes := int64(0)
|
|
|
|
|
if len(resp.DailyTrafficStats) > 0 {
|
|
|
|
|
todayTrafficBytes = resp.DailyTrafficStats[len(resp.DailyTrafficStats)-1].Bytes
|
|
|
|
|
}
|
|
|
|
|
todayTrafficString := numberutils.FormatBits(todayTrafficBytes * 8)
|
|
|
|
|
result := regexp.MustCompile(`^(?U)(.+)([a-zA-Z]+)$`).FindStringSubmatch(todayTrafficString)
|
|
|
|
|
if len(result) > 2 {
|
|
|
|
|
this.Data["todayTraffic"] = result[1]
|
|
|
|
|
this.Data["todayTrafficUnit"] = result[2]
|
|
|
|
|
} else {
|
|
|
|
|
this.Data["todayTraffic"] = todayTrafficString
|
|
|
|
|
this.Data["todayTrafficUnit"] = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 24小时流量趋势
|
|
|
|
|
{
|
|
|
|
|
statMaps := []maps.Map{}
|
|
|
|
|
for _, stat := range resp.HourlyTrafficStats {
|
|
|
|
|
statMaps = append(statMaps, maps.Map{
|
|
|
|
|
"count": math.Ceil((float64(stat.Bytes)*8/1000/1000/1000)*1000) / 1000,
|
|
|
|
|
"hour": stat.Hour[8:],
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["hourlyTrafficStats"] = statMaps
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 15天流量趋势
|
|
|
|
|
{
|
|
|
|
|
statMaps := []maps.Map{}
|
|
|
|
|
for _, stat := range resp.DailyTrafficStats {
|
|
|
|
|
statMaps = append(statMaps, maps.Map{
|
|
|
|
|
"count": math.Ceil((float64(stat.Bytes)*8/1000/1000/1000)*1000) / 1000,
|
|
|
|
|
"day": stat.Day[4:6] + "月" + stat.Day[6:] + "日",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["dailyTrafficStats"] = statMaps
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 22:47:21 +08:00
|
|
|
// 版本升级
|
|
|
|
|
this.Data["nodeUpgradeInfo"] = maps.Map{
|
|
|
|
|
"count": resp.NodeUpgradeInfo.CountNodes,
|
|
|
|
|
"version": resp.NodeUpgradeInfo.NewVersion,
|
|
|
|
|
}
|
|
|
|
|
this.Data["monitorNodeUpgradeInfo"] = maps.Map{
|
|
|
|
|
"count": resp.MonitorNodeUpgradeInfo.CountNodes,
|
|
|
|
|
"version": resp.MonitorNodeUpgradeInfo.NewVersion,
|
|
|
|
|
}
|
|
|
|
|
this.Data["apiNodeUpgradeInfo"] = maps.Map{
|
|
|
|
|
"count": resp.ApiNodeUpgradeInfo.CountNodes,
|
|
|
|
|
"version": resp.ApiNodeUpgradeInfo.NewVersion,
|
|
|
|
|
}
|
|
|
|
|
this.Data["userNodeUpgradeInfo"] = maps.Map{
|
|
|
|
|
"count": resp.UserNodeUpgradeInfo.CountNodes,
|
|
|
|
|
"version": resp.UserNodeUpgradeInfo.NewVersion,
|
|
|
|
|
}
|
|
|
|
|
this.Data["authorityNodeUpgradeInfo"] = maps.Map{
|
|
|
|
|
"count": resp.AuthorityNodeUpgradeInfo.CountNodes,
|
|
|
|
|
"version": resp.AuthorityNodeUpgradeInfo.NewVersion,
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-03 11:03:12 +08:00
|
|
|
this.Show()
|
2020-07-22 22:19:39 +08:00
|
|
|
}
|