diff --git a/internal/web/actions/default/clusters/cluster/init.go b/internal/web/actions/default/clusters/cluster/init.go index 2ab975ba..ddb2398b 100644 --- a/internal/web/actions/default/clusters/cluster/init.go +++ b/internal/web/actions/default/clusters/cluster/init.go @@ -5,6 +5,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/groups" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/monitor" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/thresholds" clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" "github.com/iwind/TeaGo" @@ -45,6 +46,7 @@ func init() { Post("/node/monitor/trafficIn", new(monitor.TrafficInAction)). Post("/node/monitor/trafficOut", new(monitor.TrafficOutAction)). Post("/node/monitor/connections", new(monitor.ConnectionsAction)). + Get("/node/thresholds", new(thresholds.IndexAction)). // 分组相关 Get("/groups", new(groups.IndexAction)). diff --git a/internal/web/actions/default/clusters/cluster/node/thresholds/index.go b/internal/web/actions/default/clusters/cluster/node/thresholds/index.go new file mode 100644 index 00000000..e4254402 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/node/thresholds/index.go @@ -0,0 +1,54 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package thresholds + +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 IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "node", "threshold") +} + +func (this *IndexAction) RunGet(params struct { + ClusterId int64 + NodeId int64 +}) { + this.Data["nodeId"] = params.NodeId + + // 列出所有阈值 + thresholdsResp, err := this.RPC().NodeThresholdRPC().FindAllEnabledNodeThresholds(this.AdminContext(), &pb.FindAllEnabledNodeThresholdsRequest{ + Role: "node", + NodeClusterId: params.ClusterId, + NodeId: params.NodeId, + }) + if err != nil { + this.ErrorPage(err) + return + } + + thresholdMaps := []maps.Map{} + for _, threshold := range thresholdsResp.NodeThresholds { + thresholdMaps = append(thresholdMaps, maps.Map{ + "id": threshold.Id, + "itemName": nodeconfigs.FindNodeValueItemName(threshold.Item), + "paramName": nodeconfigs.FindNodeValueItemParamName(threshold.Item, threshold.Param), + "operatorName": nodeconfigs.FindNodeValueOperatorName(threshold.Operator), + "value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON), + "sumMethodName": nodeconfigs.FindNodeValueSumMethodName(threshold.SumMethod), + "duration": threshold.Duration, + "durationUnitName": nodeconfigs.FindNodeValueDurationUnitName(threshold.DurationUnit), + "isOn": threshold.IsOn, + }) + } + this.Data["thresholds"] = thresholdMaps + + this.Show() +} diff --git a/internal/web/actions/default/clusters/cluster/settings/thresholds/createPopup.go b/internal/web/actions/default/clusters/cluster/settings/thresholds/createPopup.go index 251be750..f62d2938 100644 --- a/internal/web/actions/default/clusters/cluster/settings/thresholds/createPopup.go +++ b/internal/web/actions/default/clusters/cluster/settings/thresholds/createPopup.go @@ -20,8 +20,10 @@ func (this *CreatePopupAction) Init() { func (this *CreatePopupAction) RunGet(params struct { ClusterId int64 + NodeId int64 }) { this.Data["clusterId"] = params.ClusterId + this.Data["nodeId"] = params.NodeId this.Data["items"] = nodeconfigs.FindAllNodeValueItemDefinitions() this.Data["operators"] = nodeconfigs.FindAllNodeValueOperatorDefinitions() @@ -29,16 +31,17 @@ func (this *CreatePopupAction) RunGet(params struct { } func (this *CreatePopupAction) RunPost(params struct { - ClusterId int64 - NodeId int64 - Item string - Param string - SumMethod string - Operator string - Value string - Duration int32 - DurationUnit string - Message string + ClusterId int64 + NodeId int64 + Item string + Param string + SumMethod string + Operator string + Value string + Duration int32 + DurationUnit string + Message string + NotifyDuration int32 Must *actions.Must CSRF *actionutils.CSRF @@ -53,16 +56,18 @@ func (this *CreatePopupAction) RunPost(params struct { return } resp, err := this.RPC().NodeThresholdRPC().CreateNodeThreshold(this.AdminContext(), &pb.CreateNodeThresholdRequest{ - NodeClusterId: params.ClusterId, - NodeId: params.NodeId, - Item: params.Item, - Param: params.Param, - Operator: params.Operator, - ValueJSON: valueJSON, - Message: params.Message, - Duration: params.Duration, - DurationUnit: params.DurationUnit, - SumMethod: params.SumMethod, + Role: "node", + NodeClusterId: params.ClusterId, + NodeId: params.NodeId, + Item: params.Item, + Param: params.Param, + Operator: params.Operator, + ValueJSON: valueJSON, + Message: params.Message, + Duration: params.Duration, + DurationUnit: params.DurationUnit, + SumMethod: params.SumMethod, + NotifyDuration: params.NotifyDuration, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/settings/thresholds/index.go b/internal/web/actions/default/clusters/cluster/settings/thresholds/index.go index d1fca8eb..9911e2c0 100644 --- a/internal/web/actions/default/clusters/cluster/settings/thresholds/index.go +++ b/internal/web/actions/default/clusters/cluster/settings/thresholds/index.go @@ -23,6 +23,7 @@ func (this *IndexAction) RunGet(params struct { }) { // 列出所有阈值 thresholdsResp, err := this.RPC().NodeThresholdRPC().FindAllEnabledNodeThresholds(this.AdminContext(), &pb.FindAllEnabledNodeThresholdsRequest{ + Role: "node", NodeClusterId: params.ClusterId, NodeId: 0, }) @@ -33,16 +34,25 @@ func (this *IndexAction) RunGet(params struct { thresholdMaps := []maps.Map{} for _, threshold := range thresholdsResp.NodeThresholds { + var nodeMap maps.Map = nil + if threshold.Node != nil { + nodeMap = maps.Map{ + "id": threshold.Node.Id, + "name": threshold.Node.Name, + } + } + thresholdMaps = append(thresholdMaps, maps.Map{ "id": threshold.Id, "itemName": nodeconfigs.FindNodeValueItemName(threshold.Item), "paramName": nodeconfigs.FindNodeValueItemParamName(threshold.Item, threshold.Param), "operatorName": nodeconfigs.FindNodeValueOperatorName(threshold.Operator), - "value": string(threshold.ValueJSON), + "value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON), "sumMethodName": nodeconfigs.FindNodeValueSumMethodName(threshold.SumMethod), "duration": threshold.Duration, "durationUnitName": nodeconfigs.FindNodeValueDurationUnitName(threshold.DurationUnit), "isOn": threshold.IsOn, + "node": nodeMap, }) } this.Data["thresholds"] = thresholdMaps diff --git a/internal/web/actions/default/clusters/cluster/settings/thresholds/updatePopup.go b/internal/web/actions/default/clusters/cluster/settings/thresholds/updatePopup.go index 23e31b02..a0647786 100644 --- a/internal/web/actions/default/clusters/cluster/settings/thresholds/updatePopup.go +++ b/internal/web/actions/default/clusters/cluster/settings/thresholds/updatePopup.go @@ -46,31 +46,33 @@ func (this *UpdatePopupAction) RunGet(params struct { } this.Data["threshold"] = maps.Map{ - "id": threshold.Id, - "item": threshold.Item, - "param": threshold.Param, - "message": threshold.Message, - "value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON), - "operator": threshold.Operator, - "duration": threshold.Duration, - "durationUnit": threshold.DurationUnit, - "isOn": threshold.IsOn, + "id": threshold.Id, + "item": threshold.Item, + "param": threshold.Param, + "message": threshold.Message, + "notifyDuration": threshold.NotifyDuration, + "value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON), + "operator": threshold.Operator, + "duration": threshold.Duration, + "durationUnit": threshold.DurationUnit, + "isOn": threshold.IsOn, } this.Show() } func (this *UpdatePopupAction) RunPost(params struct { - ThresholdId int64 - Item string - Param string - SumMethod string - Operator string - Value string - Duration int32 - DurationUnit string - Message string - IsOn bool + ThresholdId int64 + Item string + Param string + SumMethod string + Operator string + Value string + Duration int32 + DurationUnit string + Message string + NotifyDuration int32 + IsOn bool Must *actions.Must CSRF *actionutils.CSRF @@ -89,6 +91,7 @@ func (this *UpdatePopupAction) RunPost(params struct { Operator: params.Operator, ValueJSON: valueJSON, Message: params.Message, + NotifyDuration: params.NotifyDuration, Duration: params.Duration, DurationUnit: params.DurationUnit, SumMethod: params.SumMethod, diff --git a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go index a32cabf9..aa197da1 100644 --- a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go +++ b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go @@ -197,6 +197,7 @@ func (this *ClusterHelper) checkThresholds(clusterId int64) (bool, error) { return false, err } resp, err := rpcClient.NodeThresholdRPC().CountAllEnabledNodeThresholds(rpcClient.Context(0), &pb.CountAllEnabledNodeThresholdsRequest{ + Role: "node", NodeClusterId: clusterId, }) if err != nil { diff --git a/web/views/@default/clusters/cluster/node/@node_menu.html b/web/views/@default/clusters/cluster/node/@node_menu.html index eed3b382..21833c54 100644 --- a/web/views/@default/clusters/cluster/node/@node_menu.html +++ b/web/views/@default/clusters/cluster/node/@node_menu.html @@ -3,6 +3,7 @@ | 节点详情 监控图表 + 阈值设置 运行日志 修改设置 安装节点 diff --git a/web/views/@default/clusters/cluster/node/monitor/index.html b/web/views/@default/clusters/cluster/node/monitor/index.html index 37fbb5cf..add7a8a6 100644 --- a/web/views/@default/clusters/cluster/node/monitor/index.html +++ b/web/views/@default/clusters/cluster/node/monitor/index.html @@ -6,10 +6,10 @@ {$end} -

上行流量

+

上行流量(字节)

-

下行流量

+

下行流量(字节)

连接数

diff --git a/web/views/@default/clusters/cluster/node/thresholds/index.html b/web/views/@default/clusters/cluster/node/thresholds/index.html new file mode 100644 index 00000000..14c0a26d --- /dev/null +++ b/web/views/@default/clusters/cluster/node/thresholds/index.html @@ -0,0 +1,37 @@ +{$layout} +{$template "../node_menu"} + +
+ + 添加阈值 + +
+ +

暂时还没有设置阈值。

+ + + + + + + + + + + + + + + + + + + + + +
监控项参数操作符对比值统计时间段状态操作
{{threshold.itemName}}{{threshold.paramName}}{{threshold.operatorName}}{{threshold.value}}{{threshold.duration}}{{threshold.durationUnitName}} + + + 修改   + 删除 +
\ No newline at end of file diff --git a/web/views/@default/clusters/cluster/node/thresholds/index.js b/web/views/@default/clusters/cluster/node/thresholds/index.js new file mode 100644 index 00000000..3770bf29 --- /dev/null +++ b/web/views/@default/clusters/cluster/node/thresholds/index.js @@ -0,0 +1,41 @@ +Tea.context(function () { + this.createThreshold = function () { + teaweb.popup(Tea.url("/clusters/cluster/settings/thresholds/createPopup", { + clusterId: this.clusterId, + nodeId: this.nodeId + }), { + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } + + this.updateThreshold = function (thresholdId) { + teaweb.popup(Tea.url("/clusters/cluster/settings/thresholds/updatePopup", { + thresholdId: thresholdId + }), { + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } + + this.deleteThreshold = function (thresholdId) { + let that = this + teaweb.confirm("确定要删除这个阈值吗?", function () { + that.$post(".delete") + .params({ + thresholdId: thresholdId + }) + .success(function () { + teaweb.success("删除成功", function () { + teaweb.reload() + }) + }) + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/thresholds/createPopup.html b/web/views/@default/clusters/cluster/settings/thresholds/createPopup.html index abd7ecd4..2505e606 100644 --- a/web/views/@default/clusters/cluster/settings/thresholds/createPopup.html +++ b/web/views/@default/clusters/cluster/settings/thresholds/createPopup.html @@ -4,6 +4,7 @@
+ @@ -55,12 +56,31 @@ - - + + + + + + + + + + +
消息 - -

触发阈值时的消息提示。

-
消息 + +

触发阈值时的消息提示。

+
消息通知间隔 +
+
+ +
+
+ 分钟 +
+
+

在此间隔内将不会重复发送跟此阈值相关的消息。

+
diff --git a/web/views/@default/clusters/cluster/settings/thresholds/index.html b/web/views/@default/clusters/cluster/settings/thresholds/index.html index 7b4cdde9..54457c0b 100644 --- a/web/views/@default/clusters/cluster/settings/thresholds/index.html +++ b/web/views/@default/clusters/cluster/settings/thresholds/index.html @@ -7,7 +7,7 @@

暂时还没有设置阈值。

- +
@@ -20,10 +20,14 @@ - + - + - - - - - - + + + + + + + + + + + + + + +
监控项
{{threshold.itemName}}{{threshold.itemName}} + + {{threshold.paramName}} {{threshold.operatorName}}{{threshold.itemName}}{{threshold.value}} {{threshold.duration}}{{threshold.durationUnitName}} diff --git a/web/views/@default/clusters/cluster/settings/thresholds/updatePopup.html b/web/views/@default/clusters/cluster/settings/thresholds/updatePopup.html index 16ee9e0b..b239237a 100644 --- a/web/views/@default/clusters/cluster/settings/thresholds/updatePopup.html +++ b/web/views/@default/clusters/cluster/settings/thresholds/updatePopup.html @@ -55,18 +55,37 @@
消息 - -

触发阈值时的消息提示。

-
是否启用 - -
消息 + +

触发阈值时的消息提示。

+
消息通知间隔 +
+
+ +
+
+ 分钟 +
+
+

在此间隔内将不会重复发送跟此阈值相关的消息。

+
是否启用 + +