Browse Source

修改监控接口入参

pull/488/head
zhangwei 5 months ago
parent
commit
9ab1d007e4
6 changed files with 33 additions and 11 deletions
  1. +0
    -1
      desc/cloud/pcm-cloud.api
  2. +1
    -1
      desc/core/pcm-core.api
  3. +10
    -5
      internal/logic/cloud/podslistlogic.go
  4. +2
    -0
      internal/logic/core/screenpagetasklogic.go
  5. +20
    -2
      internal/logic/monitoring/clustersloadlogic.go
  6. +0
    -2
      internal/types/types.go

+ 0
- 1
desc/cloud/pcm-cloud.api View File

@@ -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"`

+ 1
- 1
desc/core/pcm-core.api View File

@@ -102,7 +102,7 @@ type remoteResp {


type ( type (
clustersLoadReq { clustersLoadReq {
ClusterName string `form:"clusterName"`
} }
clustersLoadResp { clustersLoadResp {
Data interface{} `json:"data"` Data interface{} `json:"data"`


+ 10
- 5
internal/logic/cloud/podslistlogic.go View File

@@ -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)
} }


+ 2
- 0
internal/logic/core/screenpagetasklogic.go View File

@@ -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())


+ 20
- 2
internal/logic/monitoring/clustersloadlogic.go View File

@@ -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
} }

+ 0
- 2
internal/types/types.go View File

@@ -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 {


Loading…
Cancel
Save