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 @@
|
暂时还没有设置阈值。
+| 监控项 | +参数 | +操作符 | +对比值 | +统计时间段 | +状态 | +操作 | +
|---|---|---|---|---|---|---|
| {{threshold.itemName}} | +{{threshold.paramName}} | +{{threshold.operatorName}} | +{{threshold.value}} | +{{threshold.duration}}{{threshold.durationUnitName}} | +
+ |
+ + 修改 + 删除 + | +