mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	修复看板中统计数据可能不显示的问题
This commit is contained in:
		@@ -122,6 +122,17 @@ func (this *NodeValueDAO) ListValuesWithClusterId(tx *dbs.Tx, role string, clust
 | 
			
		||||
 | 
			
		||||
	_, err = query.Slice(&result).
 | 
			
		||||
		FindAll()
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, nodeValue := range result {
 | 
			
		||||
		nodeValue.Value, _ = json.Marshal(maps.Map{
 | 
			
		||||
			key: types.Float32(string(nodeValue.Value)),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -146,6 +157,17 @@ func (this *NodeValueDAO) ListValuesForUserNodes(tx *dbs.Tx, item string, key st
 | 
			
		||||
 | 
			
		||||
	_, err = query.Slice(&result).
 | 
			
		||||
		FindAll()
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, nodeValue := range result {
 | 
			
		||||
		nodeValue.Value, _ = json.Marshal(maps.Map{
 | 
			
		||||
			key: types.Float32(string(nodeValue.Value)),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -170,6 +192,17 @@ func (this *NodeValueDAO) ListValuesForNSNodes(tx *dbs.Tx, item string, key stri
 | 
			
		||||
 | 
			
		||||
	_, err = query.Slice(&result).
 | 
			
		||||
		FindAll()
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, nodeValue := range result {
 | 
			
		||||
		nodeValue.Value, _ = json.Marshal(maps.Map{
 | 
			
		||||
			key: types.Float32(string(nodeValue.Value)),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,13 +4,11 @@ package nameservers
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models/nameservers"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/rpc/services"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	timeutil "github.com/iwind/TeaGo/utils/time"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
@@ -144,12 +142,8 @@ func (this *NSService) ComposeNSBoard(ctx context.Context, req *pb.ComposeNSBoar
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range cpuValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.CpuNodeValues = append(result.CpuNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
@@ -159,27 +153,19 @@ func (this *NSService) ComposeNSBoard(ctx context.Context, req *pb.ComposeNSBoar
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range memoryValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.MemoryNodeValues = append(result.MemoryNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	loadValues, err := models.SharedNodeValueDAO.ListValuesForNSNodes(tx, nodeconfigs.NodeValueItemLoad, "load5m", nodeconfigs.NodeValueRangeMinute)
 | 
			
		||||
	loadValues, err := models.SharedNodeValueDAO.ListValuesForNSNodes(tx, nodeconfigs.NodeValueItemLoad, "load1m", nodeconfigs.NodeValueRangeMinute)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range loadValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.LoadNodeValues = append(result.LoadNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,6 @@ package services
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
 | 
			
		||||
@@ -14,7 +13,6 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	timeutil "github.com/iwind/TeaGo/utils/time"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
@@ -151,12 +149,8 @@ func (this *ServerStatBoardService) ComposeServerStatNodeClusterBoard(ctx contex
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range cpuValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.CpuNodeValues = append(result.CpuNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
@@ -166,27 +160,19 @@ func (this *ServerStatBoardService) ComposeServerStatNodeClusterBoard(ctx contex
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range memoryValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.MemoryNodeValues = append(result.MemoryNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	loadValues, err := models.SharedNodeValueDAO.ListValuesWithClusterId(tx, "node", req.NodeClusterId, nodeconfigs.NodeValueItemLoad, "load5m", nodeconfigs.NodeValueRangeMinute)
 | 
			
		||||
	loadValues, err := models.SharedNodeValueDAO.ListValuesWithClusterId(tx, "node", req.NodeClusterId, nodeconfigs.NodeValueItemLoad, "load1m", nodeconfigs.NodeValueRangeMinute)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range loadValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.LoadNodeValues = append(result.LoadNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
@@ -360,12 +346,8 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range cpuValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.DecodeMapValue().GetFloat32("usage")))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.CpuNodeValues = append(result.CpuNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
@@ -375,12 +357,8 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range memoryValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.DecodeMapValue().GetFloat32("usage")))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.MemoryNodeValues = append(result.MemoryNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
@@ -390,12 +368,8 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range loadValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.DecodeMapValue().GetFloat32("load5m")))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.LoadNodeValues = append(result.LoadNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -610,12 +610,8 @@ func (this *UserService) ComposeUserGlobalBoard(ctx context.Context, req *pb.Com
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range cpuValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.CpuNodeValues = append(result.CpuNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
@@ -625,27 +621,19 @@ func (this *UserService) ComposeUserGlobalBoard(ctx context.Context, req *pb.Com
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range memoryValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.MemoryNodeValues = append(result.MemoryNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	loadValues, err := models.SharedNodeValueDAO.ListValuesForUserNodes(tx, nodeconfigs.NodeValueItemLoad, "load5m", nodeconfigs.NodeValueRangeMinute)
 | 
			
		||||
	loadValues, err := models.SharedNodeValueDAO.ListValuesForUserNodes(tx, nodeconfigs.NodeValueItemLoad, "load1m", nodeconfigs.NodeValueRangeMinute)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range loadValues {
 | 
			
		||||
		valueJSON, err := json.Marshal(types.Float32(v.Value))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		result.LoadNodeValues = append(result.LoadNodeValues, &pb.NodeValue{
 | 
			
		||||
			ValueJSON: valueJSON,
 | 
			
		||||
			ValueJSON: v.Value,
 | 
			
		||||
			CreatedAt: int64(v.CreatedAt),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user