mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	集群看板数据中增加当月流量
This commit is contained in:
		@@ -114,6 +114,20 @@ func (this *NodeClusterTrafficDailyStatDAO) FindDailyStats(tx *dbs.Tx, clusterId
 | 
			
		||||
	return result, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SumDailyStats 计算当月总流量
 | 
			
		||||
func (this *NodeClusterTrafficDailyStatDAO) SumDailyStats(tx *dbs.Tx, clusterId int64, dayFrom string, dayTo string) (*NodeClusterTrafficDailyStat, error) {
 | 
			
		||||
	one, err := this.Query(tx).
 | 
			
		||||
		Result("SUM(bytes) AS bytes", "SUM(cachedBytes) AS cachedBytes", "SUM(countRequests) AS countRequests", "SUM(countCachedRequests) AS countCachedRequests", "SUM(countAttackRequests) AS countAttackRequests", "SUM(attackBytes) AS attackBytes").
 | 
			
		||||
		Attr("clusterId", clusterId).
 | 
			
		||||
		Between("day", dayFrom, dayTo).
 | 
			
		||||
		Find()
 | 
			
		||||
	if err != nil || one == nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return one.(*NodeClusterTrafficDailyStat), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Clean 清理历史数据
 | 
			
		||||
func (this *NodeClusterTrafficDailyStatDAO) Clean(tx *dbs.Tx, days int) error {
 | 
			
		||||
	var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -days))
 | 
			
		||||
 
 | 
			
		||||
@@ -85,13 +85,32 @@ func (this *ServerStatBoardService) ComposeServerStatNodeClusterBoard(ctx contex
 | 
			
		||||
	}
 | 
			
		||||
	result.CountServers = countServers
 | 
			
		||||
 | 
			
		||||
	// 当月总流量
 | 
			
		||||
	monthlyTrafficStat, err := stats.SharedNodeClusterTrafficDailyStatDAO.SumDailyStats(tx, req.NodeClusterId, timeutil.Format("Ym01"), timeutil.Format("Ym31"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var monthlyTrafficBytes int64
 | 
			
		||||
	if monthlyTrafficStat != nil {
 | 
			
		||||
		monthlyTrafficBytes = int64(monthlyTrafficStat.Bytes)
 | 
			
		||||
	}
 | 
			
		||||
	result.MonthlyTrafficBytes = monthlyTrafficBytes
 | 
			
		||||
 | 
			
		||||
	// 按日流量统计
 | 
			
		||||
	var dayFrom = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
 | 
			
		||||
	dailyTrafficStats, err := stats.SharedNodeClusterTrafficDailyStatDAO.FindDailyStats(tx, req.NodeClusterId, dayFrom, timeutil.Format("Ymd"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var dailyTrafficBytes int64
 | 
			
		||||
	var lastDailyTrafficBytes int64
 | 
			
		||||
	for _, stat := range dailyTrafficStats {
 | 
			
		||||
		if stat.Day == timeutil.Format("Ymd") { // 今天
 | 
			
		||||
			dailyTrafficBytes = int64(stat.Bytes)
 | 
			
		||||
		} else if stat.Day == timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)) {
 | 
			
		||||
			lastDailyTrafficBytes = int64(stat.Bytes)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		result.DailyTrafficStats = append(result.DailyTrafficStats, &pb.ComposeServerStatNodeClusterBoardResponse_DailyTrafficStat{
 | 
			
		||||
			Day:                 stat.Day,
 | 
			
		||||
			Bytes:               int64(stat.Bytes),
 | 
			
		||||
@@ -102,6 +121,8 @@ func (this *ServerStatBoardService) ComposeServerStatNodeClusterBoard(ctx contex
 | 
			
		||||
			AttackBytes:         int64(stat.AttackBytes),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	result.DailyTrafficBytes = dailyTrafficBytes
 | 
			
		||||
	result.LastDailyTrafficBytes = lastDailyTrafficBytes
 | 
			
		||||
 | 
			
		||||
	// 小时流量统计
 | 
			
		||||
	var hourFrom = timeutil.Format("YmdH", time.Now().Add(-23*time.Hour))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user