diff --git a/internal/db/models/stats/node_traffic_hourly_stat_dao.go b/internal/db/models/stats/node_traffic_hourly_stat_dao.go index f9618b9d..373bf93d 100644 --- a/internal/db/models/stats/node_traffic_hourly_stat_dao.go +++ b/internal/db/models/stats/node_traffic_hourly_stat_dao.go @@ -118,7 +118,7 @@ func (this *NodeTrafficHourlyStatDAO) FindHourlyStatsWithClusterId(tx *dbs.Tx, c } // FindTopNodeStats 取得一定时间内的节点排行数据 -func (this *NodeTrafficHourlyStatDAO) FindTopNodeStats(tx *dbs.Tx, role string, hourFrom string, hourTo string) (result []*NodeTrafficHourlyStat, err error) { +func (this *NodeTrafficHourlyStatDAO) FindTopNodeStats(tx *dbs.Tx, role string, hourFrom string, hourTo string, size int64) (result []*NodeTrafficHourlyStat, err error) { // TODO 节点如果已经被删除,则忽略 _, err = this.Query(tx). Attr("role", role). @@ -126,13 +126,14 @@ func (this *NodeTrafficHourlyStatDAO) FindTopNodeStats(tx *dbs.Tx, role string, Result("nodeId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes"). Group("nodeId"). Desc("countRequests"). + Limit(size). Slice(&result). FindAll() return } // FindTopNodeStatsWithClusterId 取得集群一定时间内的节点排行数据 -func (this *NodeTrafficHourlyStatDAO) FindTopNodeStatsWithClusterId(tx *dbs.Tx, role string, clusterId int64, hourFrom string, hourTo string) (result []*NodeTrafficHourlyStat, err error) { +func (this *NodeTrafficHourlyStatDAO) FindTopNodeStatsWithClusterId(tx *dbs.Tx, role string, clusterId int64, hourFrom string, hourTo string, size int64) (result []*NodeTrafficHourlyStat, err error) { // TODO 节点如果已经被删除,则忽略 _, err = this.Query(tx). Attr("role", role). @@ -141,6 +142,7 @@ func (this *NodeTrafficHourlyStatDAO) FindTopNodeStatsWithClusterId(tx *dbs.Tx, Result("nodeId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes"). Group("nodeId"). Desc("countRequests"). + Limit(size). Slice(&result). FindAll() return diff --git a/internal/rpc/services/service_admin.go b/internal/rpc/services/service_admin.go index 1fa0feca..7078fbf3 100644 --- a/internal/rpc/services/service_admin.go +++ b/internal/rpc/services/service_admin.go @@ -662,7 +662,7 @@ func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.Com // 节点排行 if isPlus { - topNodeStats, err := stats.SharedNodeTrafficHourlyStatDAO.FindTopNodeStats(tx, "node", hourFrom, hourTo) + topNodeStats, err := stats.SharedNodeTrafficHourlyStatDAO.FindTopNodeStats(tx, "node", hourFrom, hourTo, 10) if err != nil { return nil, err } diff --git a/internal/rpc/services/service_server_stat_board.go b/internal/rpc/services/service_server_stat_board.go index b789889e..5c76e8b1 100644 --- a/internal/rpc/services/service_server_stat_board.go +++ b/internal/rpc/services/service_server_stat_board.go @@ -123,7 +123,7 @@ func (this *ServerStatBoardService) ComposeServerStatNodeClusterBoard(ctx contex } // 节点排行 - topNodeStats, err := stats.SharedNodeTrafficHourlyStatDAO.FindTopNodeStatsWithClusterId(tx, "node", req.NodeClusterId, hourFrom, hourTo) + topNodeStats, err := stats.SharedNodeTrafficHourlyStatDAO.FindTopNodeStatsWithClusterId(tx, "node", req.NodeClusterId, hourFrom, hourTo, 10) if err != nil { return nil, err }