Files
EdgeAdmin/internal/web/actions/default/ns/index.go

128 lines
3.1 KiB
Go
Raw Normal View History

2021-08-10 10:47:12 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2021-05-25 15:47:40 +08:00
package ns
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2021-05-27 17:09:53 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
2021-08-10 10:47:12 +08:00
"github.com/iwind/TeaGo/types"
timeutil "github.com/iwind/TeaGo/utils/time"
2021-05-25 15:47:40 +08:00
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
2021-08-10 10:47:12 +08:00
this.Nav("", "", "dns")
2021-05-25 15:47:40 +08:00
}
2021-08-10 10:47:12 +08:00
func (this *IndexAction) RunGet(params struct{}) {
resp, err := this.RPC().NSRPC().ComposeNSBoard(this.AdminContext(), &pb.ComposeNSBoardRequest{})
if err != nil {
this.ErrorPage(err)
2021-07-13 14:28:06 +08:00
return
}
2021-08-10 10:47:12 +08:00
this.Data["board"] = maps.Map{
"countDomains": resp.CountNSDomains,
"countRecords": resp.CountNSRecords,
"countClusters": resp.CountNSClusters,
"countNodes": resp.CountNSNodes,
"countOfflineNodes": resp.CountOfflineNSNodes,
}
2021-07-13 14:28:06 +08:00
2021-08-10 10:47:12 +08:00
// 流量排行
{
var statMaps = []maps.Map{}
for _, stat := range resp.HourlyTrafficStats {
statMaps = append(statMaps, maps.Map{
"day": stat.Hour[4:6] + "月" + stat.Hour[6:8] + "日",
"hour": stat.Hour[8:],
"countRequests": stat.CountRequests,
"bytes": stat.Bytes,
})
}
this.Data["hourlyStats"] = statMaps
}
2021-05-27 17:09:53 +08:00
2021-08-10 10:47:12 +08:00
{
var statMaps = []maps.Map{}
for _, stat := range resp.DailyTrafficStats {
statMaps = append(statMaps, maps.Map{
"day": stat.Day[4:6] + "月" + stat.Day[6:] + "日",
"countRequests": stat.CountRequests,
"bytes": stat.Bytes,
})
}
this.Data["dailyStats"] = statMaps
2021-05-27 17:09:53 +08:00
}
2021-08-10 10:47:12 +08:00
// 域名排行
{
var statMaps = []maps.Map{}
for _, stat := range resp.TopNSDomainStats {
statMaps = append(statMaps, maps.Map{
"domainId": stat.NsDomainId,
"domainName": stat.NsDomainName,
"countRequests": stat.CountRequests,
"bytes": stat.Bytes,
})
}
this.Data["topDomainStats"] = statMaps
2021-05-27 17:09:53 +08:00
}
2021-08-10 10:47:12 +08:00
// 节点排行
{
var statMaps = []maps.Map{}
for _, stat := range resp.TopNSNodeStats {
statMaps = append(statMaps, maps.Map{
"clusterId": stat.NsClusterId,
"nodeId": stat.NsNodeId,
"nodeName": stat.NsNodeName,
"countRequests": stat.CountRequests,
"bytes": stat.Bytes,
})
}
this.Data["topNodeStats"] = statMaps
2021-05-27 17:09:53 +08:00
}
2021-08-10 10:47:12 +08:00
// CPU
{
var statMaps = []maps.Map{}
for _, stat := range resp.CpuNodeValues {
statMaps = append(statMaps, maps.Map{
"time": timeutil.FormatTime("H:i", stat.CreatedAt),
"value": types.Float32(string(stat.ValueJSON)),
})
2021-05-27 17:09:53 +08:00
}
2021-08-10 10:47:12 +08:00
this.Data["cpuValues"] = statMaps
}
2021-05-27 17:09:53 +08:00
2021-08-10 10:47:12 +08:00
// Memory
{
var statMaps = []maps.Map{}
for _, stat := range resp.MemoryNodeValues {
statMaps = append(statMaps, maps.Map{
"time": timeutil.FormatTime("H:i", stat.CreatedAt),
"value": types.Float32(string(stat.ValueJSON)),
})
2021-05-27 17:09:53 +08:00
}
2021-08-10 10:47:12 +08:00
this.Data["memoryValues"] = statMaps
}
2021-05-27 17:09:53 +08:00
2021-08-10 10:47:12 +08:00
// Load
{
var statMaps = []maps.Map{}
for _, stat := range resp.LoadNodeValues {
statMaps = append(statMaps, maps.Map{
"time": timeutil.FormatTime("H:i", stat.CreatedAt),
"value": types.Float32(string(stat.ValueJSON)),
})
}
this.Data["loadValues"] = statMaps
2021-05-27 17:09:53 +08:00
}
2021-05-25 15:47:40 +08:00
this.Show()
}