Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b26287264 | ||
|
|
bac20b1d1f | ||
|
|
904c641992 | ||
|
|
36004bfd94 | ||
|
|
0fcba7e90c | ||
|
|
2e9182933e |
@@ -1,9 +1,9 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.3.7"
|
Version = "0.4.0"
|
||||||
|
|
||||||
APINodeVersion = "0.3.7"
|
APINodeVersion = "0.4.0"
|
||||||
|
|
||||||
ProductName = "Edge Admin"
|
ProductName = "Edge Admin"
|
||||||
ProcessName = "edge-admin"
|
ProcessName = "edge-admin"
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ package teaconst
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
IsRecoverMode = false
|
IsRecoverMode = false
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
IsDemoMode = false
|
IsDemoMode = false
|
||||||
ErrorDemoOperation = "DEMO模式下无法进行创建、修改、删除等操作"
|
ErrorDemoOperation = "DEMO模式下无法进行创建、修改、删除等操作"
|
||||||
|
|
||||||
|
NewVersionCode = "" // 有新的版本
|
||||||
|
NewVersionDownloadURL = "" // 新版本下载地址
|
||||||
)
|
)
|
||||||
|
|||||||
12
internal/goman/instance.go
Normal file
12
internal/goman/instance.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package goman
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Instance struct {
|
||||||
|
Id uint64
|
||||||
|
CreatedTime time.Time
|
||||||
|
File string
|
||||||
|
Line int
|
||||||
|
}
|
||||||
81
internal/goman/lib.go
Normal file
81
internal/goman/lib.go
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package goman
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var locker = &sync.Mutex{}
|
||||||
|
var instanceMap = map[uint64]*Instance{} // id => *Instance
|
||||||
|
var instanceId = uint64(0)
|
||||||
|
|
||||||
|
// New 新创建goroutine
|
||||||
|
func New(f func()) {
|
||||||
|
_, file, line, _ := runtime.Caller(1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
locker.Lock()
|
||||||
|
instanceId++
|
||||||
|
|
||||||
|
var instance = &Instance{
|
||||||
|
Id: instanceId,
|
||||||
|
CreatedTime: time.Now(),
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.File = file
|
||||||
|
instance.Line = line
|
||||||
|
|
||||||
|
instanceMap[instanceId] = instance
|
||||||
|
locker.Unlock()
|
||||||
|
|
||||||
|
// run function
|
||||||
|
f()
|
||||||
|
|
||||||
|
locker.Lock()
|
||||||
|
delete(instanceMap, instanceId)
|
||||||
|
locker.Unlock()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWithArgs 创建带有参数的goroutine
|
||||||
|
func NewWithArgs(f func(args ...interface{}), args ...interface{}) {
|
||||||
|
_, file, line, _ := runtime.Caller(1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
locker.Lock()
|
||||||
|
instanceId++
|
||||||
|
|
||||||
|
var instance = &Instance{
|
||||||
|
Id: instanceId,
|
||||||
|
CreatedTime: time.Now(),
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.File = file
|
||||||
|
instance.Line = line
|
||||||
|
|
||||||
|
instanceMap[instanceId] = instance
|
||||||
|
locker.Unlock()
|
||||||
|
|
||||||
|
// run function
|
||||||
|
f(args...)
|
||||||
|
|
||||||
|
locker.Lock()
|
||||||
|
delete(instanceMap, instanceId)
|
||||||
|
locker.Unlock()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// List 列出所有正在运行goroutine
|
||||||
|
func List() []*Instance {
|
||||||
|
locker.Lock()
|
||||||
|
defer locker.Unlock()
|
||||||
|
|
||||||
|
var result = []*Instance{}
|
||||||
|
for _, instance := range instanceMap {
|
||||||
|
result = append(result, instance)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
28
internal/goman/lib_test.go
Normal file
28
internal/goman/lib_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package goman
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNew(t *testing.T) {
|
||||||
|
New(func() {
|
||||||
|
t.Log("Hello")
|
||||||
|
|
||||||
|
t.Log(List())
|
||||||
|
})
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
t.Log(List())
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewWithArgs(t *testing.T) {
|
||||||
|
NewWithArgs(func(args ...interface{}) {
|
||||||
|
t.Log(args[0], args[1])
|
||||||
|
}, 1, 2)
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
104
internal/tasks/task_check_updates.go
Normal file
104
internal/tasks/task_check_updates.go
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/goman"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
events.On(events.EventStart, func() {
|
||||||
|
var task = NewCheckUpdatesTask()
|
||||||
|
goman.New(func() {
|
||||||
|
task.Start()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckUpdatesTask struct {
|
||||||
|
ticker *time.Ticker
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCheckUpdatesTask() *CheckUpdatesTask {
|
||||||
|
return &CheckUpdatesTask{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CheckUpdatesTask) Start() {
|
||||||
|
this.ticker = time.NewTicker(12 * time.Hour)
|
||||||
|
for range this.ticker.C {
|
||||||
|
err := this.Loop()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[TASK][CHECK_UPDATES_TASK]" + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CheckUpdatesTask) Loop() error {
|
||||||
|
type Response struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 目前支持Linux
|
||||||
|
if runtime.GOOS != "linux" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiURL = teaconst.UpdatesURL
|
||||||
|
apiURL = strings.ReplaceAll(apiURL, "${os}", runtime.GOOS)
|
||||||
|
apiURL = strings.ReplaceAll(apiURL, "${arch}", runtime.GOARCH)
|
||||||
|
resp, err := http.Get(apiURL)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("read api failed: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
}()
|
||||||
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("read api failed: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiResponse = &Response{}
|
||||||
|
err = json.Unmarshal(data, apiResponse)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("decode version data failed: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if apiResponse.Code != 200 {
|
||||||
|
return errors.New("invalid response: " + apiResponse.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
var m = maps.NewMap(apiResponse.Data)
|
||||||
|
var dlHost = m.GetString("host")
|
||||||
|
var versions = m.GetSlice("versions")
|
||||||
|
if len(versions) > 0 {
|
||||||
|
for _, version := range versions {
|
||||||
|
var vMap = maps.NewMap(version)
|
||||||
|
if vMap.GetString("code") == "admin" {
|
||||||
|
var latestVersion = vMap.GetString("version")
|
||||||
|
if stringutil.VersionCompare(teaconst.Version, latestVersion) < 0 {
|
||||||
|
teaconst.NewVersionCode = latestVersion
|
||||||
|
teaconst.NewVersionDownloadURL = dlHost + vMap.GetString("url")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/goman"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
@@ -23,7 +24,9 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
events.On(events.EventStart, func() {
|
events.On(events.EventStart, func() {
|
||||||
task := NewSyncAPINodesTask()
|
task := NewSyncAPINodesTask()
|
||||||
go task.Start()
|
goman.New(func() {
|
||||||
|
task.Start()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package tasks
|
|||||||
import (
|
import (
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/goman"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
|
||||||
@@ -17,7 +18,9 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
events.On(events.EventStart, func() {
|
events.On(events.EventStart, func() {
|
||||||
task := NewSyncClusterTask()
|
task := NewSyncClusterTask()
|
||||||
go task.Start()
|
goman.New(func() {
|
||||||
|
task.Start()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 版本更新
|
||||||
|
this.Data["currentVersionCode"] = teaconst.Version
|
||||||
|
this.Data["newVersionCode"] = teaconst.NewVersionCode
|
||||||
|
this.Data["newVersionDownloadURL"] = teaconst.NewVersionDownloadURL
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,173 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package logs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/lists"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
||||||
"net"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
RequestId string
|
|
||||||
Keyword string
|
|
||||||
Day string
|
|
||||||
}) {
|
|
||||||
day := strings.ReplaceAll(params.Day, "-", "")
|
|
||||||
if !regexp.MustCompile(`^\d{8}$`).MatchString(day) {
|
|
||||||
day = timeutil.Format("Ymd")
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
this.Data["day"] = day[:4] + "-" + day[4:6] + "-" + day[6:]
|
|
||||||
this.Data["path"] = this.Request.URL.Path
|
|
||||||
|
|
||||||
var size = int64(10)
|
|
||||||
|
|
||||||
resp, err := this.RPC().NSAccessLogRPC().ListNSAccessLogs(this.AdminContext(), &pb.ListNSAccessLogsRequest{
|
|
||||||
RequestId: params.RequestId,
|
|
||||||
NsNodeId: 0,
|
|
||||||
NsDomainId: 0,
|
|
||||||
NsRecordId: 0,
|
|
||||||
Size: size,
|
|
||||||
Day: day,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Reverse: false,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ipList := []string{}
|
|
||||||
nodeIds := []int64{}
|
|
||||||
domainIds := []int64{}
|
|
||||||
if len(resp.NsAccessLogs) == 0 {
|
|
||||||
this.Data["accessLogs"] = []interface{}{}
|
|
||||||
} else {
|
|
||||||
this.Data["accessLogs"] = resp.NsAccessLogs
|
|
||||||
for _, accessLog := range resp.NsAccessLogs {
|
|
||||||
// IP
|
|
||||||
if len(accessLog.RemoteAddr) > 0 {
|
|
||||||
// 去掉端口
|
|
||||||
ip, _, err := net.SplitHostPort(accessLog.RemoteAddr)
|
|
||||||
if err == nil {
|
|
||||||
accessLog.RemoteAddr = ip
|
|
||||||
if !lists.ContainsString(ipList, ip) {
|
|
||||||
ipList = append(ipList, ip)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 节点
|
|
||||||
if !lists.ContainsInt64(nodeIds, accessLog.NsNodeId) {
|
|
||||||
nodeIds = append(nodeIds, accessLog.NsNodeId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 域名
|
|
||||||
if !lists.ContainsInt64(domainIds, accessLog.NsDomainId) {
|
|
||||||
domainIds = append(domainIds, accessLog.NsDomainId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["hasMore"] = resp.HasMore
|
|
||||||
this.Data["nextRequestId"] = resp.RequestId
|
|
||||||
|
|
||||||
// 上一个requestId
|
|
||||||
this.Data["hasPrev"] = false
|
|
||||||
this.Data["lastRequestId"] = ""
|
|
||||||
if len(params.RequestId) > 0 {
|
|
||||||
this.Data["hasPrev"] = true
|
|
||||||
prevResp, err := this.RPC().NSAccessLogRPC().ListNSAccessLogs(this.AdminContext(), &pb.ListNSAccessLogsRequest{
|
|
||||||
RequestId: params.RequestId,
|
|
||||||
NsNodeId: 0,
|
|
||||||
NsDomainId: 0,
|
|
||||||
NsRecordId: 0,
|
|
||||||
Day: day,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Size: size,
|
|
||||||
Reverse: true,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if int64(len(prevResp.NsAccessLogs)) == size {
|
|
||||||
this.Data["lastRequestId"] = prevResp.RequestId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据IP查询区域
|
|
||||||
regionMap := map[string]string{} // ip => region
|
|
||||||
if len(ipList) > 0 {
|
|
||||||
resp, err := this.RPC().IPLibraryRPC().LookupIPRegions(this.AdminContext(), &pb.LookupIPRegionsRequest{IpList: ipList})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if resp.IpRegionMap != nil {
|
|
||||||
for ip, region := range resp.IpRegionMap {
|
|
||||||
if len(region.Isp) > 0 {
|
|
||||||
region.Summary += " | " + region.Isp
|
|
||||||
}
|
|
||||||
regionMap[ip] = region.Summary
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["regions"] = regionMap
|
|
||||||
|
|
||||||
// 节点信息
|
|
||||||
nodeMap := map[int64]interface{}{} // node id => { ... }
|
|
||||||
for _, nodeId := range nodeIds {
|
|
||||||
nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: nodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
node := nodeResp.NsNode
|
|
||||||
if node != nil {
|
|
||||||
nodeMap[node.Id] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"cluster": maps.Map{
|
|
||||||
"id": node.NsCluster.Id,
|
|
||||||
"name": node.NsCluster.Name,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["nodes"] = nodeMap
|
|
||||||
|
|
||||||
// 域名信息
|
|
||||||
domainMap := map[int64]interface{}{} // domain id => { ... }
|
|
||||||
for _, domainId := range domainIds {
|
|
||||||
domainResp, err := this.RPC().NSDomainRPC().FindEnabledNSDomain(this.AdminContext(), &pb.FindEnabledNSDomainRequest{NsDomainId: domainId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
domain := domainResp.NsDomain
|
|
||||||
if domain != nil {
|
|
||||||
domainMap[domain.Id] = maps.Map{
|
|
||||||
"id": domain.Id,
|
|
||||||
"name": domain.Name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["domains"] = domainMap
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CreateNodeAction 创建节点
|
|
||||||
type CreateNodeAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateNodeAction) Init() {
|
|
||||||
this.Nav("", "node", "create")
|
|
||||||
this.SecondMenu("nodes")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateNodeAction) RunGet(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateNodeAction) RunPost(params struct {
|
|
||||||
Name string
|
|
||||||
IpAddressesJSON []byte
|
|
||||||
ClusterId int64
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("name", params.Name).
|
|
||||||
Require("请输入节点名称")
|
|
||||||
|
|
||||||
if len(params.IpAddressesJSON) == 0 {
|
|
||||||
this.Fail("请至少添加一个IP地址")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查cluster
|
|
||||||
if params.ClusterId <= 0 {
|
|
||||||
this.Fail("请选择所在集群")
|
|
||||||
}
|
|
||||||
clusterResp, err := this.RPC().NSClusterRPC().FindEnabledNSCluster(this.AdminContext(), &pb.FindEnabledNSClusterRequest{NsClusterId: params.ClusterId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if clusterResp.NsCluster == nil {
|
|
||||||
this.Fail("选择的集群不存在")
|
|
||||||
}
|
|
||||||
|
|
||||||
// IP地址
|
|
||||||
ipAddresses := []maps.Map{}
|
|
||||||
if len(params.IpAddressesJSON) > 0 {
|
|
||||||
err := json.Unmarshal(params.IpAddressesJSON, &ipAddresses)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(ipAddresses) == 0 {
|
|
||||||
this.Fail("请至少输入一个IP地址")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存
|
|
||||||
createResp, err := this.RPC().NSNodeRPC().CreateNSNode(this.AdminContext(), &pb.CreateNSNodeRequest{
|
|
||||||
Name: params.Name,
|
|
||||||
NodeClusterId: params.ClusterId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
nodeId := createResp.NsNodeId
|
|
||||||
|
|
||||||
// IP地址
|
|
||||||
for _, addrMap := range ipAddresses {
|
|
||||||
addressId := addrMap.GetInt64("id")
|
|
||||||
if addressId > 0 {
|
|
||||||
_, err = this.RPC().NodeIPAddressRPC().UpdateNodeIPAddressNodeId(this.AdminContext(), &pb.UpdateNodeIPAddressNodeIdRequest{
|
|
||||||
NodeIPAddressId: addressId,
|
|
||||||
NodeId: nodeId,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
var ipStrings = addrMap.GetString("ip")
|
|
||||||
result, _ := utils.ExtractIP(ipStrings)
|
|
||||||
|
|
||||||
if len(result) == 1 {
|
|
||||||
// 单个创建
|
|
||||||
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
|
||||||
NodeId: nodeId,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
Name: addrMap.GetString("name"),
|
|
||||||
Ip: result[0],
|
|
||||||
CanAccess: addrMap.GetBool("canAccess"),
|
|
||||||
IsUp: addrMap.GetBool("isUp"),
|
|
||||||
})
|
|
||||||
} else if len(result) > 1 {
|
|
||||||
// 批量创建
|
|
||||||
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddresses(this.AdminContext(), &pb.CreateNodeIPAddressesRequest{
|
|
||||||
NodeId: nodeId,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
Name: addrMap.GetString("name"),
|
|
||||||
IpList: result,
|
|
||||||
CanAccess: addrMap.GetBool("canAccess"),
|
|
||||||
IsUp: addrMap.GetBool("isUp"),
|
|
||||||
GroupValue: ipStrings,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建域名服务节点 %d", nodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DeleteAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteAction) Init() {
|
|
||||||
this.Nav("", "delete", "index")
|
|
||||||
this.SecondMenu("nodes")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteAction) RunGet(params struct{}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteAction) RunPost(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
}) {
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "删除域名服务集群 %d", params.ClusterId)
|
|
||||||
|
|
||||||
// TODO 如果有用户在使用此集群,就不能删除
|
|
||||||
|
|
||||||
// 删除
|
|
||||||
_, err := this.RPC().NSClusterRPC().DeleteNSCluster(this.AdminContext(), &pb.DeleteNSCluster{NsClusterId: params.ClusterId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DeleteNodeAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteNodeAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
defer this.CreateLogInfo("删除域名服务节点 %d", params.NodeId)
|
|
||||||
|
|
||||||
_, err := this.RPC().NSNodeRPC().DeleteNSNode(this.AdminContext(), &pb.DeleteNSNodeRequest{NsNodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/logs"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"github.com/iwind/TeaGo/types"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "node", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
InstalledState int
|
|
||||||
ActiveState int
|
|
||||||
Keyword string
|
|
||||||
}) {
|
|
||||||
this.Data["installState"] = params.InstalledState
|
|
||||||
this.Data["activeState"] = params.ActiveState
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
|
|
||||||
countAllResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{
|
|
||||||
NsClusterId: params.ClusterId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.Data["countAll"] = countAllResp.Count
|
|
||||||
|
|
||||||
countResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{
|
|
||||||
NsClusterId: params.ClusterId,
|
|
||||||
InstallState: types.Int32(params.InstalledState),
|
|
||||||
ActiveState: types.Int32(params.ActiveState),
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
page := this.NewPage(countResp.Count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
nodesResp, err := this.RPC().NSNodeRPC().ListEnabledNSNodesMatch(this.AdminContext(), &pb.ListEnabledNSNodesMatchRequest{
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
NsClusterId: params.ClusterId,
|
|
||||||
InstallState: types.Int32(params.InstalledState),
|
|
||||||
ActiveState: types.Int32(params.ActiveState),
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
nodeMaps := []maps.Map{}
|
|
||||||
for _, node := range nodesResp.NsNodes {
|
|
||||||
// 状态
|
|
||||||
status := &nodeconfigs.NodeStatus{}
|
|
||||||
if len(node.StatusJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.StatusJSON, &status)
|
|
||||||
if err != nil {
|
|
||||||
logs.Error(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
|
|
||||||
}
|
|
||||||
|
|
||||||
// IP
|
|
||||||
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledNodeIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledNodeIPAddressesWithNodeIdRequest{
|
|
||||||
NodeId: node.Id,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ipAddresses := []maps.Map{}
|
|
||||||
for _, addr := range ipAddressesResp.NodeIPAddresses {
|
|
||||||
ipAddresses = append(ipAddresses, maps.Map{
|
|
||||||
"id": addr.Id,
|
|
||||||
"name": addr.Name,
|
|
||||||
"ip": addr.Ip,
|
|
||||||
"canAccess": addr.CanAccess,
|
|
||||||
"isOn": addr.IsOn,
|
|
||||||
"isUp": addr.IsUp,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeMaps = append(nodeMaps, maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"isInstalled": node.IsInstalled,
|
|
||||||
"isOn": node.IsOn,
|
|
||||||
"isUp": node.IsUp,
|
|
||||||
"installStatus": maps.Map{
|
|
||||||
"isRunning": node.InstallStatus.IsRunning,
|
|
||||||
"isFinished": node.InstallStatus.IsFinished,
|
|
||||||
"isOk": node.InstallStatus.IsOk,
|
|
||||||
"error": node.InstallStatus.Error,
|
|
||||||
},
|
|
||||||
"status": maps.Map{
|
|
||||||
"isActive": node.IsActive,
|
|
||||||
"updatedAt": status.UpdatedAt,
|
|
||||||
"hostname": status.Hostname,
|
|
||||||
"cpuUsage": status.CPUUsage,
|
|
||||||
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
|
||||||
"memUsage": status.MemoryUsage,
|
|
||||||
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
|
||||||
},
|
|
||||||
"ipAddresses": ipAddresses,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["nodes"] = nodeMaps
|
|
||||||
|
|
||||||
// 记录最近访问
|
|
||||||
_, err = this.RPC().LatestItemRPC().IncreaseLatestItem(this.AdminContext(), &pb.IncreaseLatestItemRequest{
|
|
||||||
ItemType: "nsCluster",
|
|
||||||
ItemId: params.ClusterId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateNodeSSHAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateNodeSSHAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateNodeSSHAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if nodeResp.NsNode == nil {
|
|
||||||
this.NotFound("node", params.NodeId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
node := nodeResp.NsNode
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
}
|
|
||||||
|
|
||||||
if nodeResp.NsNode.NsCluster != nil {
|
|
||||||
this.Data["clusterId"] = nodeResp.NsNode.NsCluster.Id
|
|
||||||
} else {
|
|
||||||
this.Data["clusterId"] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// SSH
|
|
||||||
loginParams := maps.Map{
|
|
||||||
"host": "",
|
|
||||||
"port": "",
|
|
||||||
"grantId": 0,
|
|
||||||
}
|
|
||||||
this.Data["loginId"] = 0
|
|
||||||
if node.NodeLogin != nil {
|
|
||||||
this.Data["loginId"] = node.NodeLogin.Id
|
|
||||||
if len(node.NodeLogin.Params) > 0 {
|
|
||||||
err = json.Unmarshal(node.NodeLogin.Params, &loginParams)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["params"] = loginParams
|
|
||||||
|
|
||||||
// 认证信息
|
|
||||||
grantId := loginParams.GetInt64("grantId")
|
|
||||||
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
}
|
|
||||||
var grantMap maps.Map = nil
|
|
||||||
if grantResp.NodeGrant != nil {
|
|
||||||
grantMap = maps.Map{
|
|
||||||
"id": grantResp.NodeGrant.Id,
|
|
||||||
"name": grantResp.NodeGrant.Name,
|
|
||||||
"method": grantResp.NodeGrant.Method,
|
|
||||||
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["grant"] = grantMap
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateNodeSSHAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
LoginId int64
|
|
||||||
SshHost string
|
|
||||||
SshPort int
|
|
||||||
GrantId int64
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("sshHost", params.SshHost).
|
|
||||||
Require("请输入SSH主机地址").
|
|
||||||
Field("sshPort", params.SshPort).
|
|
||||||
Gt(0, "SSH主机端口需要大于0").
|
|
||||||
Lt(65535, "SSH主机端口需要小于65535")
|
|
||||||
|
|
||||||
if params.GrantId <= 0 {
|
|
||||||
this.Fail("需要选择或填写至少一个认证信息")
|
|
||||||
}
|
|
||||||
|
|
||||||
login := &pb.NodeLogin{
|
|
||||||
Id: params.LoginId,
|
|
||||||
Name: "SSH",
|
|
||||||
Type: "ssh",
|
|
||||||
Params: maps.Map{
|
|
||||||
"grantId": params.GrantId,
|
|
||||||
"host": params.SshHost,
|
|
||||||
"port": params.SshPort,
|
|
||||||
}.AsJSON(),
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := this.RPC().NSNodeRPC().UpdateNSNodeLogin(this.AdminContext(), &pb.UpdateNSNodeLoginRequest{
|
|
||||||
NsNodeId: params.NodeId,
|
|
||||||
NodeLogin: login,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "修改节点 %d 配置", params.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package cluster
|
|
||||||
|
|
||||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
|
|
||||||
type UpgradeRemoteAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpgradeRemoteAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpgradeRemoteAction) RunGet(params struct{}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
package clusterutils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/logs"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ClusterHelper 单个集群的帮助
|
|
||||||
type ClusterHelper struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClusterHelper() *ClusterHelper {
|
|
||||||
return &ClusterHelper{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) {
|
|
||||||
action := actionPtr.Object()
|
|
||||||
if action.Request.Method != http.MethodGet {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
action.Data["teaMenu"] = "ns"
|
|
||||||
|
|
||||||
selectedTabbar := action.Data.GetString("mainTab")
|
|
||||||
clusterId := action.ParamInt64("clusterId")
|
|
||||||
clusterIdString := strconv.FormatInt(clusterId, 10)
|
|
||||||
action.Data["clusterId"] = clusterId
|
|
||||||
|
|
||||||
if clusterId > 0 {
|
|
||||||
rpcClient, err := rpc.SharedRPC()
|
|
||||||
if err != nil {
|
|
||||||
logs.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clusterResp, err := rpcClient.NSClusterRPC().FindEnabledNSCluster(actionPtr.(actionutils.ActionInterface).AdminContext(), &pb.FindEnabledNSClusterRequest{
|
|
||||||
NsClusterId: clusterId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logs.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cluster := clusterResp.NsCluster
|
|
||||||
if cluster == nil {
|
|
||||||
action.WriteString("can not find ns cluster")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tabbar := actionutils.NewTabbar()
|
|
||||||
tabbar.Add("集群列表", "", "/ns/clusters", "", false)
|
|
||||||
tabbar.Add("集群节点", "", "/ns/clusters/cluster?clusterId="+clusterIdString, "server", selectedTabbar == "node")
|
|
||||||
tabbar.Add("集群设置", "", "/ns/clusters/cluster/settings?clusterId="+clusterIdString, "setting", selectedTabbar == "setting")
|
|
||||||
tabbar.Add("删除集群", "", "/ns/clusters/cluster/delete?clusterId="+clusterIdString, "trash", selectedTabbar == "delete")
|
|
||||||
|
|
||||||
{
|
|
||||||
m := tabbar.Add("当前集群:"+cluster.Name, "", "/ns/clusters/cluster?clusterId="+clusterIdString, "", false)
|
|
||||||
m["right"] = true
|
|
||||||
}
|
|
||||||
actionutils.SetTabbar(action, tabbar)
|
|
||||||
|
|
||||||
// 左侧菜单
|
|
||||||
secondMenuItem := action.Data.GetString("secondMenuItem")
|
|
||||||
switch selectedTabbar {
|
|
||||||
case "setting":
|
|
||||||
action.Data["leftMenuItems"] = this.createSettingMenu(cluster, secondMenuItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置菜单
|
|
||||||
func (this *ClusterHelper) createSettingMenu(cluster *pb.NSCluster, selectedItem string) (items []maps.Map) {
|
|
||||||
clusterId := numberutils.FormatInt64(cluster.Id)
|
|
||||||
return []maps.Map{
|
|
||||||
{
|
|
||||||
"name": "基础设置",
|
|
||||||
"url": "/ns/clusters/cluster/settings?clusterId=" + clusterId,
|
|
||||||
"isActive": selectedItem == "basic",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "访问日志",
|
|
||||||
"url": "/ns/clusters/cluster/settings/accessLog?clusterId=" + clusterId,
|
|
||||||
"isActive": selectedItem == "accessLog",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "递归DNS",
|
|
||||||
"url": "/ns/clusters/cluster/settings/recursion?clusterId=" + clusterId,
|
|
||||||
"isActive": selectedItem == "recursion",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package clusters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CreateAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAction) Init() {
|
|
||||||
this.Nav("", "", "create")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAction) RunGet(params struct{}) {
|
|
||||||
// 默认的访问日志设置
|
|
||||||
this.Data["accessLogRef"] = &dnsconfigs.NSAccessLogRef{
|
|
||||||
IsOn: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAction) RunPost(params struct {
|
|
||||||
Name string
|
|
||||||
AccessLogJSON []byte
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
CSRF *actionutils.CSRF
|
|
||||||
}) {
|
|
||||||
var clusterId int64
|
|
||||||
defer func() {
|
|
||||||
this.CreateLogInfo("创建域名服务集群 %d", clusterId)
|
|
||||||
}()
|
|
||||||
|
|
||||||
params.Must.
|
|
||||||
Field("name", params.Name).
|
|
||||||
Require("请输入集群名称")
|
|
||||||
|
|
||||||
// 校验访问日志设置
|
|
||||||
ref := &dnsconfigs.NSAccessLogRef{}
|
|
||||||
err := json.Unmarshal(params.AccessLogJSON, ref)
|
|
||||||
if err != nil {
|
|
||||||
this.Fail("数据格式错误:" + err.Error())
|
|
||||||
}
|
|
||||||
err = ref.Init()
|
|
||||||
if err != nil {
|
|
||||||
this.Fail("数据格式错误:" + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := this.RPC().NSClusterRPC().CreateNSCluster(this.AdminContext(), &pb.CreateNSClusterRequest{
|
|
||||||
Name: params.Name,
|
|
||||||
AccessLogJSON: params.AccessLogJSON,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clusterId = resp.NsClusterId
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package clusters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"github.com/iwind/TeaGo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct{}) {
|
|
||||||
countResp, err := this.RPC().NSClusterRPC().CountAllEnabledNSClusters(this.AdminContext(), &pb.CountAllEnabledNSClustersRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count := countResp.Count
|
|
||||||
page := this.NewPage(count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
clustersResp, err := this.RPC().NSClusterRPC().ListEnabledNSClusters(this.AdminContext(), &pb.ListEnabledNSClustersRequest{
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clusterMaps := []maps.Map{}
|
|
||||||
for _, cluster := range clustersResp.NsClusters {
|
|
||||||
// 全部节点数量
|
|
||||||
countNodesResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{NsClusterId: cluster.Id})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在线节点
|
|
||||||
countActiveNodesResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{
|
|
||||||
NsClusterId: cluster.Id,
|
|
||||||
ActiveState: types.Int32(configutils.BoolStateYes),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 需要升级的节点
|
|
||||||
countUpgradeNodesResp, err := this.RPC().NSNodeRPC().CountAllUpgradeNSNodesWithNSClusterId(this.AdminContext(), &pb.CountAllUpgradeNSNodesWithNSClusterIdRequest{NsClusterId: cluster.Id})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
clusterMaps = append(clusterMaps, maps.Map{
|
|
||||||
"id": cluster.Id,
|
|
||||||
"name": cluster.Name,
|
|
||||||
"isOn": cluster.IsOn,
|
|
||||||
"countAllNodes": countNodesResp.Count,
|
|
||||||
"countActiveNodes": countActiveNodesResp.Count,
|
|
||||||
"countUpgradeNodes": countUpgradeNodesResp.Count,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["clusters"] = clusterMaps
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package logs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
DayFrom string
|
|
||||||
DayTo string
|
|
||||||
Keyword string
|
|
||||||
Level string
|
|
||||||
}) {
|
|
||||||
this.Data["dayFrom"] = params.DayFrom
|
|
||||||
this.Data["dayTo"] = params.DayTo
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
this.Data["level"] = params.Level
|
|
||||||
|
|
||||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
|
||||||
NodeId: 0,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
DayFrom: params.DayFrom,
|
|
||||||
DayTo: params.DayTo,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Level: params.Level,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count := countResp.Count
|
|
||||||
page := this.NewPage(count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
|
||||||
NodeId: 0,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
DayFrom: params.DayFrom,
|
|
||||||
DayTo: params.DayTo,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Level: params.Level,
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
|
|
||||||
logs := []maps.Map{}
|
|
||||||
for _, log := range logsResp.NodeLogs {
|
|
||||||
// 节点信息
|
|
||||||
nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: log.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
node := nodeResp.NsNode
|
|
||||||
if node == nil || node.NsCluster == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
logs = append(logs, maps.Map{
|
|
||||||
"tag": log.Tag,
|
|
||||||
"description": log.Description,
|
|
||||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
|
||||||
"level": log.Level,
|
|
||||||
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
|
||||||
"count": log.Count,
|
|
||||||
"node": maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"cluster": maps.Map{
|
|
||||||
"id": node.NsCluster.Id,
|
|
||||||
"name": node.NsCluster.Name,
|
|
||||||
},
|
|
||||||
"name": node.Name,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["logs"] = logs
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package clusters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OptionsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *OptionsAction) RunPost(params struct{}) {
|
|
||||||
clustersResp, err := this.RPC().NSClusterRPC().FindAllEnabledNSClusters(this.AdminContext(), &pb.FindAllEnabledNSClustersRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
clusterMaps := []maps.Map{}
|
|
||||||
for _, cluster := range clustersResp.NsClusters {
|
|
||||||
clusterMaps = append(clusterMaps, maps.Map{
|
|
||||||
"id": cluster.Id,
|
|
||||||
"name": cluster.Name,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["clusters"] = clusterMaps
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"github.com/iwind/TeaGo/types"
|
|
||||||
"github.com/miekg/dns"
|
|
||||||
"net"
|
|
||||||
"regexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct{}) {
|
|
||||||
// 集群列表
|
|
||||||
clustersResp, err := this.RPC().NSClusterRPC().FindAllEnabledNSClusters(this.AdminContext(), &pb.FindAllEnabledNSClustersRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var clusterMaps = []maps.Map{}
|
|
||||||
for _, cluster := range clustersResp.NsClusters {
|
|
||||||
if !cluster.IsOn {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
countNodesResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{
|
|
||||||
NsClusterId: cluster.Id,
|
|
||||||
InstallState: 0,
|
|
||||||
ActiveState: 0,
|
|
||||||
Keyword: "",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var countNodes = countNodesResp.Count
|
|
||||||
if countNodes <= 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
clusterMaps = append(clusterMaps, maps.Map{
|
|
||||||
"id": cluster.Id,
|
|
||||||
"name": cluster.Name,
|
|
||||||
"countNodes": countNodes,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["clusters"] = clusterMaps
|
|
||||||
|
|
||||||
// 记录类型
|
|
||||||
this.Data["recordTypes"] = dnsconfigs.FindAllRecordTypeDefinitions()
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
Domain string
|
|
||||||
Type string
|
|
||||||
Ip string
|
|
||||||
ClientIP string
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var node = nodeResp.NsNode
|
|
||||||
if node == nil {
|
|
||||||
this.Fail("找不到要测试的节点")
|
|
||||||
}
|
|
||||||
|
|
||||||
var isOk = false
|
|
||||||
var errMsg string
|
|
||||||
var isNetError = false
|
|
||||||
var result string
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
this.Data["isOk"] = isOk
|
|
||||||
this.Data["err"] = errMsg
|
|
||||||
this.Data["isNetErr"] = isNetError
|
|
||||||
this.Data["result"] = result
|
|
||||||
this.Success()
|
|
||||||
}()
|
|
||||||
|
|
||||||
if !domainutils.ValidateDomainFormat(params.Domain) {
|
|
||||||
errMsg = "域名格式错误"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
recordType, ok := dns.StringToType[params.Type]
|
|
||||||
if !ok {
|
|
||||||
errMsg = "不支持此记录类型"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(params.ClientIP) > 0 && net.ParseIP(params.ClientIP) == nil {
|
|
||||||
errMsg = "客户端IP格式不正确"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var optionId int64
|
|
||||||
if len(params.ClientIP) > 0 {
|
|
||||||
optionResp, err := this.RPC().NSQuestionOptionRPC().CreateNSQuestionOption(this.AdminContext(), &pb.CreateNSQuestionOptionRequest{
|
|
||||||
Name: "setRemoteAddr",
|
|
||||||
ValuesJSON: maps.Map{"ip": params.ClientIP}.AsJSON(),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
optionId = optionResp.NsQuestionOptionId
|
|
||||||
defer func() {
|
|
||||||
_, err = this.RPC().NSQuestionOptionRPC().DeleteNSQuestionOption(this.AdminContext(), &pb.DeleteNSQuestionOptionRequest{NsQuestionOptionId: optionId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
c := new(dns.Client)
|
|
||||||
m := new(dns.Msg)
|
|
||||||
var domain = params.Domain + "."
|
|
||||||
if optionId > 0 {
|
|
||||||
domain = "$" + types.String(optionId) + "-" + domain
|
|
||||||
}
|
|
||||||
m.SetQuestion(domain, recordType)
|
|
||||||
r, _, err := c.Exchange(m, params.Ip+":53")
|
|
||||||
if err != nil {
|
|
||||||
errMsg = "解析过程中出错:" + err.Error()
|
|
||||||
|
|
||||||
// 是否为网络错误
|
|
||||||
if regexp.MustCompile(`timeout|connect`).MatchString(err.Error()) {
|
|
||||||
isNetError = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
result = r.String()
|
|
||||||
result = regexp.MustCompile(`\$\d+-`).ReplaceAllString(result, "")
|
|
||||||
isOk = true
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type NodeOptionsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *NodeOptionsAction) RunPost(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
}) {
|
|
||||||
nodesResp, err := this.RPC().NSNodeRPC().FindAllEnabledNSNodesWithNSClusterId(this.AdminContext(), &pb.FindAllEnabledNSNodesWithNSClusterIdRequest{NsClusterId: params.ClusterId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var nodeMaps = []maps.Map{}
|
|
||||||
for _, node := range nodesResp.NsNodes {
|
|
||||||
if !node.IsOn {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
addressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledNodeIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledNodeIPAddressesWithNodeIdRequest{
|
|
||||||
NodeId: node.Id,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var addresses = addressesResp.NodeIPAddresses
|
|
||||||
if len(addresses) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var addrs = []string{}
|
|
||||||
for _, addr := range addresses {
|
|
||||||
if addr.CanAccess {
|
|
||||||
addrs = append(addrs, addr.Ip)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeMaps = append(nodeMaps, maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"addrs": addrs,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["nodes"] = nodeMaps
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package users
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OptionsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *OptionsAction) RunPost(params struct{}) {
|
|
||||||
usersResp, err := this.RPC().UserRPC().ListEnabledUsers(this.AdminContext(), &pb.ListEnabledUsersRequest{
|
|
||||||
Offset: 0,
|
|
||||||
Size: 10000, // TODO 改进 <ns-user-selector> 组件
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userMaps := []maps.Map{}
|
|
||||||
for _, user := range usersResp.Users {
|
|
||||||
userMaps = append(userMaps, maps.Map{
|
|
||||||
"id": user.Id,
|
|
||||||
"fullname": user.Fullname,
|
|
||||||
"username": user.Username,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["users"] = userMaps
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -49,7 +49,7 @@ func (this *PolicyAction) RunGet(params struct {
|
|||||||
|
|
||||||
// 检查是否有升级
|
// 检查是否有升级
|
||||||
var templatePolicy = firewallconfigs.HTTPFirewallTemplate()
|
var templatePolicy = firewallconfigs.HTTPFirewallTemplate()
|
||||||
var upgradeItems = []string{}
|
var upgradeItems = []maps.Map{}
|
||||||
if templatePolicy.Inbound != nil {
|
if templatePolicy.Inbound != nil {
|
||||||
for _, group := range templatePolicy.Inbound.Groups {
|
for _, group := range templatePolicy.Inbound.Groups {
|
||||||
if len(group.Code) == 0 {
|
if len(group.Code) == 0 {
|
||||||
@@ -57,7 +57,10 @@ func (this *PolicyAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
var oldGroup = firewallPolicy.FindRuleGroupWithCode(group.Code)
|
var oldGroup = firewallPolicy.FindRuleGroupWithCode(group.Code)
|
||||||
if oldGroup == nil {
|
if oldGroup == nil {
|
||||||
upgradeItems = append(upgradeItems, group.Name)
|
upgradeItems = append(upgradeItems, maps.Map{
|
||||||
|
"name": group.Name,
|
||||||
|
"isOn": group.IsOn,
|
||||||
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, set := range group.Sets {
|
for _, set := range group.Sets {
|
||||||
@@ -66,7 +69,10 @@ func (this *PolicyAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
var oldSet = oldGroup.FindRuleSetWithCode(set.Code)
|
var oldSet = oldGroup.FindRuleSetWithCode(set.Code)
|
||||||
if oldSet == nil {
|
if oldSet == nil {
|
||||||
upgradeItems = append(upgradeItems, group.Name+" -- "+set.Name)
|
upgradeItems = append(upgradeItems, maps.Map{
|
||||||
|
"name": group.Name + " -- " + set.Name,
|
||||||
|
"isOn": set.IsOn,
|
||||||
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,6 +28,22 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct{}) {
|
func (this *IndexAction) RunGet(params struct{}) {
|
||||||
this.Data["version"] = teaconst.Version
|
this.Data["version"] = teaconst.Version
|
||||||
|
|
||||||
|
valueResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeCheckUpdates})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var valueJSON = valueResp.ValueJSON
|
||||||
|
var config = &systemconfigs.CheckUpdatesConfig{AutoCheck: false}
|
||||||
|
if len(valueJSON) > 0 {
|
||||||
|
err = json.Unmarshal(valueJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Data["config"] = config
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,8 +56,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var apiURL = teaconst.UpdatesURL
|
var apiURL = teaconst.UpdatesURL
|
||||||
apiURL = strings.ReplaceAll(apiURL, "${os}", "linux") //runtime.GOOS)
|
apiURL = strings.ReplaceAll(apiURL, "${os}", runtime.GOOS)
|
||||||
apiURL = strings.ReplaceAll(apiURL, "${arch}", "amd64") // runtime.GOARCH)
|
apiURL = strings.ReplaceAll(apiURL, "${arch}", runtime.GOARCH)
|
||||||
resp, err := http.Get(apiURL)
|
resp, err := http.Get(apiURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Data["result"] = maps.Map{
|
this.Data["result"] = maps.Map{
|
||||||
@@ -109,7 +128,6 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
"isOk": false,
|
"isOk": false,
|
||||||
"message": "找不到更新信息",
|
"message": "找不到更新信息",
|
||||||
}
|
}
|
||||||
this.Success()
|
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ func init() {
|
|||||||
Helper(settingutils.NewHelper("updates")).
|
Helper(settingutils.NewHelper("updates")).
|
||||||
Prefix("/settings/updates").
|
Prefix("/settings/updates").
|
||||||
GetPost("", new(IndexAction)).
|
GetPost("", new(IndexAction)).
|
||||||
|
Post("/update", new(UpdateAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
59
internal/web/actions/default/settings/updates/update.go
Normal file
59
internal/web/actions/default/settings/updates/update.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package updates
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdateAction) RunPost(params struct {
|
||||||
|
AutoCheck bool
|
||||||
|
}) {
|
||||||
|
valueResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeCheckUpdates})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var valueJSON = valueResp.ValueJSON
|
||||||
|
var config = &systemconfigs.CheckUpdatesConfig{AutoCheck: false}
|
||||||
|
if len(valueJSON) > 0 {
|
||||||
|
err = json.Unmarshal(valueJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.AutoCheck = params.AutoCheck
|
||||||
|
|
||||||
|
configJSON, err := json.Marshal(config)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||||
|
Code: systemconfigs.SettingCodeCheckUpdates,
|
||||||
|
ValueJSON: configJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置状态
|
||||||
|
if !config.AutoCheck {
|
||||||
|
teaconst.NewVersionCode = ""
|
||||||
|
teaconst.NewVersionDownloadURL = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -246,6 +246,8 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
// 这里我们尝试多次是为了等待API节点启动完毕
|
// 这里我们尝试多次是为了等待API节点启动完毕
|
||||||
if err != nil {
|
if err != nil {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ Vue.component("http-header-policy-box", {
|
|||||||
<submit-btn></submit-btn>
|
<submit-btn></submit-btn>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="((!vIsLocation && !vIsGroup) || requestHeaderRef.isPrior) && type == 'response'">
|
<div v-if="((!vIsLocation && !vIsGroup) || responseHeaderRef.isPrior) && type == 'response'">
|
||||||
<div v-if="vHasGroupResponseConfig">
|
<div v-if="vHasGroupResponseConfig">
|
||||||
<div class="margin"></div>
|
<div class="margin"></div>
|
||||||
<warning-message>由于已经在当前<a :href="vGroupSettingUrl + '#response'">服务分组</a>中进行了对应的配置,在这里的配置将不会生效。</warning-message>
|
<warning-message>由于已经在当前<a :href="vGroupSettingUrl + '#response'">服务分组</a>中进行了对应的配置,在这里的配置将不会生效。</warning-message>
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<first-menu>
|
|
||||||
<menu-item href="/dashboard/boards" code="index">概况</menu-item>
|
|
||||||
<menu-item href="/dashboard/boards/waf" code="waf">WAF</menu-item>
|
|
||||||
<menu-item href="/dashboard/boards/dns" code="dns">DNS</menu-item>
|
|
||||||
<menu-item href="/dashboard/boards/user" code="user">用户</menu-item>
|
|
||||||
<menu-item href="/dashboard/boards/events" code="event">事件<span :class="{red: countEvents > 0}">({{countEvents}})</span></menu-item>
|
|
||||||
</first-menu>
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
{$layout}
|
|
||||||
{$template "menu"}
|
|
||||||
{$template "/echarts"}
|
|
||||||
|
|
||||||
<div class="ui four columns grid">
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>域名<link-icon href="/ns/domains"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{board.countDomains}}</span>个</div>
|
|
||||||
</div>
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>记录<link-icon href="/ns/domains"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{board.countRecords}}</span>个</div>
|
|
||||||
</div>
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>集群<link-icon href="/ns/clusters"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{board.countClusters}}</span>个</div>
|
|
||||||
</div>
|
|
||||||
<div class="ui column no-border">
|
|
||||||
<h4>节点<link-icon href="/ns/clusters"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{board.countNodes}}</span>
|
|
||||||
<span v-if="board.countOfflineNodes > 0" style="font-size: 1em">
|
|
||||||
/ <a href="/ns/clusters"><span class="red" style="font-size: 1em">{{board.countOfflineNodes}}离线</span></a>
|
|
||||||
</span>
|
|
||||||
<span v-else style="font-size: 1em">个</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 流量统计 -->
|
|
||||||
<div class="ui menu tabular">
|
|
||||||
<a href="" class="item" :class="{active: trafficTab == 'hourly'}" @click.prevent="selectTrafficTab('hourly')">24小时流量趋势</a>
|
|
||||||
<a href="" class="item" :class="{active: trafficTab == 'daily'}" @click.prevent="selectTrafficTab('daily')">15天流量趋势</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 按小时统计流量 -->
|
|
||||||
<div class="chart-box" id="hourly-traffic-chart" v-show="trafficTab == 'hourly'"></div>
|
|
||||||
|
|
||||||
<!-- 按日统计流量 -->
|
|
||||||
<div class="chart-box" id="daily-traffic-chart" v-show="trafficTab == 'daily'"></div>
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 域名排行 -->
|
|
||||||
<h4>域名访问排行 <span>(24小时)</span></h4>
|
|
||||||
<div class="chart-box" id="top-domains-chart"></div>
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 节点排行 -->
|
|
||||||
<h4>节点访问排行 <span>(24小时)</span></h4>
|
|
||||||
<div class="chart-box" id="top-nodes-chart"></div>
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 系统信息 -->
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
<div class="ui menu tabular">
|
|
||||||
<a href="" class="item" :class="{active: nodeStatusTab == 'cpu'}" @click.prevent="selectNodeStatusTab('cpu')">DNS节点CPU</a>
|
|
||||||
<a href="" class="item" :class="{active: nodeStatusTab == 'memory'}" @click.prevent="selectNodeStatusTab('memory')">DNS节点内存</a>
|
|
||||||
<a href="" class="item" :class="{active: nodeStatusTab == 'load'}" @click.prevent="selectNodeStatusTab('load')">DNS节点负载</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="chart-box" id="cpu-chart" v-show="nodeStatusTab == 'cpu'"></div>
|
|
||||||
<div class="chart-box" id="memory-chart" v-show="nodeStatusTab == 'memory'"></div>
|
|
||||||
<div class="chart-box" id="load-chart" v-show="nodeStatusTab == 'load'"></div>
|
|
||||||
@@ -1,246 +0,0 @@
|
|||||||
Tea.context(function () {
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadHourlyTrafficChart()
|
|
||||||
this.reloadTopDomainsChart()
|
|
||||||
this.reloadTopNodesChart()
|
|
||||||
this.reloadCPUChart()
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 流量统计
|
|
||||||
*/
|
|
||||||
this.trafficTab = "hourly"
|
|
||||||
|
|
||||||
this.selectTrafficTab = function (tab) {
|
|
||||||
this.trafficTab = tab
|
|
||||||
if (tab == "hourly") {
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadHourlyTrafficChart()
|
|
||||||
})
|
|
||||||
} else if (tab == "daily") {
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadDailyTrafficChart()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadHourlyTrafficChart = function () {
|
|
||||||
let stats = this.hourlyStats
|
|
||||||
this.reloadTrafficChart("hourly-traffic-chart", "流量统计", stats, function (args) {
|
|
||||||
return stats[args.dataIndex].day + " " + stats[args.dataIndex].hour + "时 流量: " + teaweb.formatBytes(stats[args.dataIndex].bytes)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadDailyTrafficChart = function () {
|
|
||||||
let stats = this.dailyStats
|
|
||||||
this.reloadTrafficChart("daily-traffic-chart", "流量统计", stats, function (args) {
|
|
||||||
return stats[args.dataIndex].day + " 流量: " + teaweb.formatBytes(stats[args.dataIndex].bytes)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadTrafficChart = function (chartId, name, stats, tooltipFunc) {
|
|
||||||
let chartBox = document.getElementById(chartId)
|
|
||||||
if (chartBox == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let axis = teaweb.bytesAxis(stats, function (v) {
|
|
||||||
return v.bytes
|
|
||||||
})
|
|
||||||
|
|
||||||
let chart = teaweb.initChart(chartBox)
|
|
||||||
let option = {
|
|
||||||
xAxis: {
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
if (v.hour != null) {
|
|
||||||
return v.hour
|
|
||||||
}
|
|
||||||
return v.day
|
|
||||||
})
|
|
||||||
},
|
|
||||||
yAxis: {
|
|
||||||
axisLabel: {
|
|
||||||
formatter: function (value) {
|
|
||||||
return value + axis.unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
show: true,
|
|
||||||
trigger: "item",
|
|
||||||
formatter: tooltipFunc
|
|
||||||
},
|
|
||||||
grid: {
|
|
||||||
left: 50,
|
|
||||||
top: 40,
|
|
||||||
right: 20,
|
|
||||||
bottom: 20
|
|
||||||
},
|
|
||||||
series: [
|
|
||||||
{
|
|
||||||
name: "流量",
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.bytes / axis.divider
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#9DD3E8"
|
|
||||||
},
|
|
||||||
areaStyle: {
|
|
||||||
color: "#9DD3E8"
|
|
||||||
},
|
|
||||||
smooth: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
animation: true
|
|
||||||
}
|
|
||||||
chart.setOption(option)
|
|
||||||
chart.resize()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 域名排行
|
|
||||||
this.reloadTopDomainsChart = function () {
|
|
||||||
let that = this
|
|
||||||
let axis = teaweb.countAxis(this.topDomainStats, function (v) {
|
|
||||||
return v.countRequests
|
|
||||||
})
|
|
||||||
teaweb.renderBarChart({
|
|
||||||
id: "top-domains-chart",
|
|
||||||
name: "域名",
|
|
||||||
values: this.topDomainStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.domainName
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].domainName + "<br/>请求数:" + " " + teaweb.formatNumber(stats[args.dataIndex].countRequests) + "<br/>流量:" + teaweb.formatBytes(stats[args.dataIndex].bytes)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.countRequests / axis.divider;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
click: function (args, stats) {
|
|
||||||
window.location = "/ns/domains/domain?domainId=" + stats[args.dataIndex].domainId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 节点排行
|
|
||||||
this.reloadTopNodesChart = function () {
|
|
||||||
let that = this
|
|
||||||
let axis = teaweb.countAxis(this.topNodeStats, function (v) {
|
|
||||||
return v.countRequests
|
|
||||||
})
|
|
||||||
teaweb.renderBarChart({
|
|
||||||
id: "top-nodes-chart",
|
|
||||||
name: "节点",
|
|
||||||
values: this.topNodeStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.nodeName
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].nodeName + "<br/>请求数:" + " " + teaweb.formatNumber(stats[args.dataIndex].countRequests) + "<br/>流量:" + teaweb.formatBytes(stats[args.dataIndex].bytes)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.countRequests / axis.divider;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
click: function (args, stats) {
|
|
||||||
window.location = "/ns/clusters/cluster/node?nodeId=" + stats[args.dataIndex].nodeId + "&clusterId=" + stats[args.dataIndex].clusterId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统信息
|
|
||||||
*/
|
|
||||||
this.nodeStatusTab = "cpu"
|
|
||||||
|
|
||||||
this.selectNodeStatusTab = function (tab) {
|
|
||||||
this.nodeStatusTab = tab
|
|
||||||
this.$delay(function () {
|
|
||||||
switch (tab) {
|
|
||||||
case "cpu":
|
|
||||||
this.reloadCPUChart()
|
|
||||||
break
|
|
||||||
case "memory":
|
|
||||||
this.reloadMemoryChart()
|
|
||||||
break
|
|
||||||
case "load":
|
|
||||||
this.reloadLoadChart()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadCPUChart = function () {
|
|
||||||
let axis = {unit: "%", divider: 1}
|
|
||||||
teaweb.renderLineChart({
|
|
||||||
id: "cpu-chart",
|
|
||||||
name: "CPU",
|
|
||||||
values: this.cpuValues,
|
|
||||||
x: function (v) {
|
|
||||||
return v.time
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].time + ":" + (Math.ceil(stats[args.dataIndex].value * 100 * 100) / 100) + "%"
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.value * 100;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
max: 100
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadMemoryChart = function () {
|
|
||||||
let axis = {unit: "%", divider: 1}
|
|
||||||
teaweb.renderLineChart({
|
|
||||||
id: "memory-chart",
|
|
||||||
name: "内存",
|
|
||||||
values: this.memoryValues,
|
|
||||||
x: function (v) {
|
|
||||||
return v.time
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].time + ":" + (Math.ceil(stats[args.dataIndex].value * 100 * 100) / 100) + "%"
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.value * 100;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
max: 100
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadLoadChart = function () {
|
|
||||||
let axis = {unit: "", divider: 1}
|
|
||||||
let max = this.loadValues.$map(function (k, v) {
|
|
||||||
return v.value
|
|
||||||
}).$max()
|
|
||||||
if (max < 10) {
|
|
||||||
max = 10
|
|
||||||
} else if (max < 20) {
|
|
||||||
max = 20
|
|
||||||
} else if (max < 100) {
|
|
||||||
max = 100
|
|
||||||
} else {
|
|
||||||
max = null
|
|
||||||
}
|
|
||||||
teaweb.renderLineChart({
|
|
||||||
id: "load-chart",
|
|
||||||
name: "负载",
|
|
||||||
values: this.loadValues,
|
|
||||||
x: function (v) {
|
|
||||||
return v.time
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].time + ":" + (Math.ceil(stats[args.dataIndex].value * 100) / 100)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.value;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
max: max
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
{$layout}
|
|
||||||
{$template "menu"}
|
|
||||||
|
|
||||||
<p class="comment" v-if="logs.length == 0">暂时还没有事件。</p>
|
|
||||||
|
|
||||||
<second-menu v-if="logs.length > 0">
|
|
||||||
<a href="" class="item" @click.prevent="updatePageRead()">[本页已读]</a>
|
|
||||||
<a href="" class="item" @click.prevent="updateAllRead()">[全部已读]</a>
|
|
||||||
</second-menu>
|
|
||||||
|
|
||||||
<table class="ui table selectable celled" v-if="logs.length > 0">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th nowrap="">节点类型</th>
|
|
||||||
<th nowrap="">集群</th>
|
|
||||||
<th nowrap="">节点</th>
|
|
||||||
<th>信息</th>
|
|
||||||
<th class="one op">操作</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tr v-for="log in logs">
|
|
||||||
<td>
|
|
||||||
<node-role-name :v-role="log.role"></node-role-name>
|
|
||||||
</td>
|
|
||||||
<td nowrap="">
|
|
||||||
<span v-if="log.role == 'node'">
|
|
||||||
<link-icon :href="'/clusters/cluster?clusterId=' + log.node.cluster.id">{{log.node.cluster.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
<span v-else-if="log.role == 'dns'">
|
|
||||||
<link-icon :href="'/ns/clusters/cluster?clusterId=' + log.node.cluster.id">{{log.node.cluster.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
<span v-else class="disabled">-</span>
|
|
||||||
</td>
|
|
||||||
<td nowrap="">
|
|
||||||
<span v-if="log.role == 'node'">
|
|
||||||
<link-icon :href="'/clusters/cluster/node?clusterId=' + log.node.cluster.id + '&nodeId=' + log.node.id">{{log.node.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
<span v-if="log.role == 'api'">
|
|
||||||
<link-icon :href="'/api/node?nodeId=' + log.node.id">{{log.node.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
<span v-if="log.role == 'dns'">
|
|
||||||
<link-icon :href="'/ns/clusters/cluster/node?clusterId=' + log.node.cluster.id + '&nodeId=' + log.node.id">{{log.node.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
<span v-if="log.role == 'database'">
|
|
||||||
<link-icon :href="'/db/node?nodeId=' + log.node.id">{{log.node.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
<span v-if="log.role == 'admin'">管理平台</span>
|
|
||||||
<span v-if="log.role == 'user'">
|
|
||||||
<link-icon :href="'/settings/userNodes/node?nodeId=' + log.node.id">{{log.node.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
<span v-if="log.role == 'monitor'">
|
|
||||||
<link-icon :href="'/settings/monitorNodes/node?nodeId=' + log.node.id">{{log.node.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
<span v-if="log.role == 'report'">
|
|
||||||
<link-icon :href="'/clusters/monitors/reporters/reporter?reporterId=' + log.node.id">{{log.node.name}}</link-icon>
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<node-log-row :v-log="log" :v-keyword="keyword"></node-log-row>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="" @click.prevent="updateRead(log.id)">已读</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<div class="page" v-html="page"></div>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
Tea.context(function () {
|
|
||||||
this.updateRead = function (logId) {
|
|
||||||
this.$post(".readLogs")
|
|
||||||
.params({
|
|
||||||
logIds: [logId]
|
|
||||||
})
|
|
||||||
.success(function () {
|
|
||||||
teaweb.reload()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updatePageRead = function () {
|
|
||||||
let logIds = this.logs.map(function (v) {
|
|
||||||
return v.id
|
|
||||||
})
|
|
||||||
teaweb.confirm("确定要设置本页日志为已读吗?", function () {
|
|
||||||
this.$post(".readLogs")
|
|
||||||
.params({
|
|
||||||
logIds: logIds
|
|
||||||
})
|
|
||||||
.success(function () {
|
|
||||||
teaweb.reload()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateAllRead = function () {
|
|
||||||
teaweb.confirm("确定要设置所有日志为已读吗?", function () {
|
|
||||||
this.$post(".readAllLogs")
|
|
||||||
.params({})
|
|
||||||
.success(function () {
|
|
||||||
teaweb.reload()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
{$layout}
|
|
||||||
|
|
||||||
{$var "header"}
|
|
||||||
<!-- world map -->
|
|
||||||
<script type="text/javascript" src="/js/echarts/echarts.min.js"></script>
|
|
||||||
<script type="text/javascript" src="/js/world.js"></script>
|
|
||||||
<script type="text/javascript" src="/js/world-countries-map.js"></script>
|
|
||||||
{$end}
|
|
||||||
|
|
||||||
{$template "menu"}
|
|
||||||
|
|
||||||
<!-- 加载中 -->
|
|
||||||
<div style="margin-top: 0.8em">
|
|
||||||
<div class="ui message loading" v-if="isLoading">
|
|
||||||
<div class="ui active inline loader small"></div> 数据加载中...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 商业版错误 -->
|
|
||||||
<div class="ui icon message error" v-if="plusErr.length > 0">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
{{plusErr}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 没有节点提醒 -->
|
|
||||||
<div class="ui icon message warning" v-if="!isLoading && dashboard.defaultClusterId > 0 && dashboard.countNodes == 0">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a :href="'/clusters/cluster/createNode?clusterId=' + dashboard.defaultClusterId">还没有在集群中添加节点,现在去添加?添加节点后才可部署网站服务。</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 过期提醒 -->
|
|
||||||
<div class="ui icon message error" v-if="plusExpireDay.length > 0">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a href="/settings/authority">续费提醒:商业版服务即将在 {{plusExpireDay}} 过期,请及时续费。</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 升级提醒 -->
|
|
||||||
<div class="ui icon message error" v-if="!isLoading && nodeUpgradeInfo.count > 0">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a href="/clusters">
|
|
||||||
升级提醒:有 {{nodeUpgradeInfo.count}} 个边缘节点需要升级到 v{{nodeUpgradeInfo.version}} 版本,系统正在尝试自动升级...</a><a href="" title="关闭" @click.prevent="closeMessage"><i class="ui icon remove small"></i></a>
|
|
||||||
</div>
|
|
||||||
<div class="ui icon message error" v-if="!isLoading && monitorNodeUpgradeInfo.count > 0 && teaIsPlus">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a href="/settings/monitorNodes">升级提醒:有 {{monitorNodeUpgradeInfo.count}} 个监控节点需要升级到 v{{monitorNodeUpgradeInfo.version}} 版本</a><a href="" title="关闭" @click.prevent="closeMessage"><i class="ui icon remove small"></i></a></div>
|
|
||||||
<div class="ui icon message error" v-if="!isLoading && userNodeUpgradeInfo.count > 0 && teaIsPlus">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a href="/settings/userNodes">升级提醒:有 {{userNodeUpgradeInfo.count}} 个用户节点需要升级到 v{{userNodeUpgradeInfo.version}} 版本</a><a href="" title="关闭" @click.prevent="closeMessage"><i class="ui icon remove small"></i></a></div>
|
|
||||||
<div class="ui icon message error" v-if="!isLoading && apiNodeUpgradeInfo.count > 0">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a href="/api">升级提醒:有 {{apiNodeUpgradeInfo.count}} 个API节点需要升级到 v{{apiNodeUpgradeInfo.version}} 版本</a><a href="" title="关闭" @click.prevent="closeMessage"><i class="ui icon remove small"></i></a></div>
|
|
||||||
<div class="ui icon message error" v-if="!isLoading && nsNodeUpgradeInfo.count > 0 && teaIsPlus">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a href="/ns/clusters">升级提醒:有 {{nsNodeUpgradeInfo.count}} 个DNS节点需要升级到 v{{nsNodeUpgradeInfo.version}} 版本,系统正在尝试自动升级...</a><a href="" title="关闭" @click.prevent="closeMessage"><i class="ui icon remove small"></i></a>
|
|
||||||
</div>
|
|
||||||
<div class="ui icon message error" v-if="!isLoading && reportNodeUpgradeInfo.count > 0 && teaIsPlus">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a href="/clusters/monitors/reporters">升级提醒:有 {{reportNodeUpgradeInfo.count}} 个区域监控终端需要升级到 v{{reportNodeUpgradeInfo.version}} 版本</a><a href="" title="关闭" @click.prevent="closeMessage"><i class="ui icon remove small"></i></a>
|
|
||||||
</div>
|
|
||||||
<div class="ui icon message error" v-if="!isLoading && authorityNodeUpgradeInfo.count > 0 && teaIsPlus">
|
|
||||||
<i class="icon warning circle"></i>
|
|
||||||
<a href="/settings/authority/nodes">升级提醒:有 {{authorityNodeUpgradeInfo.count}} 个商业版认证节点需要升级到 v{{authorityNodeUpgradeInfo.version}} 版本</a><a href="" title="关闭" @click.prevent="closeMessage"><i class="ui icon remove small"></i></a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 统计图表 -->
|
|
||||||
<div class="ui four columns grid" v-if="!isLoading">
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>集群<link-icon href="/clusters" v-if="dashboard.canGoNodes"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{dashboard.countNodeClusters}}</span>个</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>边缘节点<link-icon href="/clusters" v-if="dashboard.canGoNodes"></link-icon></h4>
|
|
||||||
<div class="value">
|
|
||||||
<span>{{dashboard.countNodes}}</span>个
|
|
||||||
<span style="font-size: 1em" v-if="dashboard.countOfflineNodes > 0">/ <a href="/clusters" v-if="dashboard.canGoNodes"><span class="red" style="font-size: 1em">{{dashboard.countOfflineNodes}}离线</span></a><span class="red" style="font-size: 1em" v-else>{{dashboard.countOfflineNodes}}离线</span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>API节点<link-icon href="/api" v-if="dashboard.canGoSettings"></link-icon></h4>
|
|
||||||
<div class="value">
|
|
||||||
<span>{{dashboard.countAPINodes}}</span>个
|
|
||||||
<span style="font-size: 1em" v-if="dashboard.countOfflineAPINodes > 0">/ <a href="/api" v-if="dashboard.canGoSettings"><span class="red" style="font-size: 1em">{{dashboard.countOfflineAPINodes}}离线</span></a><span class="red" style="font-size: 1em" v-else>{{dashboard.countOfflineAPINodes}}离线</span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>用户<link-icon href="/users" v-if="dashboard.canGoUsers"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{dashboard.countUsers}}</span>个
|
|
||||||
<span style="font-size: 1em" v-if="dashboard.countOfflineUserNodes > 0">/ <a href="/settings/userNodes" v-if="dashboard.canGoSettings"><span class="red" style="font-size: 1em">{{dashboard.countOfflineUserNodes}}节点离线</span></a><span class="red" style="font-size: 1em" v-else>{{dashboard.countOfflineUserNodes}}节点离线</span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>服务<link-icon href="/servers" v-if="dashboard.canGoServers"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{dashboard.countServers}}</span>个
|
|
||||||
<span style="font-size: 1em" v-if="dashboard.countAuditingServers > 0">/ <a href="/servers?auditingFlag=1" v-if="dashboard.canGoServers"><span class="red" style="font-size: 1em">{{dashboard.countAuditingServers}}审核</span></a><span class="red" style="font-size: 1em" v-else>{{dashboard.countAuditingServers}}审核</span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>本周流量</h4>
|
|
||||||
<div class="value"><span>{{weekTraffic}}</span>{{weekTrafficUnit}}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>昨日流量</h4>
|
|
||||||
<div class="value"><span>{{yesterdayTraffic}}</span>{{yesterdayTrafficUnit}}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column no-border">
|
|
||||||
<h4>今日流量</h4>
|
|
||||||
<div class="value"><span>{{todayTraffic}}</span>{{todayTrafficUnit}}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 流量地图 -->
|
|
||||||
<div v-if="!isLoading">
|
|
||||||
<traffic-map-box :v-stats="topCountryStats"></traffic-map-box>
|
|
||||||
</div>
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 流量 -->
|
|
||||||
<div class="ui menu tabular" v-show="!isLoading">
|
|
||||||
<a href="" class="item" :class="{active: trafficTab == 'hourly'}" @click.prevent="selectTrafficTab('hourly')">24小时流量趋势</a>
|
|
||||||
<a href="" class="item" :class="{active: trafficTab == 'daily'}" @click.prevent="selectTrafficTab('daily')">15天流量趋势</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 按小时统计 -->
|
|
||||||
<div class="chart-box" id="hourly-traffic-chart-box" v-show="trafficTab == 'hourly'"></div>
|
|
||||||
|
|
||||||
<!-- 按日统计 -->
|
|
||||||
<div class="chart-box" id="daily-traffic-chart-box" v-show="trafficTab == 'daily'"></div>
|
|
||||||
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<div class="ui menu tabular" v-show="!isLoading">
|
|
||||||
<a href="" class="item" :class="{active: requestsTab == 'hourly'}" @click.prevent="selectRequestsTab('hourly')">24小时访问量趋势</a>
|
|
||||||
<a href="" class="item" :class="{active: requestsTab == 'daily'}" @click.prevent="selectRequestsTab('daily')">15天访问量趋势</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 按小时统计访问量 -->
|
|
||||||
<div class="chart-box" id="hourly-requests-chart" v-show="requestsTab == 'hourly'"></div>
|
|
||||||
|
|
||||||
<!-- 按日统计访问量 -->
|
|
||||||
<div class="chart-box" id="daily-requests-chart" v-show="requestsTab == 'daily'"></div>
|
|
||||||
|
|
||||||
<!-- 域名排行 -->
|
|
||||||
<h4 v-show="!isLoading">域名访问排行 <span>(24小时)</span></h4>
|
|
||||||
<div class="chart-box" id="top-domains-chart"></div>
|
|
||||||
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 节点排行 -->
|
|
||||||
<h4 v-show="!isLoading">节点访问排行 <span>(24小时)</span></h4>
|
|
||||||
<div class="chart-box" id="top-nodes-chart"></div>
|
|
||||||
|
|
||||||
<!-- 指标 -->
|
|
||||||
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
|
||||||
<metric-board>
|
|
||||||
<metric-chart v-for="chart in metricCharts"
|
|
||||||
:key="chart.id"
|
|
||||||
:v-chart="chart.chart"
|
|
||||||
:v-stats="chart.stats"
|
|
||||||
:v-item="chart.item">
|
|
||||||
</metric-chart>
|
|
||||||
</metric-board>
|
|
||||||
@@ -1,367 +0,0 @@
|
|||||||
Tea.context(function () {
|
|
||||||
this.isLoading = true
|
|
||||||
this.trafficTab = "hourly"
|
|
||||||
this.metricCharts = []
|
|
||||||
this.plusExpireDay = ""
|
|
||||||
this.topCountryStats = []
|
|
||||||
|
|
||||||
this.$delay(function () {
|
|
||||||
this.$post("$")
|
|
||||||
.success(function (resp) {
|
|
||||||
for (let k in resp.data) {
|
|
||||||
this[k] = resp.data[k]
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isLoading = false
|
|
||||||
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadHourlyTrafficChart()
|
|
||||||
this.reloadHourlyRequestsChart()
|
|
||||||
this.reloadTopDomainsChart()
|
|
||||||
this.reloadTopNodesChart()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
this.selectTrafficTab = function (tab) {
|
|
||||||
this.trafficTab = tab
|
|
||||||
if (tab == "hourly") {
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadHourlyTrafficChart()
|
|
||||||
})
|
|
||||||
} else if (tab == "daily") {
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadDailyTrafficChart()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadHourlyTrafficChart = function () {
|
|
||||||
let stats = this.hourlyTrafficStats
|
|
||||||
this.reloadTrafficChart("hourly-traffic-chart-box", stats, function (args) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
let cachedRatio = 0
|
|
||||||
let attackRatio = 0
|
|
||||||
if (stats[index].bytes > 0) {
|
|
||||||
cachedRatio = Math.round(stats[index].cachedBytes * 10000 / stats[index].bytes) / 100
|
|
||||||
attackRatio = Math.round(stats[index].attackBytes * 10000 / stats[index].bytes) / 100
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats[index].day + " " + stats[index].hour + "时<br/>总流量:" + teaweb.formatBytes(stats[index].bytes) + "<br/>缓存流量:" + teaweb.formatBytes(stats[index].cachedBytes) + "<br/>缓存命中率:" + cachedRatio + "%<br/>拦截攻击流量:" + teaweb.formatBytes(stats[index].attackBytes) + "<br/>拦截比例:" + attackRatio + "%"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadDailyTrafficChart = function () {
|
|
||||||
let stats = this.dailyTrafficStats
|
|
||||||
this.reloadTrafficChart("daily-traffic-chart-box", stats, function (args) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
let cachedRatio = 0
|
|
||||||
let attackRatio = 0
|
|
||||||
if (stats[index].bytes > 0) {
|
|
||||||
cachedRatio = Math.round(stats[index].cachedBytes * 10000 / stats[index].bytes) / 100
|
|
||||||
attackRatio = Math.round(stats[index].attackBytes * 10000 / stats[index].bytes) / 100
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats[index].day + "<br/>总流量:" + teaweb.formatBytes(stats[index].bytes) + "<br/>缓存流量:" + teaweb.formatBytes(stats[index].cachedBytes) + "<br/>缓存命中率:" + cachedRatio + "%<br/>拦截攻击流量:" + teaweb.formatBytes(stats[index].attackBytes) + "<br/>拦截比例:" + attackRatio + "%"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.reloadTrafficChart = function (chartId, stats, tooltipFunc) {
|
|
||||||
let axis = teaweb.bytesAxis(stats, function (v) {
|
|
||||||
return v.bytes
|
|
||||||
})
|
|
||||||
let chartBox = document.getElementById(chartId)
|
|
||||||
let chart = teaweb.initChart(chartBox)
|
|
||||||
let option = {
|
|
||||||
xAxis: {
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
if (v.hour != null) {
|
|
||||||
return v.hour
|
|
||||||
}
|
|
||||||
return v.day
|
|
||||||
})
|
|
||||||
},
|
|
||||||
yAxis: {
|
|
||||||
axisLabel: {
|
|
||||||
formatter: function (v) {
|
|
||||||
return v + axis.unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
show: true,
|
|
||||||
trigger: "item",
|
|
||||||
formatter: tooltipFunc
|
|
||||||
},
|
|
||||||
grid: {
|
|
||||||
left: 50,
|
|
||||||
top: 40,
|
|
||||||
right: 20,
|
|
||||||
bottom: 20
|
|
||||||
},
|
|
||||||
series: [
|
|
||||||
{
|
|
||||||
name: "总流量",
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.bytes / axis.divider;
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#9DD3E8"
|
|
||||||
},
|
|
||||||
lineStyle: {
|
|
||||||
color: "#9DD3E8"
|
|
||||||
},
|
|
||||||
areaStyle: {
|
|
||||||
color: "#9DD3E8"
|
|
||||||
},
|
|
||||||
smooth: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "缓存流量",
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.cachedBytes / axis.divider;
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#61A0A8"
|
|
||||||
},
|
|
||||||
lineStyle: {
|
|
||||||
color: "#61A0A8"
|
|
||||||
},
|
|
||||||
areaStyle: {},
|
|
||||||
smooth: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "攻击流量",
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.attackBytes / axis.divider;
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#F39494"
|
|
||||||
},
|
|
||||||
areaStyle: {
|
|
||||||
color: "#F39494"
|
|
||||||
},
|
|
||||||
smooth: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
legend: {
|
|
||||||
data: ["总流量", "缓存流量", "攻击流量"]
|
|
||||||
},
|
|
||||||
animation: false
|
|
||||||
}
|
|
||||||
chart.setOption(option)
|
|
||||||
chart.resize()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求数统计
|
|
||||||
*/
|
|
||||||
this.requestsTab = "hourly"
|
|
||||||
|
|
||||||
this.selectRequestsTab = function (tab) {
|
|
||||||
this.requestsTab = tab
|
|
||||||
if (tab == "hourly") {
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadHourlyRequestsChart()
|
|
||||||
})
|
|
||||||
} else if (tab == "daily") {
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadDailyRequestsChart()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadHourlyRequestsChart = function () {
|
|
||||||
let stats = this.hourlyTrafficStats
|
|
||||||
this.reloadRequestsChart("hourly-requests-chart", "请求数统计", stats, function (args) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
let cachedRatio = 0
|
|
||||||
let attackRatio = 0
|
|
||||||
if (stats[index].countRequests > 0) {
|
|
||||||
cachedRatio = Math.round(stats[index].countCachedRequests * 10000 / stats[index].countRequests) / 100
|
|
||||||
attackRatio = Math.round(stats[index].countAttackRequests * 10000 / stats[index].countRequests) / 100
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats[index].day + " " + stats[index].hour + "时<br/>总请求数:" + stats[index].countRequests + "<br/>缓存请求数:" + stats[index].countCachedRequests + "<br/>缓存命中率:" + cachedRatio + "%<br/>拦截攻击数:" + stats[index].countAttackRequests + "<br/>拦截比例:" + attackRatio + "%"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadDailyRequestsChart = function () {
|
|
||||||
let stats = this.dailyTrafficStats
|
|
||||||
this.reloadRequestsChart("daily-requests-chart", "请求数统计", stats, function (args) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
let cachedRatio = 0
|
|
||||||
let attackRatio = 0
|
|
||||||
if (stats[index].countRequests > 0) {
|
|
||||||
cachedRatio = Math.round(stats[index].countCachedRequests * 10000 / stats[index].countRequests) / 100
|
|
||||||
attackRatio = Math.round(stats[index].countAttackRequests * 10000 / stats[index].countRequests) / 100
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats[index].day + "<br/>总请求数:" + stats[index].countRequests + "<br/>缓存请求数:" + stats[index].countCachedRequests + "<br/>缓存命中率:" + cachedRatio + "%<br/>拦截攻击数:" + stats[index].countAttackRequests + "<br/>拦截比例:" + attackRatio + "%"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadRequestsChart = function (chartId, name, stats, tooltipFunc) {
|
|
||||||
let chartBox = document.getElementById(chartId)
|
|
||||||
if (chartBox == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let axis = teaweb.countAxis(stats, function (v) {
|
|
||||||
return Math.max(v.countRequests, v.countCachedRequests)
|
|
||||||
})
|
|
||||||
|
|
||||||
let chart = teaweb.initChart(chartBox)
|
|
||||||
let option = {
|
|
||||||
xAxis: {
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
if (v.hour != null) {
|
|
||||||
return v.hour
|
|
||||||
}
|
|
||||||
if (v.day != null) {
|
|
||||||
return v.day
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
})
|
|
||||||
},
|
|
||||||
yAxis: {
|
|
||||||
axisLabel: {
|
|
||||||
formatter: function (value) {
|
|
||||||
return value + axis.unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
show: true,
|
|
||||||
trigger: "item",
|
|
||||||
formatter: tooltipFunc
|
|
||||||
},
|
|
||||||
grid: {
|
|
||||||
left: 50,
|
|
||||||
top: 40,
|
|
||||||
right: 20,
|
|
||||||
bottom: 20
|
|
||||||
},
|
|
||||||
series: [
|
|
||||||
{
|
|
||||||
name: "请求数",
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.countRequests / axis.divider
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#9DD3E8"
|
|
||||||
},
|
|
||||||
areaStyle: {
|
|
||||||
color: "#9DD3E8"
|
|
||||||
},
|
|
||||||
smooth: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "缓存请求数",
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.countCachedRequests / axis.divider
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#61A0A8"
|
|
||||||
},
|
|
||||||
areaStyle: {
|
|
||||||
color: "#61A0A8"
|
|
||||||
},
|
|
||||||
smooth: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "攻击请求数",
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.countAttackRequests / axis.divider;
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#F39494"
|
|
||||||
},
|
|
||||||
areaStyle: {
|
|
||||||
color: "#F39494"
|
|
||||||
},
|
|
||||||
smooth: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
legend: {
|
|
||||||
data: ["请求数", "缓存请求数", "攻击请求数"]
|
|
||||||
},
|
|
||||||
animation: true
|
|
||||||
}
|
|
||||||
chart.setOption(option)
|
|
||||||
chart.resize()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 节点排行
|
|
||||||
this.reloadTopNodesChart = function () {
|
|
||||||
let that = this
|
|
||||||
let axis = teaweb.countAxis(this.topNodeStats, function (v) {
|
|
||||||
return v.countRequests
|
|
||||||
})
|
|
||||||
teaweb.renderBarChart({
|
|
||||||
id: "top-nodes-chart",
|
|
||||||
name: "节点",
|
|
||||||
values: this.topNodeStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.nodeName
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].nodeName + "<br/>请求数:" + " " + teaweb.formatNumber(stats[args.dataIndex].countRequests) + "<br/>流量:" + teaweb.formatBytes(stats[args.dataIndex].bytes)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.countRequests / axis.divider;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
click: function (args, stats) {
|
|
||||||
window.location = "/clusters/cluster/node?nodeId=" + stats[args.dataIndex].nodeId + "&clusterId=" + that.clusterId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 域名排行
|
|
||||||
this.reloadTopDomainsChart = function () {
|
|
||||||
let axis = teaweb.countAxis(this.topDomainStats, function (v) {
|
|
||||||
return v.countRequests
|
|
||||||
})
|
|
||||||
teaweb.renderBarChart({
|
|
||||||
id: "top-domains-chart",
|
|
||||||
name: "域名",
|
|
||||||
values: this.topDomainStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.domain
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].domain + "<br/>请求数:" + " " + teaweb.formatNumber(stats[args.dataIndex].countRequests) + "<br/>流量:" + teaweb.formatBytes(stats[args.dataIndex].bytes)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.countRequests / axis.divider;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
click: function (args, stats) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
window.location = "/servers/server?serverId=" + stats[index].serverId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 升级提醒
|
|
||||||
*/
|
|
||||||
this.closeMessage = function (e) {
|
|
||||||
let target = e.target
|
|
||||||
while (true) {
|
|
||||||
target = target.parentNode
|
|
||||||
if (target.tagName.toUpperCase() == "DIV") {
|
|
||||||
target.style.cssText = "display: none"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
{$layout}
|
|
||||||
{$template "menu"}
|
|
||||||
{$template "/echarts"}
|
|
||||||
|
|
||||||
<div class="ui four columns grid">
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>用户总数<link-icon href="/users"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{board.totalUsers}}</span></div>
|
|
||||||
</div>
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>今日新增</h4>
|
|
||||||
<div class="value"><span>{{board.countTodayUsers}}</span></div>
|
|
||||||
</div>
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>本周新增</h4>
|
|
||||||
<div class="value"><span>{{board.countWeeklyUsers}}</span></div>
|
|
||||||
</div>
|
|
||||||
<div class="ui column no-border">
|
|
||||||
<h4>用户节点<link-icon href="/settings/userNodes"></link-icon></h4>
|
|
||||||
<div class="value"><span>{{board.countUserNodes}}</span>
|
|
||||||
<span v-if="board.countOfflineUserNodes > 0" style="font-size: 1em">
|
|
||||||
/ <a href="/settings/userNodes"><span class="red" style="font-size: 1em">{{board.countOfflineUserNodes}}离线</span></a>
|
|
||||||
</span>
|
|
||||||
<span v-else style="font-size: 1em">个</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h4>用户增长趋势</h4>
|
|
||||||
<div class="chart-box" id="daily-stat-chart"></div>
|
|
||||||
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<h4>流量排行 <span>(24小时)</span></h4>
|
|
||||||
<div class="chart-box" id="top-traffic-chart"></div>
|
|
||||||
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 系统信息 -->
|
|
||||||
<div class="ui menu tabular">
|
|
||||||
<a href="" class="item" :class="{active: nodeStatusTab == 'cpu'}" @click.prevent="selectNodeStatusTab('cpu')">用户节点CPU</a>
|
|
||||||
<a href="" class="item" :class="{active: nodeStatusTab == 'memory'}" @click.prevent="selectNodeStatusTab('memory')">用户节点内存</a>
|
|
||||||
<a href="" class="item" :class="{active: nodeStatusTab == 'load'}" @click.prevent="selectNodeStatusTab('load')">用户节点负载</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="chart-box" id="cpu-chart" v-show="nodeStatusTab == 'cpu'"></div>
|
|
||||||
<div class="chart-box" id="memory-chart" v-show="nodeStatusTab == 'memory'"></div>
|
|
||||||
<div class="chart-box" id="load-chart" v-show="nodeStatusTab == 'load'"></div>
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
Tea.context(function () {
|
|
||||||
this.$delay(function () {
|
|
||||||
this.reloadDailyStats()
|
|
||||||
this.reloadCPUChart()
|
|
||||||
this.reloadTopTrafficChart()
|
|
||||||
})
|
|
||||||
|
|
||||||
this.reloadDailyStats = function () {
|
|
||||||
let axis = teaweb.countAxis(this.dailyStats, function (v) {
|
|
||||||
return v.count
|
|
||||||
})
|
|
||||||
let max = axis.max
|
|
||||||
if (max < 10) {
|
|
||||||
max = 10
|
|
||||||
} else if (max < 100) {
|
|
||||||
max = 100
|
|
||||||
}
|
|
||||||
teaweb.renderLineChart({
|
|
||||||
id: "daily-stat-chart",
|
|
||||||
name: "用户",
|
|
||||||
values: this.dailyStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.day.substring(4, 6) + "-" + v.day.substring(6)
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
return stats[index].day.substring(4, 6) + "-" + stats[index].day.substring(6) + ":" + stats[index].count
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.count;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
max: max
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统信息
|
|
||||||
*/
|
|
||||||
this.nodeStatusTab = "cpu"
|
|
||||||
|
|
||||||
this.selectNodeStatusTab = function (tab) {
|
|
||||||
this.nodeStatusTab = tab
|
|
||||||
this.$delay(function () {
|
|
||||||
switch (tab) {
|
|
||||||
case "cpu":
|
|
||||||
this.reloadCPUChart()
|
|
||||||
break
|
|
||||||
case "memory":
|
|
||||||
this.reloadMemoryChart()
|
|
||||||
break
|
|
||||||
case "load":
|
|
||||||
this.reloadLoadChart()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadCPUChart = function () {
|
|
||||||
let axis = {unit: "%", divider: 1}
|
|
||||||
teaweb.renderLineChart({
|
|
||||||
id: "cpu-chart",
|
|
||||||
name: "CPU",
|
|
||||||
values: this.cpuValues,
|
|
||||||
x: function (v) {
|
|
||||||
return v.time
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].time + ":" + (Math.ceil(stats[args.dataIndex].value * 100 * 100) / 100) + "%"
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.value * 100;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
max: 100
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadMemoryChart = function () {
|
|
||||||
let axis = {unit: "%", divider: 1}
|
|
||||||
teaweb.renderLineChart({
|
|
||||||
id: "memory-chart",
|
|
||||||
name: "内存",
|
|
||||||
values: this.memoryValues,
|
|
||||||
x: function (v) {
|
|
||||||
return v.time
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].time + ":" + (Math.ceil(stats[args.dataIndex].value * 100 * 100) / 100) + "%"
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.value * 100;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
max: 100
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadLoadChart = function () {
|
|
||||||
let axis = {unit: "", divider: 1}
|
|
||||||
let max = this.loadValues.$map(function (k, v) {
|
|
||||||
return v.value
|
|
||||||
}).$max()
|
|
||||||
if (max < 10) {
|
|
||||||
max = 10
|
|
||||||
} else if (max < 20) {
|
|
||||||
max = 20
|
|
||||||
} else if (max < 100) {
|
|
||||||
max = 100
|
|
||||||
} else {
|
|
||||||
max = null
|
|
||||||
}
|
|
||||||
teaweb.renderLineChart({
|
|
||||||
id: "load-chart",
|
|
||||||
name: "负载",
|
|
||||||
values: this.loadValues,
|
|
||||||
x: function (v) {
|
|
||||||
return v.time
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].time + ":" + (Math.ceil(stats[args.dataIndex].value * 100) / 100)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.value;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
max: max
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 流量排行
|
|
||||||
this.reloadTopTrafficChart = function () {
|
|
||||||
let that = this
|
|
||||||
let axis = teaweb.bytesAxis(this.topTrafficStats, function (v) {
|
|
||||||
return v.bytes
|
|
||||||
})
|
|
||||||
teaweb.renderBarChart({
|
|
||||||
id: "top-traffic-chart",
|
|
||||||
name: "流量",
|
|
||||||
values: this.topTrafficStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.userName
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
return stats[index].userName + "<br/>请求数:" + " " + teaweb.formatNumber(stats[index].countRequests) + "<br/>流量:" + teaweb.formatBytes(stats[index].bytes)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.bytes / axis.divider;
|
|
||||||
},
|
|
||||||
axis: axis
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
{$layout}
|
|
||||||
|
|
||||||
{$var "header"}
|
|
||||||
<!-- world map -->
|
|
||||||
<script type="text/javascript" src="/js/echarts/echarts.min.js"></script>
|
|
||||||
<script type="text/javascript" src="/js/world.js"></script>
|
|
||||||
<script type="text/javascript" src="/js/world-countries-map.js"></script>
|
|
||||||
{$end}
|
|
||||||
|
|
||||||
{$template "menu"}
|
|
||||||
|
|
||||||
<div class="ui four columns grid">
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>今日拦截</h4>
|
|
||||||
<div class="value"><span>{{board.countDailyBlocks}}</span>次</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>今日验证码验证</h4>
|
|
||||||
<div class="value"><span>{{board.countDailyCaptcha}}</span>次</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>今日记录</h4>
|
|
||||||
<div class="value"><span>{{board.countDailyLogs}}</span>次</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui column">
|
|
||||||
<h4>本周拦截</h4>
|
|
||||||
<div class="value"><span>{{board.countWeeklyBlocks}}</span>次</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 流量地图 -->
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
<div v-if="!isLoading">
|
|
||||||
<traffic-map-box :v-stats="topCountryStats" :v-is-attack="true"></traffic-map-box>
|
|
||||||
</div>
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 最近日志 -->
|
|
||||||
<div v-if="accessLogs.length > 0">
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
<h4 class="header">最新拦截记录 <a href="/servers/logs?hasWAF=1">更多 »</a></h4>
|
|
||||||
<table class="ui table selectable">
|
|
||||||
<tr v-for="accessLog in accessLogs" :key="accessLog.requestId">
|
|
||||||
<td><http-access-log-box :v-access-log="accessLog"></http-access-log-box></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 按小时/天统计 -->
|
|
||||||
<div class="ui menu tabular">
|
|
||||||
<a href="" class="item" :class="{active: requestsTab == 'hourly'}" @click.prevent="selectRequestsTab('hourly')">24小时趋势</a>
|
|
||||||
<a href="" class="item" :class="{active: requestsTab == 'daily'}" @click.prevent="selectRequestsTab('daily')">15天趋势</a>
|
|
||||||
<div class="item right">
|
|
||||||
<span class="color-span" style="background: #F39494">拦截</span>
|
|
||||||
<span class="color-span" style="background: #FBD88A">验证码</span>
|
|
||||||
<span class="color-span" style="background: #879BD7">记录</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="chart-box" id="hourly-chart" v-show="requestsTab == 'hourly'"></div>
|
|
||||||
<div class="chart-box" id="daily-chart" v-show="requestsTab == 'daily'"></div>
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
|
|
||||||
<h4>拦截类型分布</h4>
|
|
||||||
<div class="chart-box" id="group-chart"></div>
|
|
||||||
|
|
||||||
<!-- 域名排行 -->
|
|
||||||
<h4 v-show="!isLoading">域名拦截排行 <span>(24小时)</span></h4>
|
|
||||||
<div class="chart-box" id="top-domains-chart"></div>
|
|
||||||
|
|
||||||
<div class="ui divider"></div>
|
|
||||||
|
|
||||||
<!-- 节点排行 -->
|
|
||||||
<h4 v-show="!isLoading">节点拦截排行 <span>(24小时)</span></h4>
|
|
||||||
<div class="chart-box" id="top-nodes-chart"></div>
|
|
||||||
@@ -1,248 +0,0 @@
|
|||||||
Tea.context(function () {
|
|
||||||
this.isLoading = false
|
|
||||||
|
|
||||||
this.$delay(function () {
|
|
||||||
this.board.countDailyBlocks = teaweb.formatCount(this.board.countDailyBlocks)
|
|
||||||
this.board.countDailyCaptcha = teaweb.formatCount(this.board.countDailyCaptcha)
|
|
||||||
this.board.countDailyLogs = teaweb.formatCount(this.board.countDailyLogs)
|
|
||||||
this.board.countWeeklyBlocks = teaweb.formatCount(this.board.countWeeklyBlocks)
|
|
||||||
|
|
||||||
this.reloadHourlyChart()
|
|
||||||
this.reloadGroupChart()
|
|
||||||
this.reloadAccessLogs()
|
|
||||||
this.reloadTopNodesChart()
|
|
||||||
this.reloadTopDomainsChart()
|
|
||||||
})
|
|
||||||
|
|
||||||
this.requestsTab = "hourly"
|
|
||||||
|
|
||||||
this.selectRequestsTab = function (tab) {
|
|
||||||
this.requestsTab = tab
|
|
||||||
this.$delay(function () {
|
|
||||||
switch (tab) {
|
|
||||||
case "hourly":
|
|
||||||
this.reloadHourlyChart()
|
|
||||||
break
|
|
||||||
case "daily":
|
|
||||||
this.reloadDailyChart()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadHourlyChart = function () {
|
|
||||||
let axis = teaweb.countAxis(this.hourlyStats, function (v) {
|
|
||||||
return [v.countLogs, v.countCaptcha, v.countBlocks].$max()
|
|
||||||
})
|
|
||||||
let that = this
|
|
||||||
this.reloadLineChart("hourly-chart", "按小时统计", this.hourlyStats, function (v) {
|
|
||||||
return v.hour.substring(8, 10)
|
|
||||||
}, function (args) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
let hour = that.hourlyStats[index].hour.substring(0, 4) + "-" + that.hourlyStats[index].hour.substring(4, 6) + "-" + that.hourlyStats[index].hour.substring(6, 8) + " " + that.hourlyStats[index].hour.substring(8)
|
|
||||||
return hour + "时<br/>拦截: "
|
|
||||||
+ teaweb.formatNumber(that.hourlyStats[index].countBlocks) + "<br/>验证码: " + teaweb.formatNumber(that.hourlyStats[index].countCaptcha) + "<br/>记录: " + teaweb.formatNumber(that.hourlyStats[index].countLogs)
|
|
||||||
}, axis)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadDailyChart = function () {
|
|
||||||
let axis = teaweb.countAxis(this.dailyStats, function (v) {
|
|
||||||
return [v.countLogs, v.countCaptcha, v.countBlocks].$max()
|
|
||||||
})
|
|
||||||
let that = this
|
|
||||||
this.reloadLineChart("daily-chart", "按天统计", this.dailyStats, function (v) {
|
|
||||||
return v.day.substring(4, 6) + "月" + v.day.substring(6, 8) + "日"
|
|
||||||
}, function (args) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
let day = that.dailyStats[index].day.substring(0, 4) + "-" + that.dailyStats[index].day.substring(4, 6) + "-" + that.dailyStats[index].day.substring(6, 8)
|
|
||||||
return day + "<br/>拦截: "
|
|
||||||
+ teaweb.formatNumber(that.dailyStats[index].countBlocks) + "<br/>验证码: " + teaweb.formatNumber(that.dailyStats[index].countCaptcha) + "<br/>记录: " + teaweb.formatNumber(that.dailyStats[index].countLogs)
|
|
||||||
}, axis)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadLineChart = function (chartId, name, stats, xFunc, tooltipFunc, axis) {
|
|
||||||
let chartBox = document.getElementById(chartId)
|
|
||||||
if (chartBox == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let chart = teaweb.initChart(chartBox)
|
|
||||||
let option = {
|
|
||||||
xAxis: {
|
|
||||||
data: stats.map(xFunc)
|
|
||||||
},
|
|
||||||
yAxis: {
|
|
||||||
axisLabel: {
|
|
||||||
formatter: function (value) {
|
|
||||||
return value + axis.unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
show: true,
|
|
||||||
trigger: "item",
|
|
||||||
formatter: tooltipFunc
|
|
||||||
},
|
|
||||||
grid: {
|
|
||||||
left: 42,
|
|
||||||
top: 10,
|
|
||||||
right: 20,
|
|
||||||
bottom: 20
|
|
||||||
},
|
|
||||||
series: [
|
|
||||||
{
|
|
||||||
name: name,
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.countLogs / axis.divider;
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#879BD7"
|
|
||||||
},
|
|
||||||
areaStyle: {},
|
|
||||||
stack: "总量",
|
|
||||||
smooth: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: name,
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.countCaptcha / axis.divider;
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#FBD88A"
|
|
||||||
},
|
|
||||||
areaStyle: {},
|
|
||||||
stack: "总量",
|
|
||||||
smooth: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: name,
|
|
||||||
type: "line",
|
|
||||||
data: stats.map(function (v) {
|
|
||||||
return v.countBlocks / axis.divider;
|
|
||||||
}),
|
|
||||||
itemStyle: {
|
|
||||||
color: "#F39494"
|
|
||||||
},
|
|
||||||
areaStyle: {},
|
|
||||||
stack: "总量",
|
|
||||||
smooth: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
animation: true
|
|
||||||
}
|
|
||||||
chart.setOption(option)
|
|
||||||
chart.resize()
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reloadGroupChart = function () {
|
|
||||||
let axis = teaweb.countAxis(this.groupStats, function (v) {
|
|
||||||
return v.count
|
|
||||||
})
|
|
||||||
teaweb.renderBarChart({
|
|
||||||
id: "group-chart",
|
|
||||||
values: this.groupStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.name
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.count / axis.divider
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
return stats[index].name + ": " + stats[index].count
|
|
||||||
},
|
|
||||||
axis: axis
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.accessLogs = []
|
|
||||||
this.reloadAccessLogs = function () {
|
|
||||||
this.$post(".wafLogs")
|
|
||||||
.success(function (resp) {
|
|
||||||
if (resp.data.accessLogs != null) {
|
|
||||||
let regions = resp.data.regions
|
|
||||||
|
|
||||||
let that = this
|
|
||||||
resp.data.accessLogs.forEach(function (accessLog) {
|
|
||||||
that.formatTime(accessLog)
|
|
||||||
|
|
||||||
if (typeof (regions[accessLog.remoteAddr]) == "string") {
|
|
||||||
accessLog.region = regions[accessLog.remoteAddr]
|
|
||||||
} else {
|
|
||||||
accessLog.region = ""
|
|
||||||
}
|
|
||||||
})
|
|
||||||
this.accessLogs = resp.data.accessLogs
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.done(function () {
|
|
||||||
this.$delay(this.reloadAccessLogs, 10000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.formatTime = function (accessLog) {
|
|
||||||
let elapsedSeconds = Math.ceil(new Date().getTime() / 1000) - accessLog.timestamp
|
|
||||||
if (elapsedSeconds >= 0) {
|
|
||||||
if (elapsedSeconds < 60) {
|
|
||||||
accessLog.humanTime = elapsedSeconds + "秒前"
|
|
||||||
} else if (elapsedSeconds < 3600) {
|
|
||||||
accessLog.humanTime = Math.ceil(elapsedSeconds / 60) + "分钟前"
|
|
||||||
} else if (elapsedSeconds < 3600 * 24) {
|
|
||||||
accessLog.humanTime = Math.ceil(elapsedSeconds / 3600) + "小时前"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 节点排行
|
|
||||||
this.reloadTopNodesChart = function () {
|
|
||||||
let that = this
|
|
||||||
let axis = teaweb.countAxis(this.topNodeStats, function (v) {
|
|
||||||
return v.countRequests
|
|
||||||
})
|
|
||||||
teaweb.renderBarChart({
|
|
||||||
id: "top-nodes-chart",
|
|
||||||
name: "节点",
|
|
||||||
values: this.topNodeStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.nodeName
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].nodeName + "<br/>请求数:" + " " + teaweb.formatNumber(stats[args.dataIndex].countRequests) + "<br/>流量:" + teaweb.formatBytes(stats[args.dataIndex].bytes)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.countRequests / axis.divider;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
click: function (args, stats) {
|
|
||||||
window.location = "/clusters/cluster/node?nodeId=" + stats[args.dataIndex].nodeId + "&clusterId=" + that.clusterId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 域名排行
|
|
||||||
this.reloadTopDomainsChart = function () {
|
|
||||||
let axis = teaweb.countAxis(this.topDomainStats, function (v) {
|
|
||||||
return v.countRequests
|
|
||||||
})
|
|
||||||
teaweb.renderBarChart({
|
|
||||||
id: "top-domains-chart",
|
|
||||||
name: "域名",
|
|
||||||
values: this.topDomainStats,
|
|
||||||
x: function (v) {
|
|
||||||
return v.domain
|
|
||||||
},
|
|
||||||
tooltip: function (args, stats) {
|
|
||||||
return stats[args.dataIndex].domain + "<br/>请求数:" + " " + teaweb.formatNumber(stats[args.dataIndex].countRequests) + "<br/>流量:" + teaweb.formatBytes(stats[args.dataIndex].bytes)
|
|
||||||
},
|
|
||||||
value: function (v) {
|
|
||||||
return v.countRequests / axis.divider;
|
|
||||||
},
|
|
||||||
axis: axis,
|
|
||||||
click: function (args, stats) {
|
|
||||||
let index = args.dataIndex
|
|
||||||
window.location = "/servers/server?serverId=" + stats[index].serverId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -14,6 +14,15 @@
|
|||||||
<a :href="'/clusters/cluster/createNode?clusterId=' + dashboard.defaultClusterId">还没有在集群中添加节点,现在去添加?添加节点后才可部署网站服务。</a>
|
<a :href="'/clusters/cluster/createNode?clusterId=' + dashboard.defaultClusterId">还没有在集群中添加节点,现在去添加?添加节点后才可部署网站服务。</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 新版本更新提醒 -->
|
||||||
|
<div class="ui icon message error" v-if="!isLoading && newVersionCode.length > 0">
|
||||||
|
<i class="icon warning circle"></i>
|
||||||
|
升级提醒:有新版本管理系统可以更新:v{{currentVersionCode}} -> v{{newVersionCode}}
|
||||||
|
<a href="https://goedge.cn/docs/Releases/Index.md?nav=1" target="_blank">[去官网查看]</a> <a :href="newVersionDownloadURL" target="_blank">[直接下载]</a>
|
||||||
|
|
||||||
|
<a href="" title="关闭" @click.prevent="closeMessage"><i class="ui icon remove small"></i></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- 升级提醒 -->
|
<!-- 升级提醒 -->
|
||||||
<div class="ui icon message error" v-if="!isLoading && nodeUpgradeInfo.count > 0">
|
<div class="ui icon message error" v-if="!isLoading && nodeUpgradeInfo.count > 0">
|
||||||
<i class="icon warning circle"></i>
|
<i class="icon warning circle"></i>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
<span class="ui label tiny basic" v-for="group in firewallPolicy.groups" style="margin-bottom:0.5em" :class="{disabled:!group.isOn}">{{group.name}}</span>
|
<span class="ui label tiny basic" v-for="group in firewallPolicy.groups" style="margin-bottom:0.5em" :class="{disabled:!group.isOn}">{{group.name}}</span>
|
||||||
<div v-if="upgradeItems.length > 0">
|
<div v-if="upgradeItems.length > 0">
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
<a href=""><span class="red">升级提醒:官方提供了新的规则,是否要加入以下规则:<span class="ui label tiny basic" v-for="item in upgradeItems" style="margin-bottom: 0.2em">{{item}}</span></span></a> <a href="" @click.prevent="upgradeTemplate">[加入]</a>
|
<a href=""><span class="red">升级提醒:官方提供了新的规则,是否要加入以下规则:<span class="ui label tiny basic" v-for="item in upgradeItems" style="margin-bottom: 0.2em">{{item.name}}<span v-if="!item.isOn" class="small">(默认不启用)</span></span></span></a> <a href="" @click.prevent="upgradeTemplate">[加入]</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -7,6 +7,13 @@
|
|||||||
<td class="title">当前已安装版本</td>
|
<td class="title">当前已安装版本</td>
|
||||||
<td>v{{version}}</td>
|
<td>v{{version}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>自动检查</td>
|
||||||
|
<td>
|
||||||
|
<checkbox v-model="config.autoCheck" @input="changeAutoCheck"></checkbox>
|
||||||
|
<p class="comment">选中后系统将定时检查是否有新版本更新。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr v-if="isStarted">
|
<tr v-if="isStarted">
|
||||||
<td>最新版本</td>
|
<td>最新版本</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -21,4 +21,11 @@ Tea.context(function () {
|
|||||||
this.isChecking = false
|
this.isChecking = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.changeAutoCheck = function () {
|
||||||
|
this.$post(".update")
|
||||||
|
.params({
|
||||||
|
autoCheck: this.config.autoCheck ? 1 : 0
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user