mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-16 05:36:36 +08:00
实现基础的统计指标
This commit is contained in:
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()
|
||||
}
|
||||
Reference in New Issue
Block a user