实现基础的统计指标
This commit is contained in:
@@ -392,6 +392,10 @@ func (this *RPCClient) MetricItemRPC() pb.MetricItemServiceClient {
|
||||
return pb.NewMetricItemServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
func (this *RPCClient) MetricStatRPC() pb.MetricStatServiceClient {
|
||||
return pb.NewMetricStatServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
func (this *RPCClient) NodeClusterMetricItemRPC() pb.NodeClusterMetricItemServiceClient {
|
||||
return pb.NewNodeClusterMetricItemServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package metrics
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -17,12 +18,14 @@ func (this *CreatePopupAction) Init() {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
Category string
|
||||
ClusterId int64
|
||||
Category string
|
||||
}) {
|
||||
if len(params.Category) == 0 {
|
||||
params.Category = "http"
|
||||
}
|
||||
this.Data["category"] = params.Category
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
|
||||
countResp, err := this.RPC().MetricItemRPC().CountAllEnabledMetricItems(this.AdminContext(), &pb.CountAllEnabledMetricItemsRequest{Category: params.Category})
|
||||
if err != nil {
|
||||
@@ -44,6 +47,17 @@ func (this *CreatePopupAction) RunGet(params struct {
|
||||
}
|
||||
var itemMaps = []maps.Map{}
|
||||
for _, item := range itemsResp.MetricItems {
|
||||
// 是否已添加
|
||||
existsResp, err := this.RPC().NodeClusterMetricItemRPC().ExistsNodeClusterMetricItem(this.AdminContext(), &pb.ExistsNodeClusterMetricItemRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
MetricItemId: item.Id,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var exists = existsResp.Exists
|
||||
|
||||
itemMaps = append(itemMaps, maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
@@ -53,9 +67,29 @@ func (this *CreatePopupAction) RunGet(params struct {
|
||||
"keys": item.Keys,
|
||||
"value": item.Value,
|
||||
"category": item.Category,
|
||||
"isChecked": exists,
|
||||
})
|
||||
}
|
||||
this.Data["items"] = itemMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
ItemId int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("添加指标 %d 到集群 %d", params.ItemId, params.ClusterId)
|
||||
|
||||
_, err := this.RPC().NodeClusterMetricItemRPC().EnableNodeClusterMetricItem(this.AdminContext(), &pb.EnableNodeClusterMetricItemRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
MetricItemId: params.ItemId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -2,12 +2,29 @@
|
||||
|
||||
package metrics
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
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{}) {
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
ItemId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("从集群 %d 中移除指标 %d", params.ClusterId, params.ItemId)
|
||||
|
||||
_, err := this.RPC().NodeClusterMetricItemRPC().DisableNodeClusterMetricItem(this.AdminContext(), &pb.DisableNodeClusterMetricItemRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
MetricItemId: params.ItemId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -26,7 +26,10 @@ func (this *IndexAction) RunGet(params struct {
|
||||
}
|
||||
this.Data["category"] = params.Category
|
||||
|
||||
itemsResp, err := this.RPC().NodeClusterMetricItemRPC().FindAllNodeClusterMetricItems(this.AdminContext(), &pb.FindAllNodeClusterMetricItemsRequest{NodeClusterId: params.ClusterId})
|
||||
itemsResp, err := this.RPC().NodeClusterMetricItemRPC().FindAllNodeClusterMetricItems(this.AdminContext(), &pb.FindAllNodeClusterMetricItemsRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
Category: params.Category,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
|
||||
@@ -121,12 +121,12 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, info *pb.F
|
||||
"isActive": selectedItem == "dns",
|
||||
"isOn": cluster.DnsDomainId > 0 || len(cluster.DnsName) > 0,
|
||||
})
|
||||
/**items = append(items, maps.Map{
|
||||
items = append(items, maps.Map{
|
||||
"name": "统计指标",
|
||||
"url": "/clusters/cluster/settings/metrics?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "metric",
|
||||
"isOn": info != nil && info.HasMetricItems,
|
||||
})**/
|
||||
})
|
||||
|
||||
if teaconst.IsPlus {
|
||||
items = append(items, maps.Map{
|
||||
|
||||
@@ -15,7 +15,7 @@ func (this *ChartsAction) Init() {
|
||||
func (this *ChartsAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
_, err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
@@ -22,6 +23,7 @@ func (this *CreatePopupAction) RunGet(params struct {
|
||||
Category string
|
||||
}) {
|
||||
this.Data["category"] = params.Category
|
||||
this.Data["valueDefinitions"] = serverconfigs.FindAllMetricValueDefinitions(params.Category)
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ func init() {
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Get("/item", new(ItemAction)).
|
||||
Get("/charts", new(ChartsAction)).
|
||||
Get("/stats", new(StatsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func (this *ItemAction) Init() {
|
||||
func (this *ItemAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
_, err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
|
||||
65
internal/web/actions/default/servers/metrics/stats.go
Normal file
65
internal/web/actions/default/servers/metrics/stats.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type StatsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *StatsAction) Init() {
|
||||
this.Nav("", "", "stat")
|
||||
}
|
||||
|
||||
func (this *StatsAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
item, err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
countResp, err := this.RPC().MetricStatRPC().CountMetricStats(this.AdminContext(), &pb.CountMetricStatsRequest{
|
||||
MetricItemId: params.ItemId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
|
||||
page := this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
statsResp, err := this.RPC().MetricStatRPC().ListMetricStats(this.AdminContext(), &pb.ListMetricStatsRequest{
|
||||
MetricItemId: params.ItemId,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range statsResp.MetricStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"id": stat.Id,
|
||||
"time": serverconfigs.HumanMetricTime(item.PeriodUnit, stat.Time),
|
||||
"keys": stat.Keys,
|
||||
"value": stat.Value,
|
||||
"cluster": maps.Map{"id": stat.NodeCluster.Id, "name": stat.NodeCluster.Name},
|
||||
"node": maps.Map{"id": stat.Node.Id, "name": stat.Node.Name},
|
||||
"server": maps.Map{"id": stat.Server.Id, "name": stat.Server.Name},
|
||||
})
|
||||
}
|
||||
this.Data["stats"] = statMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
@@ -21,12 +22,14 @@ func (this *UpdateAction) Init() {
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
item, err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["valueDefinitions"] = serverconfigs.FindAllMetricValueDefinitions(item.Category)
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
|
||||
@@ -10,18 +10,19 @@ import (
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
func InitItem(parent *actionutils.ParentAction, itemId int64) error {
|
||||
// InitItem 初始化指标信息
|
||||
func InitItem(parent *actionutils.ParentAction, itemId int64) (*pb.MetricItem, error) {
|
||||
client, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
resp, err := client.MetricItemRPC().FindEnabledMetricItem(parent.AdminContext(), &pb.FindEnabledMetricItemRequest{MetricItemId: itemId})
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
var item = resp.MetricItem
|
||||
if item == nil {
|
||||
return errors.New("not found")
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
parent.Data["item"] = maps.Map{
|
||||
"id": item.Id,
|
||||
@@ -33,5 +34,5 @@ func InitItem(parent *actionutils.ParentAction, itemId int64) error {
|
||||
"periodUnit": item.PeriodUnit,
|
||||
"category": item.Category,
|
||||
}
|
||||
return nil
|
||||
return item, nil
|
||||
}
|
||||
|
||||
@@ -177,11 +177,11 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map {
|
||||
"url": "/servers/certs",
|
||||
"code": "cert",
|
||||
},
|
||||
/**{
|
||||
{
|
||||
"name": "统计指标",
|
||||
"url": "/servers/metrics",
|
||||
"code": "metric",
|
||||
},**/
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user