diff --git a/desc/cloud/pcm-cloud.api b/desc/cloud/pcm-cloud.api index 18377c50..4b5fe5ca 100644 --- a/desc/cloud/pcm-cloud.api +++ b/desc/cloud/pcm-cloud.api @@ -121,7 +121,6 @@ type Cloud { } type PodsListReq { - ClusterName string `form:"clusterName"` } type PodsListResp { Data []interface{} `json:"data"` diff --git a/desc/core/pcm-core.api b/desc/core/pcm-core.api index 74a4337c..0a95eef3 100644 --- a/desc/core/pcm-core.api +++ b/desc/core/pcm-core.api @@ -102,7 +102,7 @@ type remoteResp { type ( clustersLoadReq { - ClusterName string `form:"clusterName"` + } clustersLoadResp { Data interface{} `json:"data"` diff --git a/internal/logic/cloud/podslistlogic.go b/internal/logic/cloud/podslistlogic.go index 63f576f1..e2d5a0c2 100644 --- a/internal/logic/cloud/podslistlogic.go +++ b/internal/logic/cloud/podslistlogic.go @@ -22,6 +22,11 @@ type ParticipantResp struct { Data *v1.PodList `json:"data"` // 改成结构体 } +type ClusterInfo struct { + Name string `json:"name"` + Server string `json:"server"` +} + func NewPodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PodsListLogic { return &PodsListLogic{ Logger: logx.WithContext(ctx), @@ -33,14 +38,14 @@ func NewPodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PodsList func (l *PodsListLogic) PodsList(req *types.PodsListReq) (resp *types.PodsListResp, err error) { resp = &types.PodsListResp{} // query cluster http url. - var apiServerList []string - l.svcCtx.DbEngin.Raw("select server from t_adapter where resource_type = '01'").Scan(&apiServerList) - for _, server := range apiServerList { + var clusterInfoList []ClusterInfo + l.svcCtx.DbEngin.Raw("select ta.server,tc.name from t_adapter ta,t_cluster tc where ta.id = tc.adapter_id and ta.resource_type = '01'").Scan(&clusterInfoList) + for _, clusterInfo := range clusterInfoList { participantResp := ParticipantResp{} param := map[string]string{ - "clusterName": req.ClusterName, + "clusterName": clusterInfo.Name, } - httputils.HttpGetWithResult(param, server+"/api/v1/pod/list", &participantResp) + httputils.HttpGetWithResult(param, clusterInfo.Server+"/api/v1/pod/list", &participantResp) resp.Data = append(resp.Data, participantResp.Data) } diff --git a/internal/logic/core/screenpagetasklogic.go b/internal/logic/core/screenpagetasklogic.go index f02803f7..25ba9a50 100644 --- a/internal/logic/core/screenpagetasklogic.go +++ b/internal/logic/core/screenpagetasklogic.go @@ -53,6 +53,8 @@ func (l *ScreenPageTaskLogic) ScreenPageTask(req *types.PageTaskReq) (resp *type return nil, result.NewDefaultError(err.Error()) } + // 运行卡时数 + // 查询任务列表 if err := db.Limit(limit).Offset(offset).Order("created_time desc").Find(&list).Error; err != nil { return nil, result.NewDefaultError(err.Error()) diff --git a/internal/logic/monitoring/clustersloadlogic.go b/internal/logic/monitoring/clustersloadlogic.go index 22d6a629..c3c1c423 100644 --- a/internal/logic/monitoring/clustersloadlogic.go +++ b/internal/logic/monitoring/clustersloadlogic.go @@ -2,6 +2,7 @@ package monitoring import ( "context" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker" "time" @@ -17,6 +18,11 @@ type ClustersLoadLogic struct { svcCtx *svc.ServiceContext } +type ClusterInfo struct { + ClusterName string `json:"clusterName"` + Metrics []tracker.Metric `json:"metrics"` +} + func NewClustersLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClustersLoadLogic { return &ClustersLoadLogic{ Logger: logx.WithContext(ctx), @@ -27,8 +33,20 @@ func NewClustersLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Clus func (l *ClustersLoadLogic) ClustersLoad(req *types.ClustersLoadReq) (resp *types.ClustersLoadResp, err error) { resp = &types.ClustersLoadResp{} - metrics := []string{"cluster_cpu_utilisation", "cluster_cpu_avail", "cluster_cpu_total", "cluster_memory_total", "cluster_memory_avail", "cluster_memory_utilisation", "cluster_disk_utilisation", "cluster_disk_avail", "cluster_disk_total", "cluster_pod_utilisation", "cluster_node_count"} - result := l.svcCtx.PromClient.GetNamedMetrics(metrics, time.Now(), tracker.ClusterOption{ClusterName: req.ClusterName}) + // 查询集群列表 + var clustersModel []models.ComputeCluster + l.svcCtx.DbEngin.Raw("select * from t_cluster where label = 'kubernetes'").Scan(&clustersModel) + var result []ClusterInfo + for _, cluster := range clustersModel { + metrics := []string{"cluster_cpu_utilisation", "cluster_cpu_avail", "cluster_cpu_total", "cluster_memory_total", "cluster_memory_avail", "cluster_memory_utilisation", "cluster_disk_utilisation", "cluster_disk_avail", "cluster_disk_total", "cluster_pod_utilisation", "cluster_node_count"} + data := l.svcCtx.PromClient.GetNamedMetrics(metrics, time.Now(), tracker.ClusterOption{ClusterName: cluster.Name.String}) + clusterInfo := ClusterInfo{ + ClusterName: cluster.Name.String, + Metrics: data, + } + result = append(result, clusterInfo) + + } resp.Data = result return resp, nil } diff --git a/internal/types/types.go b/internal/types/types.go index c9052a2d..2a690151 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -90,7 +90,6 @@ type RemoteResp struct { } type ClustersLoadReq struct { - ClusterName string `form:"clusterName"` } type ClustersLoadResp struct { @@ -5738,7 +5737,6 @@ type Cloud struct { } type PodsListReq struct { - ClusterName string `form:"clusterName"` } type PodsListResp struct {