| @@ -121,7 +121,6 @@ type Cloud { | |||||
| } | } | ||||
| type PodsListReq { | type PodsListReq { | ||||
| ClusterName string `form:"clusterName"` | |||||
| } | } | ||||
| type PodsListResp { | type PodsListResp { | ||||
| Data []interface{} `json:"data"` | Data []interface{} `json:"data"` | ||||
| @@ -102,7 +102,7 @@ type remoteResp { | |||||
| type ( | type ( | ||||
| clustersLoadReq { | clustersLoadReq { | ||||
| ClusterName string `form:"clusterName"` | |||||
| } | } | ||||
| clustersLoadResp { | clustersLoadResp { | ||||
| Data interface{} `json:"data"` | Data interface{} `json:"data"` | ||||
| @@ -22,6 +22,11 @@ type ParticipantResp struct { | |||||
| Data *v1.PodList `json:"data"` // 改成结构体 | 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 { | func NewPodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PodsListLogic { | ||||
| return &PodsListLogic{ | return &PodsListLogic{ | ||||
| Logger: logx.WithContext(ctx), | 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) { | func (l *PodsListLogic) PodsList(req *types.PodsListReq) (resp *types.PodsListResp, err error) { | ||||
| resp = &types.PodsListResp{} | resp = &types.PodsListResp{} | ||||
| // query cluster http url. | // 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{} | participantResp := ParticipantResp{} | ||||
| param := map[string]string{ | 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) | resp.Data = append(resp.Data, participantResp.Data) | ||||
| } | } | ||||
| @@ -53,6 +53,8 @@ func (l *ScreenPageTaskLogic) ScreenPageTask(req *types.PageTaskReq) (resp *type | |||||
| return nil, result.NewDefaultError(err.Error()) | return nil, result.NewDefaultError(err.Error()) | ||||
| } | } | ||||
| // 运行卡时数 | |||||
| // 查询任务列表 | // 查询任务列表 | ||||
| if err := db.Limit(limit).Offset(offset).Order("created_time desc").Find(&list).Error; err != nil { | if err := db.Limit(limit).Offset(offset).Order("created_time desc").Find(&list).Error; err != nil { | ||||
| return nil, result.NewDefaultError(err.Error()) | return nil, result.NewDefaultError(err.Error()) | ||||
| @@ -2,6 +2,7 @@ package monitoring | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker" | "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker" | ||||
| "time" | "time" | ||||
| @@ -17,6 +18,11 @@ type ClustersLoadLogic struct { | |||||
| svcCtx *svc.ServiceContext | svcCtx *svc.ServiceContext | ||||
| } | } | ||||
| type ClusterInfo struct { | |||||
| ClusterName string `json:"clusterName"` | |||||
| Metrics []tracker.Metric `json:"metrics"` | |||||
| } | |||||
| func NewClustersLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClustersLoadLogic { | func NewClustersLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClustersLoadLogic { | ||||
| return &ClustersLoadLogic{ | return &ClustersLoadLogic{ | ||||
| Logger: logx.WithContext(ctx), | 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) { | func (l *ClustersLoadLogic) ClustersLoad(req *types.ClustersLoadReq) (resp *types.ClustersLoadResp, err error) { | ||||
| resp = &types.ClustersLoadResp{} | 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 | resp.Data = result | ||||
| return resp, nil | return resp, nil | ||||
| } | } | ||||
| @@ -90,7 +90,6 @@ type RemoteResp struct { | |||||
| } | } | ||||
| type ClustersLoadReq struct { | type ClustersLoadReq struct { | ||||
| ClusterName string `form:"clusterName"` | |||||
| } | } | ||||
| type ClustersLoadResp struct { | type ClustersLoadResp struct { | ||||
| @@ -5738,7 +5737,6 @@ type Cloud struct { | |||||
| } | } | ||||
| type PodsListReq struct { | type PodsListReq struct { | ||||
| ClusterName string `form:"clusterName"` | |||||
| } | } | ||||
| type PodsListResp struct { | type PodsListResp struct { | ||||