This commit is contained in:
zhangwei 2024-11-06 20:54:22 +08:00
parent 0b07910415
commit b4896b8b38
1 changed files with 10 additions and 4 deletions

View File

@ -26,8 +26,8 @@ func NewCenterResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
}
}
func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesResp, err error) {
resp = &types.CenterResourcesResp{}
func (l *CenterResourcesLogic) CenterResources() (*types.CenterResourcesResp, error) {
resp := &types.CenterResourcesResp{}
rawData, err := l.svcCtx.PromClient.GetRawData("center_top3", tracker.AdapterOption{})
if err != nil {
return nil, err
@ -45,9 +45,15 @@ func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesRes
}
for _, centerIndex := range centersIndex {
// Query the types of resource centers
l.svcCtx.DbEngin.Raw("select name,type as CenterType from t_adapter where id = ?", centerIndex.Id).Scan(&centerIndex)
tx := l.svcCtx.DbEngin.Raw("select name,type as CenterType from t_adapter where id = ?", centerIndex.Id).Scan(&centerIndex)
if tx.Error != nil {
return nil, tx.Error
}
var clustersName string
l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(name SEPARATOR '|' ) as clustersName from t_cluster where adapter_id = ?", centerIndex.Id).Scan(&clustersName)
tx = l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(name SEPARATOR '|' ) as clustersName from t_cluster where adapter_id = ?", centerIndex.Id).Scan(&clustersName)
if tx.Error != nil {
return nil, tx.Error
}
cpuRawData, err := l.svcCtx.PromClient.GetRawData("center_cpu_utilisation", tracker.AdapterOption{AdapterId: centerIndex.Id, ClustersName: clustersName})
cpuData := cpuRawData.(model.Vector)
if err != nil {