From 3cce13e671d2a03705dd0b11a0171a7b2cbbc5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 21 Jul 2021 08:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=9F=E5=90=8D=E6=8E=92=E8=A1=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9D=A1=E6=95=B0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/models/stats/server_domain_hourly_stat_dao.go | 12 ++++++++---- internal/rpc/services/service_admin.go | 2 +- internal/rpc/services/service_server_stat_board.go | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/db/models/stats/server_domain_hourly_stat_dao.go b/internal/db/models/stats/server_domain_hourly_stat_dao.go index 6abce0c5..5c6a45b4 100644 --- a/internal/db/models/stats/server_domain_hourly_stat_dao.go +++ b/internal/db/models/stats/server_domain_hourly_stat_dao.go @@ -87,20 +87,21 @@ func (this *ServerDomainHourlyStatDAO) IncreaseHourlyStat(tx *dbs.Tx, clusterId } // FindTopDomainStats 取得一定时间内的域名排行数据 -func (this *ServerDomainHourlyStatDAO) FindTopDomainStats(tx *dbs.Tx, hourFrom string, hourTo string) (result []*ServerDomainHourlyStat, err error) { +func (this *ServerDomainHourlyStatDAO) FindTopDomainStats(tx *dbs.Tx, hourFrom string, hourTo string, size int64) (result []*ServerDomainHourlyStat, err error) { // TODO 节点如果已经被删除,则忽略 _, err = this.Query(tx). Between("hour", hourFrom, hourTo). Result("domain, MIN(serverId) AS serverId, 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("domain"). Desc("countRequests"). + Limit(size). Slice(&result). FindAll() return } // FindTopDomainStatsWithClusterId 取得集群上的一定时间内的域名排行数据 -func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithClusterId(tx *dbs.Tx, clusterId int64, hourFrom string, hourTo string) (result []*ServerDomainHourlyStat, err error) { +func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithClusterId(tx *dbs.Tx, clusterId int64, hourFrom string, hourTo string, size int64) (result []*ServerDomainHourlyStat, err error) { // TODO 节点如果已经被删除,则忽略 _, err = this.Query(tx). Attr("clusterId", clusterId). @@ -108,13 +109,14 @@ func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithClusterId(tx *dbs.T Result("domain, MIN(serverId) AS serverId, 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("domain"). Desc("countRequests"). + Limit(size). Slice(&result). FindAll() return } // FindTopDomainStatsWithNodeId 取得节点上的一定时间内的域名排行数据 -func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithNodeId(tx *dbs.Tx, nodeId int64, hourFrom string, hourTo string) (result []*ServerDomainHourlyStat, err error) { +func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithNodeId(tx *dbs.Tx, nodeId int64, hourFrom string, hourTo string, size int64) (result []*ServerDomainHourlyStat, err error) { // TODO 节点如果已经被删除,则忽略 _, err = this.Query(tx). Attr("nodeId", nodeId). @@ -122,13 +124,14 @@ func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithNodeId(tx *dbs.Tx, Result("domain, MIN(serverId) AS serverId, 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("domain"). Desc("countRequests"). + Limit(size). Slice(&result). FindAll() return } // FindTopDomainStatsWithServerId 取得某个服务的一定时间内的域名排行数据 -func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithServerId(tx *dbs.Tx, serverId int64, hourFrom string, hourTo string) (result []*ServerDomainHourlyStat, err error) { +func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithServerId(tx *dbs.Tx, serverId int64, hourFrom string, hourTo string, size int64) (result []*ServerDomainHourlyStat, err error) { // TODO 节点如果已经被删除,则忽略 _, err = this.Query(tx). Attr("serverId", serverId). @@ -136,6 +139,7 @@ func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithServerId(tx *dbs.Tx Result("domain, MIN(serverId) AS serverId, 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("domain"). 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 c5bee827..9f216b65 100644 --- a/internal/rpc/services/service_admin.go +++ b/internal/rpc/services/service_admin.go @@ -647,7 +647,7 @@ func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.Com // 域名排行 if isPlus { - topDomainStats, err := stats.SharedServerDomainHourlyStatDAO.FindTopDomainStats(tx, hourFrom, hourTo) + topDomainStats, err := stats.SharedServerDomainHourlyStatDAO.FindTopDomainStats(tx, 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 1adac1c3..2f9195e2 100644 --- a/internal/rpc/services/service_server_stat_board.go +++ b/internal/rpc/services/service_server_stat_board.go @@ -146,7 +146,7 @@ func (this *ServerStatBoardService) ComposeServerStatNodeClusterBoard(ctx contex } // 域名排行 - topDomainStats, err := stats.SharedServerDomainHourlyStatDAO.FindTopDomainStatsWithClusterId(tx, req.NodeClusterId, hourFrom, hourTo) + topDomainStats, err := stats.SharedServerDomainHourlyStatDAO.FindTopDomainStatsWithClusterId(tx, req.NodeClusterId, hourFrom, hourTo, 10) if err != nil { return nil, err } @@ -370,7 +370,7 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte } // 域名排行 - topDomainStats, err := stats.SharedServerDomainHourlyStatDAO.FindTopDomainStatsWithNodeId(tx, req.NodeId, hourFrom, hourTo) + topDomainStats, err := stats.SharedServerDomainHourlyStatDAO.FindTopDomainStatsWithNodeId(tx, req.NodeId, hourFrom, hourTo, 10) if err != nil { return nil, err } @@ -499,7 +499,7 @@ func (this *ServerStatBoardService) ComposeServerStatBoard(ctx context.Context, } // 域名排行 - topDomainStats, err := stats.SharedServerDomainHourlyStatDAO.FindTopDomainStatsWithServerId(tx, req.ServerId, hourFrom, hourTo) + topDomainStats, err := stats.SharedServerDomainHourlyStatDAO.FindTopDomainStatsWithServerId(tx, req.ServerId, hourFrom, hourTo, 10) if err != nil { return nil, err }