diff --git a/internal/web/actions/default/clusters/cluster/init.go b/internal/web/actions/default/clusters/cluster/init.go index 49237a30..2ab975ba 100644 --- a/internal/web/actions/default/clusters/cluster/init.go +++ b/internal/web/actions/default/clusters/cluster/init.go @@ -44,6 +44,7 @@ func init() { Post("/node/monitor/load", new(monitor.LoadAction)). Post("/node/monitor/trafficIn", new(monitor.TrafficInAction)). Post("/node/monitor/trafficOut", new(monitor.TrafficOutAction)). + Post("/node/monitor/connections", new(monitor.ConnectionsAction)). // 分组相关 Get("/groups", new(groups.IndexAction)). diff --git a/internal/web/actions/default/clusters/cluster/node/monitor/connections.go b/internal/web/actions/default/clusters/cluster/node/monitor/connections.go new file mode 100644 index 00000000..f4aa111f --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/node/monitor/connections.go @@ -0,0 +1,73 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package monitor + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils" + "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" + "time" +) + +type ConnectionsAction struct { + actionutils.ParentAction +} + +func (this *ConnectionsAction) RunPost(params struct { + NodeId int64 +}) { + resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{ + Role: "node", + NodeId: params.NodeId, + Item: nodeconfigs.NodeValueItemConnections, + Range: nodeconfigs.NodeValueRangeMinute, + }) + if err != nil { + this.ErrorPage(err) + return + } + valuesMap := map[string]int64{} // YmdHi => count + for _, v := range resp.NodeValues { + if len(v.ValueJSON) == 0 { + continue + } + + valueMap := maps.Map{} + err = json.Unmarshal(v.ValueJSON, &valueMap) + if err != nil { + this.ErrorPage(err) + return + } + + valuesMap[timeutil.FormatTime("YmdHi", v.CreatedAt)] = valueMap.GetInt64("total") + } + + // 过去一个小时 + result := []maps.Map{} + for i := 60; i >= 1; i-- { + timestamp := time.Now().Unix() - int64(i)*60 + minute := timeutil.FormatTime("YmdHi", timestamp) + total, ok := valuesMap[minute] + if ok { + result = append(result, maps.Map{ + "label": timeutil.FormatTime("H:i", timestamp), + "value": total, + "text": numberutils.FormatInt64(total), + }) + } else { + result = append(result, maps.Map{ + "label": timeutil.FormatTime("H:i", timestamp), + "value": 0, + "text": "0", + }) + } + } + + this.Data["values"] = result + + this.Success() +} diff --git a/web/views/@default/clusters/cluster/node/monitor/index.html b/web/views/@default/clusters/cluster/node/monitor/index.html index 615d7b37..37fbb5cf 100644 --- a/web/views/@default/clusters/cluster/node/monitor/index.html +++ b/web/views/@default/clusters/cluster/node/monitor/index.html @@ -12,6 +12,9 @@

下行流量

+

连接数

+
+

CPU

diff --git a/web/views/@default/clusters/cluster/node/monitor/index.js b/web/views/@default/clusters/cluster/node/monitor/index.js index 8af4923b..0bdb748c 100644 --- a/web/views/@default/clusters/cluster/node/monitor/index.js +++ b/web/views/@default/clusters/cluster/node/monitor/index.js @@ -2,6 +2,7 @@ Tea.context(function () { this.$delay(function () { this.loadTrafficInChart() this.loadTrafficOutChart() + this.loadConnectionsChart() this.loadCPUChart() this.loadMemoryChart() this.loadLoadChart() @@ -10,6 +11,7 @@ Tea.context(function () { window.addEventListener("resize", function () { that.resizeChart("traffic-in-chart") that.resizeChart("traffic-out-chart") + that.resizeChart("connections-chart") that.resizeChart("cpu-chart") that.resizeChart("memory-chart") that.resizeChart("load-chart") @@ -84,6 +86,40 @@ Tea.context(function () { }) } + this.loadConnectionsChart = function () { + this.$post(".connections") + .params({ + nodeId: this.nodeId + }) + .success(function (resp) { + let values = resp.data.values + let maxFunc = function () { + let max = values.map(function (v) { + return v.value + }).$max() + if (max < 10) { + return 10 + } + if (max < 100) { + return 100 + } + if (max < 1000) { + return 1000 + } + return null + } + let valueFunc = function (v) { + return v.value + } + this.reloadChart("connections-chart", "", values, "", maxFunc, valueFunc) + }) + .done(function () { + this.$delay(function () { + this.loadConnectionsChart() + }, 30000) + }) + } + this.loadCPUChart = function () { this.$post(".cpu") .params({