mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-11 18:30:25 +08:00
阶段性提交
This commit is contained in:
@@ -388,6 +388,14 @@ func (this *RPCClient) NSAccessLogRPC() pb.NSAccessLogServiceClient {
|
||||
return pb.NewNSAccessLogServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
func (this *RPCClient) MetricItemRPC() pb.MetricItemServiceClient {
|
||||
return pb.NewMetricItemServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
func (this *RPCClient) NodeClusterMetricItemRPC() pb.NodeClusterMetricItemServiceClient {
|
||||
return pb.NewNodeClusterMetricItemServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
// Context 构造Admin上下文
|
||||
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -32,6 +32,9 @@ func (this *RunPopupAction) RunPost(params struct {
|
||||
this.Fail(err.Error())
|
||||
}
|
||||
|
||||
if resp.Results == nil {
|
||||
resp.Results = []*pb.ExecuteNodeClusterHealthCheckResponse_Result{}
|
||||
}
|
||||
this.Data["results"] = resp.Results
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
firewallActions "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/firewall-actions"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/health"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/message"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/metrics"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/services"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/thresholds"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/toa"
|
||||
@@ -67,6 +68,12 @@ func init() {
|
||||
GetPost("/updatePopup", new(thresholds.UpdatePopupAction)).
|
||||
Post("/delete", new(thresholds.DeleteAction)).
|
||||
|
||||
// 指标
|
||||
Prefix("/clusters/cluster/settings/metrics").
|
||||
Get("", new(metrics.IndexAction)).
|
||||
GetPost("/createPopup", new(metrics.CreatePopupAction)).
|
||||
Post("/delete", new(metrics.DeleteAction)).
|
||||
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
Category string
|
||||
}) {
|
||||
if len(params.Category) == 0 {
|
||||
params.Category = "http"
|
||||
}
|
||||
this.Data["category"] = params.Category
|
||||
|
||||
countResp, err := this.RPC().MetricItemRPC().CountAllEnabledMetricItems(this.AdminContext(), &pb.CountAllEnabledMetricItemsRequest{Category: params.Category})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
page := this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
itemsResp, err := this.RPC().MetricItemRPC().ListEnabledMetricItems(this.AdminContext(), &pb.ListEnabledMetricItemsRequest{
|
||||
Category: params.Category,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var itemMaps = []maps.Map{}
|
||||
for _, item := range itemsResp.MetricItems {
|
||||
itemMaps = append(itemMaps, maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"isOn": item.IsOn,
|
||||
"period": item.Period,
|
||||
"periodUnit": item.PeriodUnit,
|
||||
"keys": item.Keys,
|
||||
"value": item.Value,
|
||||
"category": item.Category,
|
||||
})
|
||||
}
|
||||
this.Data["items"] = itemMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct{}) {
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "setting", "setting")
|
||||
this.SecondMenu("metric")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
Category string
|
||||
}) {
|
||||
if len(params.Category) == 0 {
|
||||
params.Category = "http"
|
||||
}
|
||||
this.Data["category"] = params.Category
|
||||
|
||||
itemsResp, err := this.RPC().NodeClusterMetricItemRPC().FindAllNodeClusterMetricItems(this.AdminContext(), &pb.FindAllNodeClusterMetricItemsRequest{NodeClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var itemMaps = []maps.Map{}
|
||||
for _, item := range itemsResp.MetricItems {
|
||||
itemMaps = append(itemMaps, maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"isOn": item.IsOn,
|
||||
"period": item.Period,
|
||||
"periodUnit": item.PeriodUnit,
|
||||
"keys": item.Keys,
|
||||
"value": item.Value,
|
||||
"category": item.Category,
|
||||
})
|
||||
}
|
||||
this.Data["items"] = itemMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
package clusterutils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||
"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/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
@@ -39,7 +36,8 @@ func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext
|
||||
action.Data["clusterId"] = clusterId
|
||||
|
||||
if clusterId > 0 {
|
||||
cluster, err := dao.SharedNodeClusterDAO.FindEnabledNodeCluster(actionPtr.(rpc.ContextInterface).AdminContext(), clusterId)
|
||||
var ctx = actionPtr.(rpc.ContextInterface).AdminContext()
|
||||
cluster, err := dao.SharedNodeClusterDAO.FindEnabledNodeCluster(ctx, clusterId)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
@@ -49,6 +47,16 @@ func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext
|
||||
return
|
||||
}
|
||||
|
||||
clusterInfo, err := dao.SharedNodeClusterDAO.FindEnabledNodeClusterConfigInfo(ctx, clusterId)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
if clusterInfo == nil {
|
||||
action.WriteString("can not find cluster info")
|
||||
return
|
||||
}
|
||||
|
||||
tabbar := actionutils.NewTabbar()
|
||||
tabbar.Add("集群列表", "", "/clusters", "", false)
|
||||
tabbar.Add("集群节点", "", "/clusters/cluster?clusterId="+clusterIdString, "server", selectedTabbar == "node")
|
||||
@@ -65,7 +73,7 @@ func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext
|
||||
secondMenuItem := action.Data.GetString("secondMenuItem")
|
||||
switch selectedTabbar {
|
||||
case "setting":
|
||||
action.Data["leftMenuItems"] = this.createSettingMenu(cluster, secondMenuItem)
|
||||
action.Data["leftMenuItems"] = this.createSettingMenu(cluster, clusterInfo, secondMenuItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +81,7 @@ func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext
|
||||
}
|
||||
|
||||
// 设置菜单
|
||||
func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedItem string) (items []maps.Map) {
|
||||
func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, info *pb.FindEnabledNodeClusterConfigInfoResponse, selectedItem string) (items []maps.Map) {
|
||||
clusterId := numberutils.FormatInt64(cluster.Id)
|
||||
items = append(items, maps.Map{
|
||||
"name": "基础设置",
|
||||
@@ -93,25 +101,19 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt
|
||||
"isOn": cluster.HttpFirewallPolicyId > 0,
|
||||
})
|
||||
|
||||
{
|
||||
hasActions, _ := this.checkFirewallActions(cluster.Id)
|
||||
items = append(items, maps.Map{
|
||||
"name": "WAF动作",
|
||||
"url": "/clusters/cluster/settings/firewall-actions?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "firewallAction",
|
||||
"isOn": hasActions,
|
||||
})
|
||||
}
|
||||
items = append(items, maps.Map{
|
||||
"name": "WAF动作",
|
||||
"url": "/clusters/cluster/settings/firewall-actions?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "firewallAction",
|
||||
"isOn": info != nil && info.HasFirewallActions,
|
||||
})
|
||||
|
||||
{
|
||||
healthCheckIsOn, _ := this.checkHealthCheckIsOn(cluster.Id)
|
||||
items = append(items, maps.Map{
|
||||
"name": "健康检查",
|
||||
"url": "/clusters/cluster/settings/health?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "health",
|
||||
"isOn": healthCheckIsOn,
|
||||
})
|
||||
}
|
||||
items = append(items, maps.Map{
|
||||
"name": "健康检查",
|
||||
"url": "/clusters/cluster/settings/health?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "health",
|
||||
"isOn": info != nil && info.HealthCheckIsOn,
|
||||
})
|
||||
|
||||
items = append(items, maps.Map{
|
||||
"name": "DNS设置",
|
||||
@@ -119,22 +121,26 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt
|
||||
"isActive": selectedItem == "dns",
|
||||
"isOn": cluster.DnsDomainId > 0 || len(cluster.DnsName) > 0,
|
||||
})
|
||||
/**items = append(items, maps.Map{
|
||||
"name": "统计指标",
|
||||
"url": "/clusters/cluster/settings/metrics?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "metric",
|
||||
"isOn": info != nil && info.HasMetricItems,
|
||||
})**/
|
||||
|
||||
if teaconst.IsPlus {
|
||||
hasThresholds, _ := this.checkThresholds(cluster.Id)
|
||||
items = append(items, maps.Map{
|
||||
"name": "阈值设置",
|
||||
"url": "/clusters/cluster/settings/thresholds?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "threshold",
|
||||
"isOn": hasThresholds,
|
||||
"isOn": info != nil && info.HasThresholds,
|
||||
})
|
||||
}
|
||||
if teaconst.IsPlus {
|
||||
hasMessageReceivers, _ := this.checkMessages(cluster.Id)
|
||||
|
||||
items = append(items, maps.Map{
|
||||
"name": "消息通知",
|
||||
"url": "/clusters/cluster/settings/message?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "message",
|
||||
"isOn": hasMessageReceivers,
|
||||
"isOn": info != nil && info.HasMessageReceivers,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -150,99 +156,12 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt
|
||||
"isActive": selectedItem == "service",
|
||||
})
|
||||
{
|
||||
isChecked, _ := this.checkTOA(cluster.Id)
|
||||
items = append(items, maps.Map{
|
||||
"name": "TOA设置",
|
||||
"url": "/clusters/cluster/settings/toa?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "toa",
|
||||
"isOn": isChecked,
|
||||
"isOn": info != nil && info.IsTOAEnabled,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 检查健康检查是否开启
|
||||
func (this *ClusterHelper) checkHealthCheckIsOn(clusterId int64) (bool, error) {
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
resp, err := rpcClient.NodeClusterRPC().FindNodeClusterHealthCheckConfig(rpcClient.Context(0), &pb.FindNodeClusterHealthCheckConfigRequest{NodeClusterId: clusterId})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(resp.HealthCheckJSON) > 0 {
|
||||
healthCheckConfig := &serverconfigs.HealthCheckConfig{}
|
||||
err = json.Unmarshal(resp.HealthCheckJSON, healthCheckConfig)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return healthCheckConfig.IsOn, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 检查是否有WAF动作
|
||||
func (this *ClusterHelper) checkFirewallActions(clusterId int64) (bool, error) {
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
resp, err := rpcClient.NodeClusterFirewallActionRPC().CountAllEnabledNodeClusterFirewallActions(rpcClient.Context(0), &pb.CountAllEnabledNodeClusterFirewallActionsRequest{NodeClusterId: clusterId})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return resp.Count > 0, nil
|
||||
}
|
||||
|
||||
// 检查阈值是否已经设置
|
||||
func (this *ClusterHelper) checkThresholds(clusterId int64) (bool, error) {
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
resp, err := rpcClient.NodeThresholdRPC().CountAllEnabledNodeThresholds(rpcClient.Context(0), &pb.CountAllEnabledNodeThresholdsRequest{
|
||||
Role: "node",
|
||||
NodeClusterId: clusterId,
|
||||
})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return resp.Count > 0, nil
|
||||
}
|
||||
|
||||
// 检查消息通知是否已经设置
|
||||
func (this *ClusterHelper) checkMessages(clusterId int64) (bool, error) {
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
resp, err := rpcClient.MessageReceiverRPC().CountAllEnabledMessageReceivers(rpcClient.Context(0), &pb.CountAllEnabledMessageReceiversRequest{
|
||||
NodeClusterId: clusterId,
|
||||
})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return resp.Count > 0, nil
|
||||
}
|
||||
|
||||
// 检查TOA是否设置
|
||||
func (this *ClusterHelper) checkTOA(clusterId int64) (bool, error) {
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
resp, err := rpcClient.NodeClusterRPC().FindEnabledNodeClusterTOA(rpcClient.Context(0), &pb.FindEnabledNodeClusterTOARequest{NodeClusterId: clusterId})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(resp.ToaJSON) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
var toaConfig = &nodeconfigs.TOAConfig{}
|
||||
err = json.Unmarshal(resp.ToaJSON, toaConfig)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return toaConfig.IsOn, nil
|
||||
}
|
||||
|
||||
@@ -99,6 +99,8 @@ func (this *BindHTTPFirewallPopupAction) RunPost(params struct {
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("绑定IP名单 %d 到WAF策略 %d", params.ListId, params.HttpFirewallPolicyId)
|
||||
|
||||
// List类型
|
||||
listResp, err := this.RPC().IPListRPC().FindEnabledIPList(this.AdminContext(), &pb.FindEnabledIPListRequest{IpListId: params.ListId})
|
||||
if err != nil {
|
||||
|
||||
@@ -18,6 +18,8 @@ func (this *UnbindHTTPFirewallAction) RunPost(params struct {
|
||||
HttpFirewallPolicyId int64
|
||||
ListId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("接触绑定IP名单 %d WAF策略 %d", params.ListId, params.HttpFirewallPolicyId)
|
||||
|
||||
// List类型
|
||||
listResp, err := this.RPC().IPListRPC().FindEnabledIPList(this.AdminContext(), &pb.FindEnabledIPListRequest{IpListId: params.ListId})
|
||||
if err != nil {
|
||||
|
||||
25
internal/web/actions/default/servers/metrics/charts.go
Normal file
25
internal/web/actions/default/servers/metrics/charts.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type ChartsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ChartsAction) Init() {
|
||||
this.Nav("", "", "chart")
|
||||
}
|
||||
|
||||
func (this *ChartsAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
83
internal/web/actions/default/servers/metrics/createPopup.go
Normal file
83
internal/web/actions/default/servers/metrics/createPopup.go
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
Category string
|
||||
}) {
|
||||
this.Data["category"] = params.Category
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
Category string
|
||||
KeysJSON []byte
|
||||
PeriodJSON []byte
|
||||
Value string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入指标名称")
|
||||
|
||||
if len(params.Category) == 0 {
|
||||
this.Fail("请选择指标类型")
|
||||
}
|
||||
|
||||
// 统计对象
|
||||
if len(params.KeysJSON) == 0 {
|
||||
this.FailField("keys", "请选择指标统计的对象")
|
||||
}
|
||||
var keys = []string{}
|
||||
err := json.Unmarshal(params.KeysJSON, &keys)
|
||||
if err != nil {
|
||||
this.FailField("keys", "解析指标对象失败")
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
this.FailField("keys", "请选择指标统计的对象")
|
||||
}
|
||||
|
||||
var periodMap = maps.Map{}
|
||||
err = json.Unmarshal(params.PeriodJSON, &periodMap)
|
||||
if err != nil {
|
||||
this.FailField("period", "解析统计周期失败")
|
||||
}
|
||||
var period = periodMap.GetInt32("period")
|
||||
var periodUnit = periodMap.GetString("unit")
|
||||
|
||||
createResp, err := this.RPC().MetricItemRPC().CreateMetricItem(this.AdminContext(), &pb.CreateMetricItemRequest{
|
||||
Code: "", // TODO 未来实现
|
||||
Category: params.Category,
|
||||
Name: params.Name,
|
||||
Keys: keys,
|
||||
Period: period,
|
||||
PeriodUnit: periodUnit,
|
||||
Value: params.Value,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defer this.CreateLogInfo("创建统计指标 %d", createResp.MetricItemId)
|
||||
this.Success()
|
||||
}
|
||||
26
internal/web/actions/default/servers/metrics/delete.go
Normal file
26
internal/web/actions/default/servers/metrics/delete.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("删除统计指标")
|
||||
|
||||
_, err := this.RPC().MetricItemRPC().DeleteMetricItem(this.AdminContext(), &pb.DeleteMetricItemRequest{MetricItemId: params.ItemId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
61
internal/web/actions/default/servers/metrics/index.go
Normal file
61
internal/web/actions/default/servers/metrics/index.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Category string
|
||||
}) {
|
||||
if len(params.Category) == 0 {
|
||||
params.Category = "http"
|
||||
}
|
||||
this.Data["category"] = params.Category
|
||||
|
||||
countResp, err := this.RPC().MetricItemRPC().CountAllEnabledMetricItems(this.AdminContext(), &pb.CountAllEnabledMetricItemsRequest{Category: params.Category})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
page := this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
itemsResp, err := this.RPC().MetricItemRPC().ListEnabledMetricItems(this.AdminContext(), &pb.ListEnabledMetricItemsRequest{
|
||||
Category: params.Category,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var itemMaps = []maps.Map{}
|
||||
for _, item := range itemsResp.MetricItems {
|
||||
itemMaps = append(itemMaps, maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"isOn": item.IsOn,
|
||||
"period": item.Period,
|
||||
"periodUnit": item.PeriodUnit,
|
||||
"keys": item.Keys,
|
||||
"value": item.Value,
|
||||
"category": item.Category,
|
||||
})
|
||||
}
|
||||
this.Data["items"] = itemMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
24
internal/web/actions/default/servers/metrics/init.go
Normal file
24
internal/web/actions/default/servers/metrics/init.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Data("teaMenu", "servers").
|
||||
Data("teaSubMenu", "metric").
|
||||
Prefix("/servers/metrics").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Get("/item", new(ItemAction)).
|
||||
Get("/charts", new(ChartsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
25
internal/web/actions/default/servers/metrics/item.go
Normal file
25
internal/web/actions/default/servers/metrics/item.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type ItemAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ItemAction) Init() {
|
||||
this.Nav("", "", "item")
|
||||
}
|
||||
|
||||
func (this *ItemAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -2,16 +2,83 @@
|
||||
|
||||
package metrics
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
this.Nav("", "", "update")
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunGet(params struct{}) {
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
ItemId int64
|
||||
Name string
|
||||
KeysJSON []byte
|
||||
PeriodJSON []byte
|
||||
Value string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入指标名称")
|
||||
|
||||
// 统计对象
|
||||
if len(params.KeysJSON) == 0 {
|
||||
this.FailField("keys", "请选择指标统计的对象")
|
||||
}
|
||||
var keys = []string{}
|
||||
err := json.Unmarshal(params.KeysJSON, &keys)
|
||||
if err != nil {
|
||||
this.FailField("keys", "解析指标对象失败")
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
this.FailField("keys", "请选择指标统计的对象")
|
||||
}
|
||||
|
||||
var periodMap = maps.Map{}
|
||||
err = json.Unmarshal(params.PeriodJSON, &periodMap)
|
||||
if err != nil {
|
||||
this.FailField("period", "解析统计周期失败")
|
||||
}
|
||||
var period = periodMap.GetInt32("period")
|
||||
var periodUnit = periodMap.GetString("unit")
|
||||
|
||||
_, err = this.RPC().MetricItemRPC().UpdateMetricItem(this.AdminContext(), &pb.UpdateMetricItemRequest{
|
||||
MetricItemId: params.ItemId,
|
||||
Name: params.Name,
|
||||
Keys: keys,
|
||||
Period: period,
|
||||
PeriodUnit: periodUnit,
|
||||
Value: params.Value,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defer this.CreateLogInfo("修改统计指标 %d", params.ItemId)
|
||||
this.Success()
|
||||
}
|
||||
|
||||
37
internal/web/actions/default/servers/metrics/utils.go
Normal file
37
internal/web/actions/default/servers/metrics/utils.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
func InitItem(parent *actionutils.ParentAction, itemId int64) error {
|
||||
client, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := client.MetricItemRPC().FindEnabledMetricItem(parent.AdminContext(), &pb.FindEnabledMetricItemRequest{MetricItemId: itemId})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var item = resp.MetricItem
|
||||
if item == nil {
|
||||
return errors.New("not found")
|
||||
}
|
||||
parent.Data["item"] = maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"isOn": item.IsOn,
|
||||
"keys": item.Keys,
|
||||
"value": item.Value,
|
||||
"period": item.Period,
|
||||
"periodUnit": item.PeriodUnit,
|
||||
"category": item.Category,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -2,22 +2,33 @@ package ui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/conds/condutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/files"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ComponentsAction actions.Action
|
||||
|
||||
var componentsData = []byte{}
|
||||
var componentsDataSum string
|
||||
|
||||
func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
this.AddHeader("Content-Type", "text/javascript; charset=utf-8")
|
||||
|
||||
// etag
|
||||
var requestETag = this.Header("If-None-Match")
|
||||
if len(requestETag) > 0 && requestETag == "\""+componentsDataSum+"\"" {
|
||||
this.ResponseWriter.WriteHeader(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
|
||||
if !Tea.IsTesting() && len(componentsData) > 0 {
|
||||
this.AddHeader("Last-Modified", "Fri, 06 Sep 2019 08:29:50 GMT")
|
||||
this.Write(componentsData)
|
||||
@@ -81,5 +92,12 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
}
|
||||
|
||||
componentsData = buffer.Bytes()
|
||||
|
||||
// ETag
|
||||
var h = md5.New()
|
||||
h.Write(buffer.Bytes())
|
||||
componentsDataSum = fmt.Sprintf("%x", h.Sum(nil))
|
||||
this.AddHeader("ETag", "\""+componentsDataSum+"\"")
|
||||
|
||||
this.Write(componentsData)
|
||||
}
|
||||
|
||||
@@ -177,6 +177,11 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map {
|
||||
"url": "/servers/certs",
|
||||
"code": "cert",
|
||||
},
|
||||
/**{
|
||||
"name": "统计指标",
|
||||
"url": "/servers/metrics",
|
||||
"code": "metric",
|
||||
},**/
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -110,6 +110,7 @@ import (
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/stat"
|
||||
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/iplists"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics"
|
||||
|
||||
// 设置相关
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings"
|
||||
|
||||
@@ -176,6 +176,7 @@ Vue.component("health-check-config-box", {
|
||||
<td>域名</td>
|
||||
<td>
|
||||
<input type="text" v-model="urlHost"/>
|
||||
<p class="comment">在此集群上可以访问到的一个域名。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -62,7 +62,7 @@ Vue.component("tip-icon", {
|
||||
teaweb.popupTip(this.content)
|
||||
}
|
||||
},
|
||||
template: `<a href="" title="查看帮助" @click.prevent="showTip"><i class="icon question circle"></i></a>`
|
||||
template: `<a href="" title="查看帮助" @click.prevent="showTip"><i class="icon question circle grey"></i></a>`
|
||||
})
|
||||
|
||||
// 提交点击事件
|
||||
|
||||
@@ -8,29 +8,52 @@ Vue.component("metric-keys-config-box", {
|
||||
}
|
||||
return {
|
||||
keys: keys,
|
||||
isAdding: false
|
||||
isAdding: false,
|
||||
key: ""
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
cancel: function () {
|
||||
this.key = ""
|
||||
this.isAdding = false
|
||||
},
|
||||
confirm: function () {
|
||||
if (this.key.length > 0) {
|
||||
this.keys.push(this.key)
|
||||
this.cancel()
|
||||
}
|
||||
},
|
||||
add: function () {
|
||||
this.isAdding = true
|
||||
let that = this
|
||||
setTimeout(function () {
|
||||
that.$refs.key.focus()
|
||||
}, 100)
|
||||
},
|
||||
remove: function (index) {
|
||||
this.keys.$remove(index)
|
||||
}
|
||||
},
|
||||
methods: {},
|
||||
template: `<div>
|
||||
<input type="hidden" name="keysJSON" :value="JSON.stringify(keys)"/>
|
||||
<div>
|
||||
<div v-for="key in keys">
|
||||
|
||||
<div v-for="(key, index) in keys" class="ui label small basic">
|
||||
{{key}} <a href="" title="删除" @click.prevent="remove"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div v-if="isAdding" style="margin-top: 1em">
|
||||
<div class="ui fields inline">
|
||||
<div class="ui field">
|
||||
<input type="text" placeholder=""/>
|
||||
<input type="text" v-model="key" ref="key" @keyup.enter="confirm()" @keypress.enter.prevent="1"/>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button type="button" class="ui button tiny">确定</button>
|
||||
<button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
|
||||
<a href="" @click.prevent="cancel"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" class="ui button tiny">+</button>
|
||||
<div style="margin-top: 1em" v-if="!isAdding">
|
||||
<button type="button" class="ui button tiny" @click.prevent="add">+</button>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
@@ -219,9 +219,9 @@ window.teaweb = {
|
||||
},
|
||||
popupTip: function (html) {
|
||||
Swal.fire({
|
||||
html: '<i class="icon question circle"></i><span style="line-height: 1.7">' + html + "</span>",
|
||||
html: '<div style="line-height: 1.7;text-align: left "><i class="icon question circle"></i>' + html + "</div>",
|
||||
width: "30em",
|
||||
padding: "5em",
|
||||
padding: "4em",
|
||||
showConfirmButton: false,
|
||||
showCloseButton: true,
|
||||
focusConfirm: false
|
||||
|
||||
@@ -219,9 +219,14 @@ p.margin {
|
||||
.main-menu .ui.menu .sub-items .item {
|
||||
padding-left: 2.8em !important;
|
||||
}
|
||||
.main-menu .ui.menu .sub-items .item .icon {
|
||||
position: absolute;
|
||||
left: 1.1em;
|
||||
top: 0.93em;
|
||||
}
|
||||
@media screen and (max-width: 512px) {
|
||||
.main-menu .ui.menu .sub-items .item {
|
||||
padding-left: 1em!important;
|
||||
padding-left: 1em !important;
|
||||
}
|
||||
}
|
||||
.main-menu .ui.menu .sub-items .item.active {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -85,7 +85,7 @@
|
||||
<div class="subtitle" v-if="module.subtitle != null && module.subtitle.length > 0">{{module.subtitle}}</div>
|
||||
</a>
|
||||
<div v-if="teaMenu == module.code" class="sub-items">
|
||||
<a class="item" v-for="subItem in module.subItems" v-if="subItem.isOn !== false" :href="subItem.url" :class="{active:subItem.code == teaSubMenu}">{{subItem.name}}</a>
|
||||
<a class="item" v-for="subItem in module.subItems" v-if="subItem.isOn !== false" :href="subItem.url"><i class="icon angle right" v-if="subItem.code == teaSubMenu"></i> {{subItem.name}}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -172,11 +172,17 @@ div.margin, p.margin {
|
||||
.sub-items {
|
||||
.item {
|
||||
padding-left: 2.8em !important;
|
||||
|
||||
.icon {
|
||||
position: absolute;
|
||||
left: 1.1em;
|
||||
top: 0.93em;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 512px) {
|
||||
.item {
|
||||
padding-left: 1em!important;
|
||||
padding-left: 1em !important;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<form method="post" class="ui form" v-if="!isRequesting">
|
||||
<p>成功节点:<span class="green">{{countSuccess}}</span> 失败节点:<span class="red">{{countFail}}</span></p>
|
||||
<table class="ui table selectable celled">
|
||||
<table class="ui table selectable celled" v-if="results.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>节点</th>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{$layout "layout_popup"}
|
||||
|
||||
<h3>添加指标</h3>
|
||||
|
||||
<p class="comment" v-if="items.length == 0">暂时还没有指标。</p>
|
||||
<table class="ui table celled selectable" v-if="items.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>指标名称</th>
|
||||
<th>统计对象</th>
|
||||
<th>统计周期</th>
|
||||
<th class="three wide">统计数值</th>
|
||||
<th class="two wide">状态</th>
|
||||
<th class="two op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="item in items">
|
||||
<td>{{item.name}}</td>
|
||||
<td>
|
||||
<span v-if="item.keys != null" v-for="key in item.keys" class="ui label basic small">{{key}}</span>
|
||||
</td>
|
||||
<td>
|
||||
{{item.period}} {{item.periodUnit}}
|
||||
</td>
|
||||
<td>
|
||||
<span class="ui label small basic">{{item.value}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<label-on :v-is-on="item.isOn"></label-on>
|
||||
</td>
|
||||
<td>
|
||||
<a href="" v-if="!item.isChecked">添加</a>
|
||||
<a href="" v-if="item.isChecked"><span class="grey">已添加</span></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="page" v-html="page"></div>
|
||||
@@ -0,0 +1,47 @@
|
||||
{$layout}
|
||||
{$template "/left_menu"}
|
||||
|
||||
<div class="right-box">
|
||||
<first-menu>
|
||||
<menu-item :href="'/clusters/cluster/settings/metrics?category=http&clusterId=' + clusterId" :active="category == 'http'">HTTP</menu-item>
|
||||
<menu-item :href="'/clusters/cluster/settings/metrics?category=tcp&clusterId=' + clusterId" :active="category == 'tcp'">TCP</menu-item>
|
||||
<menu-item :href="'/clusters/cluster/settings/metrics?category=udp&clusterId=' + clusterId" :active="category == 'udp'">UDP</menu-item>
|
||||
<span class="item disabled">|</span>
|
||||
<menu-item @click.prevent="createItem">[添加指标]</menu-item>
|
||||
<span class="item disabled">|</span>
|
||||
<span class="item"><tip-icon content="在这里设置的指标,会自动应用到部署在当前集群上的所有服务上。"></tip-icon></span>
|
||||
</first-menu>
|
||||
|
||||
<p class="comment" v-if="items.length == 0">暂时还没有设置指标。</p>
|
||||
|
||||
<table class="ui table celled selectable" v-if="items.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>指标名称</th>
|
||||
<th>统计对象</th>
|
||||
<th>统计周期</th>
|
||||
<th class="three wide">统计数值</th>
|
||||
<th class="two wide">状态</th>
|
||||
<th class="two op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="item in items">
|
||||
<td>{{item.name}}</td>
|
||||
<td>
|
||||
<span v-if="item.keys != null" v-for="key in item.keys" class="ui label basic small">{{key}}</span>
|
||||
</td>
|
||||
<td>
|
||||
{{item.period}} {{item.periodUnit}}
|
||||
</td>
|
||||
<td>
|
||||
<span class="ui label small basic">{{item.value}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<label-on :v-is-on="item.isOn"></label-on>
|
||||
</td>
|
||||
<td>
|
||||
<a href="" @click.prevent="deleteItem(item.id)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,30 @@
|
||||
Tea.context(function () {
|
||||
this.createItem = function () {
|
||||
teaweb.popup(Tea.url(".createPopup", {
|
||||
clusterId: this.clusterId
|
||||
}), {
|
||||
callback: function () {
|
||||
teaweb.success("保存成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
},
|
||||
width: "50em",
|
||||
height: "25em"
|
||||
})
|
||||
}
|
||||
|
||||
this.deleteItem = function (itemId) {
|
||||
let that = this
|
||||
teaweb.confirm("确定要删除这个指标吗?", function () {
|
||||
that.$post(".delete")
|
||||
.params({
|
||||
itemId: itemId
|
||||
})
|
||||
.success(function () {
|
||||
teaweb.success("删除成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -12,7 +12,7 @@
|
||||
<td class="title">是否启用TOA</td>
|
||||
<td>
|
||||
<checkbox name="isOn" v-model="toa.isOn"></checkbox>
|
||||
<p class="comment">在启用之前,请确保当前集群下所有节点服务器已经安装TOA模块和libnetfilter_queue,并启用了IPTables。</p>
|
||||
<p class="comment">在启用之前,请确保当前集群下所有节点服务器已经安装libnetfilter_queue,并启用了IPTables。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tbody v-show="toa.isOn">
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<td>绑定域名</td>
|
||||
<td>
|
||||
<server-name-box></server-name-box>
|
||||
<p class="comment">绑定后,才能通过域名可以访问不同的服务。</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
7
web/views/@default/servers/metrics/@item_menu.html
Normal file
7
web/views/@default/servers/metrics/@item_menu.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<first-menu>
|
||||
<menu-item :href="'/servers/metrics'">指标列表</menu-item>
|
||||
<span class="item disabled">|</span>
|
||||
<menu-item :href="'/servers/metrics/item?itemId=' + item.id" code="item">"{{item.name}}"详情</menu-item>
|
||||
<menu-item :href="'/servers/metrics/update?itemId=' + item.id" code="update">修改</menu-item>
|
||||
<menu-item :href="'/servers/metrics/charts?itemId=' + item.id" code="chart">图表</menu-item>
|
||||
</first-menu>
|
||||
4
web/views/@default/servers/metrics/charts.html
Normal file
4
web/views/@default/servers/metrics/charts.html
Normal file
@@ -0,0 +1,4 @@
|
||||
{$layout}
|
||||
{$template "item_menu"}
|
||||
|
||||
<p class="ui message warning">此功能暂未开通,敬等期待。</p>
|
||||
54
web/views/@default/servers/metrics/createPopup.html
Normal file
54
web/views/@default/servers/metrics/createPopup.html
Normal file
@@ -0,0 +1,54 @@
|
||||
{$layout "layout_popup"}
|
||||
|
||||
<h3>创建{{category.toUpperCase()}}统计指标</h3>
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<csrf-token></csrf-token>
|
||||
<input type="hidden" name="category" :value="category"/>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">指标名称 *</td>
|
||||
<td>
|
||||
<input type="text" name="name" maxlength="100" ref="focus"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>统计对象 *</td>
|
||||
<td>
|
||||
<metric-keys-config-box :v-category="category"></metric-keys-config-box>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>统计周期 *</td>
|
||||
<td>
|
||||
<metric-period-config-box></metric-period-config-box>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>统计数值 *</td>
|
||||
<td>
|
||||
<!-- HTTP -->
|
||||
<select class="ui dropdown auto-width" name="value" v-if="category == 'http'">
|
||||
<option value="${countRequest}">请求数</option>
|
||||
<option value="${countConnection}">连接数</option>
|
||||
<option value="${countTrafficIn}">下行流量</option>
|
||||
<option value="${countTrafficOut}">上行流量</option>
|
||||
</select>
|
||||
|
||||
<!-- TCP -->
|
||||
<select class="ui dropdown auto-width" name="value" v-if="category == 'tcp'">
|
||||
<option value="${countConnection}">连接数</option>
|
||||
<option value="${countTrafficIn}">下行流量</option>
|
||||
<option value="${countTrafficOut}">上行流量</option>
|
||||
</select>
|
||||
|
||||
<!-- UDP -->
|
||||
<select class="ui dropdown auto-width" name="value" v-if="category == 'udp'">
|
||||
<option value="${countConnection}">连接数</option>
|
||||
<option value="${countTrafficIn}">下行流量</option>
|
||||
<option value="${countTrafficOut}">上行流量</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
46
web/views/@default/servers/metrics/index.html
Normal file
46
web/views/@default/servers/metrics/index.html
Normal file
@@ -0,0 +1,46 @@
|
||||
{$layout}
|
||||
|
||||
<first-menu>
|
||||
<menu-item :href="'/servers/metrics?category=http'" :active="category == 'http'">HTTP</menu-item>
|
||||
<menu-item :href="'/servers/metrics?category=tcp'" :active="category == 'tcp'">TCP</menu-item>
|
||||
<menu-item :href="'/servers/metrics?category=udp'" :active="category == 'udp'">UDP</menu-item>
|
||||
<span class="item disabled">|</span>
|
||||
<menu-item @click.prevent="createItem">[创建指标]</menu-item>
|
||||
<span class="item disabled">|</span>
|
||||
<span class="item"><tip-icon content="在这里创建一些指标后,可以在集群中使用这些指标,从而实现阈值、图表等功能"></tip-icon></span>
|
||||
</first-menu>
|
||||
|
||||
<p class="comment" v-if="items.length == 0">暂时还没有指标。</p>
|
||||
<table class="ui table celled selectable" v-if="items.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>指标名称</th>
|
||||
<th>统计对象</th>
|
||||
<th>统计周期</th>
|
||||
<th class="three wide">统计数值</th>
|
||||
<th class="two wide">状态</th>
|
||||
<th class="two op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="item in items">
|
||||
<td>{{item.name}}</td>
|
||||
<td>
|
||||
<span v-if="item.keys != null" v-for="key in item.keys" class="ui label basic small">{{key}}</span>
|
||||
</td>
|
||||
<td>
|
||||
{{item.period}} {{item.periodUnit}}
|
||||
</td>
|
||||
<td>
|
||||
<span class="ui label small basic">{{item.value}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<label-on :v-is-on="item.isOn"></label-on>
|
||||
</td>
|
||||
<td>
|
||||
<a :href="'/servers/metrics/item?itemId=' + item.id">详情</a>
|
||||
<a href="" @click.prevent="deleteItem(item.id)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="page" v-html="page"></div>
|
||||
27
web/views/@default/servers/metrics/index.js
Normal file
27
web/views/@default/servers/metrics/index.js
Normal file
@@ -0,0 +1,27 @@
|
||||
Tea.context(function () {
|
||||
this.createItem = function () {
|
||||
teaweb.popup(Tea.url(".createPopup?category=" + this.category), {
|
||||
callback: function () {
|
||||
teaweb.success("保存成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
},
|
||||
height: "26em"
|
||||
})
|
||||
}
|
||||
|
||||
this.deleteItem = function (itemId) {
|
||||
let that = this
|
||||
teaweb.confirm("确定要删除此指标吗?", function () {
|
||||
that.$post(".delete")
|
||||
.params({
|
||||
itemId: itemId
|
||||
})
|
||||
.success(function () {
|
||||
teaweb.success("删除成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
27
web/views/@default/servers/metrics/item.html
Normal file
27
web/views/@default/servers/metrics/item.html
Normal file
@@ -0,0 +1,27 @@
|
||||
{$layout}
|
||||
{$template "item_menu"}
|
||||
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">指标名称</td>
|
||||
<td>
|
||||
{{item.name}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>状态</td>
|
||||
<td><label-on :v-is-on="item.isOn"></label-on></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>统计周期</td>
|
||||
<td>
|
||||
{{item.period}} {{item.periodUnit}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>统计数值</td>
|
||||
<td>
|
||||
{{item.value}}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
60
web/views/@default/servers/metrics/update.html
Normal file
60
web/views/@default/servers/metrics/update.html
Normal file
@@ -0,0 +1,60 @@
|
||||
{$layout "layout"}
|
||||
{$template "item_menu"}
|
||||
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<csrf-token></csrf-token>
|
||||
<input type="hidden" name="itemId" :value="item.id"/>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">指标名称 *</td>
|
||||
<td>
|
||||
<input type="text" name="name" maxlength="100" ref="focus" v-model="item.name"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>统计对象 *</td>
|
||||
<td>
|
||||
<metric-keys-config-box :v-category="item.category" :v-keys="item.keys"></metric-keys-config-box>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>统计周期 *</td>
|
||||
<td>
|
||||
<metric-period-config-box :v-period="item.period" :v-period-unit="item.periodUnit"></metric-period-config-box>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>统计数值 *</td>
|
||||
<td>
|
||||
<!-- HTTP -->
|
||||
<select class="ui dropdown auto-width" name="value" v-if="item.category == 'http'" v-model="item.value">
|
||||
<option value="${countRequest}">请求数</option>
|
||||
<option value="${countConnection}">连接数</option>
|
||||
<option value="${countTrafficIn}">下行流量</option>
|
||||
<option value="${countTrafficOut}">上行流量</option>
|
||||
</select>
|
||||
|
||||
<!-- TCP -->
|
||||
<select class="ui dropdown auto-width" name="value" v-if="item.category == 'tcp'">
|
||||
<option value="${countConnection}">连接数</option>
|
||||
<option value="${countTrafficIn}">下行流量</option>
|
||||
<option value="${countTrafficOut}">上行流量</option>
|
||||
</select>
|
||||
|
||||
<!-- UDP -->
|
||||
<select class="ui dropdown auto-width" name="value" v-if="item.category == 'udp'">
|
||||
<option value="${countConnection}">连接数</option>
|
||||
<option value="${countTrafficIn}">下行流量</option>
|
||||
<option value="${countTrafficOut}">上行流量</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>是否启用</td>
|
||||
<td>
|
||||
<checkbox name="isOn" v-model="item.isOn" value="1"></checkbox>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
3
web/views/@default/servers/metrics/update.js
Normal file
3
web/views/@default/servers/metrics/update.js
Normal file
@@ -0,0 +1,3 @@
|
||||
Tea.context(function () {
|
||||
this.success = NotifySuccess("保存成功", "/servers/metrics/item?itemId=" + this.item.id)
|
||||
})
|
||||
Reference in New Issue
Block a user