diff --git a/internal/web/actions/default/clusters/cluster/createNode.go b/internal/web/actions/default/clusters/cluster/createNode.go index d8773a2b..21fa535f 100644 --- a/internal/web/actions/default/clusters/cluster/createNode.go +++ b/internal/web/actions/default/clusters/cluster/createNode.go @@ -175,12 +175,19 @@ func (this *CreateNodeAction) RunPost(params struct { NodeId: nodeId, }) } else { + var thresholdsJSON = []byte{} + var thresholds = address.GetSlice("thresholds") + if len(thresholds) > 0 { + thresholdsJSON, _ = json.Marshal(thresholds) + } + _, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{ - NodeId: nodeId, - Role: nodeconfigs.NodeRoleNode, - Name: address.GetString("name"), - Ip: address.GetString("ip"), - CanAccess: address.GetBool("canAccess"), + NodeId: nodeId, + Role: nodeconfigs.NodeRoleNode, + Name: address.GetString("name"), + Ip: address.GetString("ip"), + CanAccess: address.GetBool("canAccess"), + ThresholdsJSON: thresholdsJSON, }) } if err != nil { diff --git a/internal/web/actions/default/clusters/cluster/node/detail.go b/internal/web/actions/default/clusters/cluster/node/detail.go index 7044123d..49a9a418 100644 --- a/internal/web/actions/default/clusters/cluster/node/detail.go +++ b/internal/web/actions/default/clusters/cluster/node/detail.go @@ -79,13 +79,22 @@ func (this *DetailAction) RunGet(params struct { var ipAddresses = ipAddressesResp.Addresses ipAddressMaps := []maps.Map{} for _, addr := range ipAddressesResp.Addresses { + var thresholds = []*nodeconfigs.NodeValueThresholdConfig{} + if len(addr.ThresholdsJSON) > 0 { + err = json.Unmarshal(addr.ThresholdsJSON, &thresholds) + if err != nil { + this.ErrorPage(err) + return + } + } ipAddressMaps = append(ipAddressMaps, maps.Map{ - "id": addr.Id, - "name": addr.Name, - "ip": addr.Ip, - "canAccess": addr.CanAccess, - "isOn": addr.IsOn, - "isUp": addr.IsUp, + "id": addr.Id, + "name": addr.Name, + "ip": addr.Ip, + "canAccess": addr.CanAccess, + "isOn": addr.IsOn, + "isUp": addr.IsUp, + "thresholds": thresholds, }) } diff --git a/internal/web/actions/default/clusters/cluster/node/update.go b/internal/web/actions/default/clusters/cluster/node/update.go index f2f5f40a..7a8ccd97 100644 --- a/internal/web/actions/default/clusters/cluster/node/update.go +++ b/internal/web/actions/default/clusters/cluster/node/update.go @@ -57,13 +57,23 @@ func (this *UpdateAction) RunGet(params struct { } ipAddressMaps := []maps.Map{} for _, addr := range ipAddressesResp.Addresses { + var thresholds = []*nodeconfigs.NodeValueThresholdConfig{} + if len(addr.ThresholdsJSON) > 0 { + err = json.Unmarshal(addr.ThresholdsJSON, &thresholds) + if err != nil { + this.ErrorPage(err) + return + } + } + ipAddressMaps = append(ipAddressMaps, maps.Map{ - "id": addr.Id, - "name": addr.Name, - "ip": addr.Ip, - "canAccess": addr.CanAccess, - "isOn": addr.IsOn, - "isUp": addr.IsUp, + "id": addr.Id, + "name": addr.Name, + "ip": addr.Ip, + "canAccess": addr.CanAccess, + "isOn": addr.IsOn, + "isUp": addr.IsUp, + "thresholds": thresholds, }) } diff --git a/internal/web/actions/default/nodes/ipAddresses/createPopup.go b/internal/web/actions/default/nodes/ipAddresses/createPopup.go index 57541bcd..7f565c97 100644 --- a/internal/web/actions/default/nodes/ipAddresses/createPopup.go +++ b/internal/web/actions/default/nodes/ipAddresses/createPopup.go @@ -1,7 +1,10 @@ package ipAddresses import ( + "encoding/json" + teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" "net" @@ -16,18 +19,18 @@ func (this *CreatePopupAction) Init() { } func (this *CreatePopupAction) RunGet(params struct{}) { + this.Show() } func (this *CreatePopupAction) RunPost(params struct { - IP string `alias:"ip"` - CanAccess bool - Name string + IP string `alias:"ip"` + CanAccess bool + Name string + ThresholdsJSON []byte Must *actions.Must }) { - // TODO 严格校验IP地址 - ip := net.ParseIP(params.IP) if len(ip) == 0 { this.Fail("请输入正确的IP") @@ -37,13 +40,19 @@ func (this *CreatePopupAction) RunPost(params struct { Field("ip", params.IP). Require("请输入IP地址") + var thresholds = []*nodeconfigs.NodeValueThresholdConfig{} + if teaconst.IsPlus && len(params.ThresholdsJSON) > 0 { + _ = json.Unmarshal(params.ThresholdsJSON, &thresholds) + } + this.Data["ipAddress"] = maps.Map{ - "name": params.Name, - "canAccess": params.CanAccess, - "ip": params.IP, - "id": 0, - "isOn": true, - "isUp": true, + "name": params.Name, + "canAccess": params.CanAccess, + "ip": params.IP, + "id": 0, + "isOn": true, + "isUp": true, + "thresholds": thresholds, } this.Success() } diff --git a/internal/web/actions/default/nodes/ipAddresses/ipaddressutils/utils.go b/internal/web/actions/default/nodes/ipAddresses/ipaddressutils/utils.go index c62a66fe..23ae436c 100644 --- a/internal/web/actions/default/nodes/ipAddresses/ipaddressutils/utils.go +++ b/internal/web/actions/default/nodes/ipAddresses/ipaddressutils/utils.go @@ -16,6 +16,12 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64, return err } for _, addr := range addresses { + var thresholdsJSON = []byte{} + var thresholds = addr.GetSlice("thresholds") + if len(thresholds) > 0 { + thresholdsJSON, _ = json.Marshal(thresholds) + } + addrId := addr.GetInt64("id") if addrId > 0 { var isOn = false @@ -24,23 +30,26 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64, } else { isOn = addr.GetBool("isOn") } + _, err = parentAction.RPC().NodeIPAddressRPC().UpdateNodeIPAddress(parentAction.AdminContext(), &pb.UpdateNodeIPAddressRequest{ - AddressId: addrId, - Ip: addr.GetString("ip"), - Name: addr.GetString("name"), - CanAccess: addr.GetBool("canAccess"), - IsOn: isOn, + AddressId: addrId, + Ip: addr.GetString("ip"), + Name: addr.GetString("name"), + CanAccess: addr.GetBool("canAccess"), + IsOn: isOn, + ThresholdsJSON: thresholdsJSON, }) if err != nil { return err } } else { _, err = parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddress(parentAction.AdminContext(), &pb.CreateNodeIPAddressRequest{ - NodeId: nodeId, - Role: role, - Name: addr.GetString("name"), - Ip: addr.GetString("ip"), - CanAccess: addr.GetBool("canAccess"), + NodeId: nodeId, + Role: role, + Name: addr.GetString("name"), + Ip: addr.GetString("ip"), + CanAccess: addr.GetBool("canAccess"), + ThresholdsJSON: thresholdsJSON, }) if err != nil { return err diff --git a/internal/web/actions/default/nodes/ipAddresses/updatePopup.go b/internal/web/actions/default/nodes/ipAddresses/updatePopup.go index 65d92e7f..57672da2 100644 --- a/internal/web/actions/default/nodes/ipAddresses/updatePopup.go +++ b/internal/web/actions/default/nodes/ipAddresses/updatePopup.go @@ -1,7 +1,10 @@ package ipAddresses import ( + "encoding/json" + teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "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" @@ -23,11 +26,12 @@ func (this *UpdatePopupAction) RunGet(params struct { } func (this *UpdatePopupAction) RunPost(params struct { - AddressId int64 - IP string `alias:"ip"` - Name string - CanAccess bool - IsOn bool + AddressId int64 + IP string `alias:"ip"` + Name string + CanAccess bool + IsOn bool + ThresholdsJSON []byte Must *actions.Must }) { @@ -36,14 +40,18 @@ func (this *UpdatePopupAction) RunPost(params struct { Require("请输入IP地址") // 获取IP地址信息 - addressResp, err := this.RPC().NodeIPAddressRPC().FindEnabledNodeIPAddress(this.AdminContext(), &pb.FindEnabledNodeIPAddressRequest{AddressId: params.AddressId}) - if err != nil { - this.ErrorPage(err) - return - } - var address = addressResp.IpAddress - if address == nil { - this.Fail("找不到要修改的地址") + var isUp = true + if params.AddressId > 0 { + addressResp, err := this.RPC().NodeIPAddressRPC().FindEnabledNodeIPAddress(this.AdminContext(), &pb.FindEnabledNodeIPAddressRequest{AddressId: params.AddressId}) + if err != nil { + this.ErrorPage(err) + return + } + var address = addressResp.IpAddress + if address == nil { + this.Fail("找不到要修改的地址") + } + isUp = address.IsUp } ip := net.ParseIP(params.IP) @@ -51,13 +59,19 @@ func (this *UpdatePopupAction) RunPost(params struct { this.Fail("请输入正确的IP") } + var thresholds = []*nodeconfigs.NodeValueThresholdConfig{} + if teaconst.IsPlus && len(params.ThresholdsJSON) > 0 { + _ = json.Unmarshal(params.ThresholdsJSON, &thresholds) + } + this.Data["ipAddress"] = maps.Map{ - "name": params.Name, - "ip": params.IP, - "id": params.AddressId, - "canAccess": params.CanAccess, - "isOn": params.IsOn, - "isUp": address.IsUp, + "name": params.Name, + "ip": params.IP, + "id": params.AddressId, + "canAccess": params.CanAccess, + "isOn": params.IsOn, + "isUp": isUp, + "thresholds": thresholds, } this.Success() diff --git a/web/public/js/components/node/node-ip-address-thresholds-box.js b/web/public/js/components/node/node-ip-address-thresholds-box.js new file mode 100644 index 00000000..d4be0912 --- /dev/null +++ b/web/public/js/components/node/node-ip-address-thresholds-box.js @@ -0,0 +1,213 @@ +// 节点IP阈值 +Vue.component("node-ip-address-thresholds-box", { + props: ["v-thresholds"], + data: function () { + let thresholds = this.vThresholds + if (thresholds == null) { + thresholds = [] + } + + let avgRequests = { + duration: "", + operator: "lt", + value: "" + } + + let avgTrafficOut = { + duration: "", + operator: "lt", + value: "" + } + + let avgTrafficIn = { + duration: "", + operator: "lt", + value: "" + } + + thresholds.forEach(function (v) { + switch (v.item) { + case "avgRequests": + avgRequests.duration = v.duration + avgRequests.operator = v.operator + avgRequests.value = v.value.toString() + break + case "avgTrafficOut": + avgTrafficOut.duration = v.duration + avgTrafficOut.operator = v.operator + avgTrafficOut.value = v.value.toString() + break + case "avgTrafficIn": + avgTrafficIn.duration = v.duration + avgTrafficIn.operator = v.operator + avgTrafficIn.value = v.value.toString() + break + } + }) + + return { + thresholds: thresholds, + avgRequests: avgRequests, + avgTrafficOut: avgTrafficOut, + avgTrafficIn: avgTrafficIn + } + }, + watch: { + "avgRequests.duration": function () { + this.compose() + }, + "avgRequests.operator": function () { + this.compose() + }, + "avgRequests.value": function () { + this.compose() + }, + "avgTrafficOut.duration": function () { + this.compose() + }, + "avgTrafficOut.operator": function () { + this.compose() + }, + "avgTrafficOut.value": function () { + this.compose() + }, + "avgTrafficIn.duration": function () { + this.compose() + }, + "avgTrafficIn.operator": function () { + this.compose() + }, + "avgTrafficIn.value": function () { + this.compose() + } + }, + methods: { + compose: function () { + let thresholds = [] + + // avg requests + { + let duration = parseInt(this.avgRequests.duration) + let value = parseInt(this.avgRequests.value) + if (!isNaN(duration) && duration > 0 && !isNaN(value) && value > 0) { + thresholds.push({ + item: "avgRequests", + operator: this.avgRequests.operator, + duration: duration, + durationUnit: "minute", + value: value + }) + } + } + + // avg traffic out + { + let duration = parseInt(this.avgTrafficOut.duration) + let value = parseInt(this.avgTrafficOut.value) + if (!isNaN(duration) && duration > 0 && !isNaN(value) && value > 0) { + thresholds.push({ + item: "avgTrafficOut", + operator: this.avgTrafficOut.operator, + duration: duration, + durationUnit: "minute", + value: value + }) + } + } + + // avg requests + { + let duration = parseInt(this.avgTrafficIn.duration) + let value = parseInt(this.avgTrafficIn.value) + if (!isNaN(duration) && duration > 0 && !isNaN(value) && value > 0) { + thresholds.push({ + item: "avgTrafficIn", + operator: this.avgTrafficIn.operator, + duration: duration, + durationUnit: "minute", + value: value + }) + } + } + + this.thresholds = thresholds + } + }, + template: `
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
统计项目统计周期操作符对比值
平均请求数/秒 +
+ + 分钟 +
+
+ + +
+ + +
+
平均下行流量/秒 +
+ + 分钟 +
+
+ + +
+ + MB +
+
平均上行流量/秒 +
+ + 分钟 +
+
+ + +
+ + MB +
+
+

满足所有阈值条件时IP才会上线,否则下线。统计周期和对比值设置为0表示没有限制。各个输入项只支持整数数字。

+
` +}) \ No newline at end of file diff --git a/web/public/js/components/node/node-ip-addresses-box.js b/web/public/js/components/node/node-ip-addresses-box.js index 829f4a44..4bebe135 100644 --- a/web/public/js/components/node/node-ip-addresses-box.js +++ b/web/public/js/components/node/node-ip-addresses-box.js @@ -15,7 +15,9 @@ Vue.component("node-ip-addresses-box", { teaweb.popup("/nodes/ipAddresses/createPopup", { callback: function (resp) { that.ipAddresses.push(resp.data.ipAddress); - } + }, + height: "24em", + width: "44em" }) }, @@ -27,7 +29,9 @@ Vue.component("node-ip-addresses-box", { teaweb.popup("/nodes/ipAddresses/updatePopup", { callback: function (resp) { Vue.set(that.ipAddresses, index, resp.data.ipAddress); - } + }, + height: "24em", + width: "44em" }) }, @@ -51,6 +55,7 @@ Vue.component("node-ip-addresses-box", { (不可访问) [off] [down] + [阈值]   diff --git a/web/views/@default/clusters/cluster/node/detail.html b/web/views/@default/clusters/cluster/node/detail.html index 4ed4faab..6acdd264 100644 --- a/web/views/@default/clusters/cluster/node/detail.html +++ b/web/views/@default/clusters/cluster/node/detail.html @@ -29,6 +29,7 @@ (不可访问) [off] [down] + [阈值] diff --git a/web/views/@default/nodes/ipAddresses/createPopup.html b/web/views/@default/nodes/ipAddresses/createPopup.html index 45127632..ff0db06a 100644 --- a/web/views/@default/nodes/ipAddresses/createPopup.html +++ b/web/views/@default/nodes/ipAddresses/createPopup.html @@ -20,12 +20,23 @@

是否为可以公开访问的IP,如果选中,也会作为DNS解析记录的值使用。

- - 备注 - - - - + + + + + + 备注 + + + + + + 上线阈值 + + + + + \ No newline at end of file diff --git a/web/views/@default/nodes/ipAddresses/updatePopup.html b/web/views/@default/nodes/ipAddresses/updatePopup.html index 3bcc96e5..3855af07 100644 --- a/web/views/@default/nodes/ipAddresses/updatePopup.html +++ b/web/views/@default/nodes/ipAddresses/updatePopup.html @@ -41,6 +41,12 @@ + + 上线阈值 + + + +